This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

power factor calculation in msp430f425

Other Parts Discussed in Thread: MSP430F425, MSP430F425A

I need help in calculating power factor in msp430f425. Currently I am calculating count during zero crossing, and try to find the power factor.

But the result is not accurate at different power factors. And how to calibrate it.

Can anybody provide me example code for this. Please help.

Thanks in advance.

  • Hello Suman,

    Please note that the MSP430F425 is not recommended for new designs (NRND) and has been replaced by the MSP430F425A . You can look at some of our E-Meter EVMs to try to reason out how it is down on those chips.

    Such as:
    www.ti.com/.../evm430-f6779
    www.ti.com/.../TIDM-SINGLEPHASEMETER
    www.ti.com/.../TIDM-SINGLEPHASEMETER
    www.ti.com/.../TIDM-THREEPHASEMETER-F449
    www.ti.com/.../TIDM-TWOPHASEMETER-I2040

    Regards,
    JH
  • Thanks for your reply Jace H,
    But I needed help to calculate power factor accurately, no matter it is f425 or f425A. Please provide me source code for the same.

    Thanks in advance.
  • The source code provided with our energy metering TI designs and app. notes contains an implementation of power factor measurement which achieves high accuracy.

  • Bharti,

    The link we suggested already have a complete set of code provided including the calculation of power factor. Though the code is written for other devices the calculation for power factor and the associated calculation is the same for MSP430F425. Calculate PF at zero crossing is a correct approach but please make sure the zero crossing is where your ADC samples seeing a negative to positive (or the other way round) change instead of at the assumption that after a certain number of cycle there is a zeros crossing. Also please make sure you do some averaging from the result you get as there may be some noise and other factor that would make the result jitter a bit.

    mars

  • Steve Underwood,
    Please have a look on my code below and suggest if it is right approach or not. If not, please suggest correct approach.
    Please don't mind but that code (that you provided me in another link for active power calculation) is very tedious to understand. So I tried this.
    Please guide what more to do for better resolution of power factor.
    "pf_final_sample" in this code after hardware multiplier is used to calculate power factor further in another routine.



    #include "math.h"
    #include "sb_defination.h"
    #include <msp430xE42x.h>

    int16_t pf_sq_sum[3];
    int16_t pf_sample=0;

    int16_t adc_vol=0;
    int16_t adc_ct=0;
    int16_t adc_shunt=0;


    int16_t vol_dc_filter=-1129550;
    int16_t shunt_dc_filter=-1129550;



    int16_t phase_count=0,phase_count_temp=0;

    int8_t phase_check=0,phase_check_temp=0;


    int16_t dc_filter(int32_t *p, int16_t x)
    {
    //One would like to estimate DC by something like:
    // z += ((((int32_t) x << 15) - z) >> 14);
    // return x - (z >> 15);
    //but this:
    // z += ((((int32_t) x << 16) - z) >> 14);
    // return x - (z >> 16);
    //is a bit faster, and the shift by 16 will never
    //cause an overflow in this application. However,
    //remember this is not a generic DC filter!
    *p += ((((int32_t) x << 16) - *p) >> 14);
    x -= (*p >> 16);
    return x;

    }

    #pragma vector=SD16_VECTOR // SD16 Interrupt....
    __interrupt void adc_interrupt(void)

    //void adc_interrupt(void)
    {



    adc_vol= SD16MEM2;
    adc_ct= SD16MEM1; // CT
    adc_shunt= SD16MEM0; // SHUNT

    vol_sample=dc_filter(&vol_dc_filter,adc_vol);
    shunt_sample=dc_filter(&shunt_dc_filter,adc_shunt);

    if(vol_sample>0)
    {
    if(shunt_sample<0)
    {
    phase_count_temp++; //=phase_count_temp+10;
    phase_check=1;
    phase_check_temp=0;
    }
    }

    if(vol_sample<0) //adc_shunt>0)
    {
    if(shunt_sample>0)
    {
    phase_count_temp++; //=phase_count_temp+10;
    phase_check=2;
    phase_check_temp=0;
    }
    }

    if(phase_check_temp==0)
    {
    if(vol_sample>0 && shunt_sample>0)
    {
    phase_count=phase_count_temp;
    phase_count_temp=0;
    phase_check_temp=1;
    //phase_check=1; ()
    }
    }


    asm(

    // get power factor


    " MOV phase_count+0,&0132h ; Signed MPY is used\n"
    " MOV phase_count+0,&0138h\n"
    " ADD &013Ah,pf_sq_sum ; Add LSBs to result\n"
    " ADDC &013Ch,pf_sq_sum+2 ; Add MSBs to result\n"
    " ADDC &013Eh,pf_sq_sum+4 ; Add &013Eh to MSBs\n"
    " ;ADDC &013Eh,pf_sq_sum+6 ; Add &013Eh to MSBs\n"

    );
    Sample_Count++;



    if(Sample_Count>=4096)
    {
    pf_final_sample = div48(pf_sq_sum,Sample_Count); // First Stage

    pf_sq_sum[0]=0;
    pf_sq_sum[1]=0;
    pf_sq_sum[2]=0;

    Sample_Count=0x00;

    }




    }

    int32_t div48(register int16_t x[3], register int16_t y)
    {
    /* Divide a 16 bit integer into a 48 bit one. Expect the answer to be no
    greater than 32 bits, so return the answer as a 32 bit integer.
    A somewhat domain specific divide operation, but pretty useful when
    handling dot products. */
    int32_t x1;
    int32_t z;

    /* Avoid any divide by zero trouble */
    if (y == 0)
    return 0;
    x1 = x[2]%y;
    x1 <<= 16;
    x1 |= (uint16_t) x[1];
    z = x1/y;
    x1 = x1%y;
    x1 <<= 16;
    x1 |= (uint16_t) x[0];
    z = (z << 16) + x1/y;
    return z;
    }
  • Please share me logic and basic C code for this.
  • SUMAN,

    The link we gave you in our early reply should have the code of the calculation of power factor included. I suggest you to follow the code we gave in the reference design if you could not be sure your code is performing the same function correctly. Any reason to rewrite on your own ?

    mars

  • Yes that link have a code, but is very tedious and typical to understand.
    So, it will be very helpful if you can provide me logic and C code to calculate power factor and frequency.
    I will then change that according to my code.
    Please also have a look on my code above and reply.

    thanks in advance.
  • You do not have to understand how it work to use the calculation. Why are you insist to understand the code and reproduce your own with your understanding and just doing exactly the same thing ? The library code is for you to use. It is very difficult to explain everything to you in words.

    Even though it is not a project for F425 you can try to set the project up from the original project to a project fo F425 and the compile the code you get the answer. In short, these calculations are device independent, thus the calculation works for other device works for F425 as well.
  • Mars Leung,
    I insist to understand the code to understand the basics. I want to learn its basics, and not just get my work done by using pre produced softwares.
    So, please help me if you can.

    I have tried it with some other way, please read my logic and give your feedback over it.

    I have started a counter in TIMER A with 500 micro second interrupt.
    I am reading its value between zero crossing of voltage and current and calculating power factor from there.
    But i am not getting very good accuracy from here. As if i increase TIMER A interrupt frequency, it causes interference in proper working of other peripherals.

    So please help me into it.

**Attention** This is a public forum