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.

KW Measurement problems



Hello,

I am facing some problems with measurement of KW. My Voltage Current and KVA I am measuring comes correct but my KW is very much incorrect. Please let me know if I am folowing any wrong method.

My sampling rate is 200uS and for evry sample I multiply instantaneous voltage and current and at every 100 samples means for every wave I integrate that multiplication. 

Is this wrong?

Please let me know where I am making mistake

  • Hi Abhishek!

    Unfortunately this is way too much code to have a quick look at. It would be great if you would debug your code and find out where your program starts to behave different from what you expect. Then post this part and explain what happens wrong. Based on this one could look for the issue.

    Dennis
  • Hello Abhishek!

    I believe you're measuring current using Current Transformers. If you're, then I've got some inputs for you.

    1. Do not do operations on every sample. Collect 100 samples and than calculate Vrms and Irms. If you calculate voltage and current for every sample, you may miss some samples which results in lot of error.
    2. Use IQMath library to do the calculations . I advise you to read the IQMath user guide at www.ti.com/.../msp-iqmathlib. You may find the same in MSPWare . I've got mine at C:\ti\msp430\MSPWare_3_20_00_37\iqmathlib

    Feel free to ping me if you need any further assistance.

    Teja

  • Hello Teja,

    Thanks for your reply.

    1> I have used IQmath library for all my caculation.
    2> Please let me know how would I find KW instantaneous for each phase with multiplying there instantaneous voltage and current.

    Also I have taken 1500 samples along with calculation and made an array and found that I am not loosing any sample as my controller finishes its instantaneous work before it going into next ISR of ADC that I am very sure.

    Thank you

    Abhishek
  • Abhishek,

    1. Great!
    2. You take 100 samples(200uS *100 = 0.2Seconds = Period of AC Sine wave). After you've 100 samples, each of voltage and current, you calculate RMSVoltage and RMS Current, multiply them and get the wattage.

    For more precise readings, you may average over 5 current readings.

    Teja
  • Hello Teja,

    Thanks for continuous reply,

    Yes exactly the same thing I am doing also I am taking average for 25 waves readings. After calibration of Voltage and Current KVA, Vrms, Irms I am getting is quite near (0.1% error) I eam getting. Only In KW I am getting 400W diffrence for every wave.

    Thanks

    Regards
    Abhishek
  • Are you using IQ math for KVA calculation too? If so, did you use correct GLOBAL_IQ? The product of Vrms and Irms should fall below the limits set by GLOBAL_IQ.

    Tell me what's the GLOBAL_IQ value you selected, the Max Vrms and Irms you're gonna get.

  • Yes I am using IQmath for my KW calculation too.

    I am using GLOBAL_IQ 12 for my calculation
  • What are the Max Vrms and Irms are we expecting to get?
  • Here's how my equation(Working) looks like:

    wattHour += _IQ14toF(_IQ14div(_IQ14mpy(_IQ14mpy(Q_VrmsResult, Q_IrmsResult), _IQ14(1.03)), _IQ14(3600)));
  • Maximum Vrms Irms expected is 5242.88 (Volts/ Amp)

    What I am doing for finding KW is

    Rphase.KWInst = Vr.Inst * Ir.Instx;
    Rphase.KWMean_temp = Rphase.KWMean_temp + Rphase.KWInst;

    now for every wave calculation

    Rphase.KWMean = _IQ12div(Rphase.KWMean_temp, Div100); //_iq12 Div100 = _IQ12(100);

    And Average of 25 waves

    Rphase.KW = _IQ12mpy(Rphase.KW_Disp, Div25); //_iq12 Div25 = _IQ12(25);
  • And also for KWH

    T_KW = (Rphase.KW + Yphase.KW + Bphase.KW);
    T_KW_temp = T_KW/3600; // done at every second once so timing won't be problematic
  • Hello Teja and ,

    Here is a part of my code.

    #define GLOBAL_IQ	12
    #include <msp430.h>
    #include<math.h>
    #include<stdint.h>
    #include"variables.h"
    #include<IQmathLib.h>
    
    char value=0, Flash_Data_clear=0;                                 // 8-bit value to write to segment C for testing only
    unsigned char Flash_Data[128];
    volatile int Set_TimerA0_flag = 0;
    static int Counter_20ms=0, Get_Parameter_Start=0, Counter_1s=0, Counter_900s=0, count15=0,Counter_1m=0; 		
    volatile unsigned short index1 = 0, Set_Timer_flag =0 , Counter_1ms=0;
    
    
    _iq12 SinglePhase_FSMul10000 = _IQ9(1251.6922);			// multiply by 10000
    _iq12 SinglePhase_FSMul = _IQ12(1.25169227); 		// =	(FS_Vlt/FS_Count)*10		old: 1.2307692
    _iq12 SinglePhase_FSMul_Rph = _IQ12(0.3319791742); 		// =	(FS_Vlt/FS_Count)*10		old: 1.2307692
    _iq12 SinglePhase_FSMul_Yph = _IQ12(0.3334973155); 		// =	(FS_Vlt/FS_Count)*10		old: 1.2307692
    _iq12 SinglePhase_FSMul_Bph = _IQ12(0.3307428101); 		// =	(FS_Vlt/FS_Count)*10		old: 1.2307692
    _iq12 SinglePhase_FSMulCrnt = _IQ12(0.72050492); 		// =	(FS_Crnt/FS_Count)*10		old: 0.02577319
    _iq12 SinglePhase_FSMulCrnt_Rph = _IQ12(0.6957011713); 		// =	(FS_Crnt/FS_Count)*10		old: 0.02577319
    _iq12 SinglePhase_FSMulCrnt_Yph = _IQ12(0.6943120942); 		// =	(FS_Crnt/FS_Count)*10		old: 0.02577319
    _iq12 SinglePhase_FSMulCrnt_Bph = _IQ12(0.6920073564); 		// =	(FS_Crnt/FS_Count)*10		old: 0.02577319
    
    
    
    
    _iq12 Divideby100 = _IQ12(0.01);
    _iq12 Div100 = _IQ12(100);
    _iq12 LinetoLine = _IQ12(1.73205);
    _iq12 Divideby14 = _IQ12(0.07142857);
    _iq12 Divideby17 = _IQ12(0.05882352);
    _iq12 Divideby20 = _IQ12(0.05);
    _iq12 Divideby25 = _IQ12(0.04);
    _iq12 Div25 = _IQ12(25);
    _iq12 Divideby33 = _IQ12(0.03030303);
    _iq12 Divideby50 = _IQ12(0.02);
    
    _iq12 Divideby10 = _IQ12(0.1);
    _iq12 Dividebyroot2 =_IQ12(0.7071067);
    _iq12 Divideby3600 = _IQ12(0.0000277777777);
    _iq12 Divideby36 = _IQ12(0.0277777777);
    _iq12 multiply100 = _IQ12(100);
    _iq12 Divideby3 = _IQ12(0.3333333);
    _iq12 Divideby1000 = _IQ12(0.001);
    
    _iq12 Divideby5 = _IQ12(0.2);
    _iq12 Divideby240 = _IQ12(0.00416666667);
    
    unsigned long CT_Ratio=409500 , PT_Ratio=4080 ;
    
    volatile int Ch0results = 0;		
    volatile int Ch4results = 0;
    volatile int Ch0_Offset = 4318;
    volatile int Ch4_Offset = 4315;
    
    
    volatile int Sample=0;
    
    int Ch0Prevresult;
    
    unsigned int CT_Primary_Turns = 5, PT_Primary_Turns = 240;
    unsigned short Frame_stop=0, Frame_type=0, Frame_for_Data_req, One_time_ONLY;
    
    unsigned long samplecount, freq;
    unsigned short freqcount, cycles_count=0, Lets_Start = 0, Meter_running = 1;
    
    /********************Calculation for Parameters********///
    unsigned short complete_trsnfer=1;
    
    /**********Defined and declaration of the parameter*******/
    long RKW_INST_ARRAY[101];
    long RKW_TEMP_ARRAY[101];
    long VR_INST_ARRAY[101];
    long VR_INSTX_ARRAY[101];
    long IR_INST_ARRAY[101];
    long IR_INSTX_ARRAY[101];
    
    /*******Frame Generation Function********/
    //void Xbee_Communication(void);
    /*****Global Variable Defination and Declaration*****/
    unsigned char b;
    unsigned char v[176],rx[50],h[30],tmp[176];
    unsigned int c,l,tttt=0,w,l1,g;
    volatile unsigned short i,i1;
    unsigned char s,rx1;
    uint8_t a,k;
    volatile int xx=0;
    
    const bsr_bit=0x0194;			//404 sampling bosr
    
    void Instant_Calculations();
    void Get_Parameter_Values();
    void Display_Parameter();
    void UCS_config();
    void SD24_B_config(void);
    void frequency_Calc();
    
    /*
     * main.c
     */
    int main(void)
    {
    	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    
    	/***** Unified Clock system ****/
    	UCS_config();
    
    	P1DIR |= BIT0;
    	P1REN |= BIT6;
    
        SD24_B_config();
       __delay_cycles(0x3600);                 // Delay for 1.5V REF startup
      SD24BCTL1 |= SD24GRP0SC;                // Set bit to start conversion
    
       __bis_SR_register( GIE);       // Enter interrupt
    
       for(;;)
       {
    	   if(Lets_Start == 1)
    	   {
    			   if(Get_Parameter_Start == 1)
    			   {
    
    				   Get_Parameter_Values();						// takes 100 uSec every 20mSecs
    
    				   Get_Parameter_Start = 0;
    			   }
    				   if(index1 == 25)									// Every 500 mSec
    				   {
    						++Counter_1s;
    						Display_Parameter();
    						Counter_1m++;
    						index1 = 0;
    				   }
    
    					if(Counter_1s == 2)
    					{
    						T_KVA = (Rphase.KVA + Yphase.KVA + Bphase.KVA);
    						T_KVAR = (Rphase.KVAR + Yphase.KVAR + Bphase.KVAR);
    						T_KW = (Rphase.KW + Yphase.KW + Bphase.KW);
    
    						T_KVA_temp = T_KVA/36;
    						MVA = MVA + T_KVA_temp;
    
    						T_KW_temp = T_KW/36;
    						MWA = MWA + T_KW_temp;
    
    						if (MVA >= 10000) 					//at 50kW
    						{
    							MVA = MVA - 10000;
    							KVAH++;
    						}
    
    						if (MWA >= 10000)
    						{
    							MWA = MWA - 10000;
    							KWH++;
    						}
    
    						if (KWH >= 10000)						//at 1MW
    						{
    							KWH = KWH -10000;
    							MWH++;
    						}
    
    						if (KVAH >= 10000)
    						{
    							KVAH = KVAH -10000;
    							MVAH++;
    						}
    
    
    						++Counter_900s;
    							if(Counter_900s == 900)
    							{
    								T15_calc_start = 1;
    								Counter_900s = 0;
    							}
    								for(count15=0;count15<900;count15++)
    								{
    									T15_KWH_temp = T15_KWH_temp  + T15_KWsample[count15];
    									T15_KVAH_temp = T15_KVAH_temp + T15_KVAsample[count15];
    								}
    						T15_KWH = T15_KWH_temp;
    						T15_KVAH = T15_KVAH_temp;
    						T15_KWH_temp = 0;
    						T15_KVAH_temp = 0;
    
    					if(Counter_1m==108)			// 108 for 1 Minute
    					{
    						Active_Runtime++;
    						T_Runtime++;
    						Counter_1m = 0;
    					}
    					Counter_1s = 0;
    					}
    
    				if(Frame_for_Data_req ==1 && Counter_1ms == 1)
    				{
    					if (complete_trsnfer==1)
    					{
    						complete_trsnfer = 0;
    					}
    					UCA0IE |= UCTXIE;
    
    			   }
    					if(Counter_1m==108)				// 108 for 1 Minute
    					{
    						T_Runtime++;
    						Counter_1m = 0;
    					}
    
    					if(Frame_for_Data_req ==1 && Counter_1ms == 1)
    						{
    							if (complete_trsnfer==1)
    							{
    								complete_trsnfer = 0;
    							}
    							UCA0IE |= UCTXIE;
    						}
    			   }
    
    	   }
       }
    }
    
    void frequency_Calc(void)
    {
    	if((Ch0results >= 0 && Ch0Prevresult <= 0)) 		//detect cycle crosses zero level
    	{
    		if(Lets_Start == 0)
    		{
    			Lets_Start = 1;
    			samplecount = 0;
    		}
    		else
    		{
    			++cycles_count;								// in other conditions ( wen parameters r calculated) Lets_start==1
    			if(cycles_count == 50)
    			{
    				freq = (samplecount*100)/freqcount;
    				cycles_count = 0;
    				samplecount = 0;
    			}
    		}
    
    		freqcount = 0;
    
    	}
    
    			++freqcount;
    			++samplecount;
    			Ch0Prevresult = Ch0results;
    }
    
    void Display_Parameter(void)
    {
    
    
    	Vr.RMS = _IQ12div(Vr.RMS_Disp, Div25);
    	Vr.RMS = _IQ12mpy(Vr.RMS, PT_Ratio);
    	Vr.RMS_LtoL = _IQ12mpy(Vr.RMS, LinetoLine);
    	Ir.RMS = _IQ12div(Ir.RMS_Disp, Div25);
    	Ir.RMS_Disp = _IQ12mpy(Ir.RMS, CT_Ratio);
    	Ir.RMS = _IQ12div(Ir.RMS_Disp, Div100);
    	Rphase.KW = _IQ12mpy(Rphase.KW_Disp, Divideby25);
    	Rphase.KW = _IQ12mpy(Rphase.KW, CT_Ratio);
    
    	Rphase.KVA = _IQ12mpy(Vr.RMS, Ir.RMS);
    	Rphase.KVA = _IQ12div(Rphase.KVA,10000);
    
    	Rphase.Pfactor = (Rphase.KW/Rphase.KVA);
    	Rphase.KW = _IQ12div (Rphase.KW, Div100); //
    	Rphase.KVAR = Rphase.KVA - Rphase.KW;
    
    	
    	if (Rphase.Pfactor > 100 && One_time_ONLY == 0)
    	{
    		Frame_for_Data_req=1;
    		One_time_ONLY = 1;
    	}
    
    	Rphase.KW = _IQ12mpy(Rphase.KW, PT_Ratio);
    
    	Vr.RMS_Disp = 0;
    	Ir.RMS_Disp = 0;
    
    	Rphase.KW_Disp = 0;
    
    }
    
    
    void Get_Parameter_Values(void)
    {
    
    //		Channel 1  ---------		R-Phase
    
    	   Vr.Mean = _IQ18sqrt(Vr.Mean);
    	   Vr.RMS_Get = _IQ9mpy(Vr.Mean,1);
    	   Vr.RMS_Disp = Vr.RMS_Disp + Vr.RMS_Get;
    
    	   Ir.Mean = _IQ18sqrt(Ir.Mean);
    	   Ir.RMS_Get = _IQ9mpy(Ir.Mean,1);
    	   Ir.RMS_Disp = Ir.RMS_Disp + Ir.RMS_Get;
    
    	   Rphase.KW_Get = _IQ12mpy (Rphase.KWMean, SinglePhase_FSMulCrnt_Rph);
    	   Rphase.KW_Get = _IQ12div(Rphase.KW_Get,Div100);
    	   Rphase.KW_Disp = Rphase.KW_Disp + Rphase.KW_Get;
    	   ++index1;
    
    
    }
    
    void Instant_Calculations(void)
    {
    
    //-------------------------------------------------------------------------------------Start Sensed Data Calc
    	//-----------------------------------------------------------------------------------------
    	// Channel 0 for R-phase Voltage
    
    	Vr.Instx = Ch0results;
    	Vr.Inst = _IQ12mpy(Vr.Instx, SinglePhase_FSMul_Rph);
    	Vr.Square = Vr.Inst * Vr.Inst;
    	Vr.Mean_temp = Vr.Mean_temp + Vr.Square;
    	VR_INST_ARRAY[Counter_20ms] = Vr.Inst;
    	VR_INSTX_ARRAY[Counter_20ms] = Vr.Instx;
    
    	// Channel 4 for R-phase Current
    
    	Ir.Instx = Ch4results;
    	Ir.Inst = _IQ12mpy(Ir.Instx, SinglePhase_FSMulCrnt_Rph);
    	Ir.Square = Ir.Inst * Ir.Inst;
    	Ir.Mean_temp = Ir.Mean_temp + Ir.Square;
    	IR_INST_ARRAY[Counter_20ms] = Ir.Inst;
    	IR_INSTX_ARRAY[Counter_20ms] = Ir.Instx;
    
    	Rphase.KWInst = Vr.Inst * Ir.Instx;
    	Rphase.KWMean_temp = Rphase.KWMean_temp + Rphase.KWInst;			//New
    
    	RKW_INST_ARRAY[Counter_20ms] = Rphase.KWInst;
    	RKW_TEMP_ARRAY[Counter_20ms] = Rphase.KWMean_temp;
    
    
    	++Counter_20ms;
    
    	// Harmonics Calculation THD for upto 3rd harmonic
    
    
    	if(Counter_20ms == 100)									//20msec
    	{
    // every 20 mSecs
    		Counter_20ms = 0;
    
    
    //KW = active power
    		Vr.Mean = Vr.Mean_temp;
    		Ir.Mean = Ir.Mean_temp;
    		Rphase.KWMean = _IQ12div(Rphase.KWMean_temp, Div100);
    
    
    		Vr.Mean_temp = 0;
    		Ir.Mean_temp = 0;
    		Rphase.KWMean_temp = 0;
    		Get_Parameter_Start = 1;
    	}
    }
    
    
    void UCS_config(void)
    {
    			PMMCTL0_H = 0xA5;
    			PMMCTL0_L = 0x03;
    			UCSCTL0 = UCSCTL0 | 0x1F00;
    			UCSCTL1 = UCSCTL1 & 0x0000;
    			UCSCTL1 = UCSCTL1 | 0x0050;
    			UCSCTL2 = UCSCTL2 & 0x0000 ; // FLL Divider
    			UCSCTL2 = UCSCTL2 | 0x403C ; // for 32 MHz MCLK and 2.0 MHz SMCLK
    			UCSCTL3 = 0x0000;
    			UCSCTL7 = 0;
    			UCSCTL4 = UCSCTL4 & 0X0000;
    			UCSCTL4 = UCSCTL4 | 0X0043;
    			UCSCTL7 = 0;
    }
    
    
    // Sigma-Delta ADC *******************
    void SD24_B_config(void)
    {
    	SD24BCTL0 = SD24REFS | SD24SSEL_1;      // Select internal REF // Select SMCLK as SD24_B clock source
    
    	SD24BOSR0 = bsr_bit;		//C7 for 5K samplin; OSR = 520
    	SD24BOSR1 = bsr_bit;		//C7 for 5K samplin; OSR = 520
    	SD24BOSR2 = bsr_bit;		//C7 for 5K samplin; OSR = 520
    	SD24BOSR3 = bsr_bit;		//C7 for 5K samplin; OSR = 520
    	SD24BOSR4 = bsr_bit;		//C7 for 5K samplin; OSR = 520
    	SD24BOSR5 = bsr_bit;		//C7 for 5K samplin; OSR = 520
    	SD24BOSR6 = bsr_bit;		//C7 for 5K samplin; OSR = 520
    
    	SD24BCCTL0 = SD24ALGN | SD24SCS_4;      // Left-aligned, group 0
    	SD24BCCTL1 = SD24ALGN | SD24SCS_4;      // Left-aligned, group 0
    	SD24BCCTL2 = SD24ALGN | SD24SCS_4;      // Left-aligned, group 0
    	SD24BCCTL3 = SD24ALGN | SD24SCS_4;      // Left-aligned, group 0
    	SD24BCCTL4 = SD24ALGN | SD24SCS_4;      // Left-aligned, group 0
    	SD24BCCTL5 = SD24ALGN | SD24SCS_4;      // Left-aligned, group 0
    	SD24BCCTL6 = SD24ALGN | SD24SCS_4;      // Left-aligned, group 0
    
    	SD24BIE = SD24IE5;                      // Enable channel 5 interrupt
    }
    
    
    
    // 24Bit ADC Interrupt Sub routine
    #pragma vector=SD24B_VECTOR
    __interrupt void SD24BISR(void)
    {
    
    // Every 200 uSeconds
    //	 P1OUT = 0x0001;
    	if(SD24BIV == SD24BIV_SD24IFG5)
    	{
    	//	P1OUT = 0x0001;
    
    		Ch0results = SD24BMEMH0 -  16232;//4324;//4319;//crd6-4316;
    		Ch4results = SD24BMEMH4 -  16224;//4318;//4316;//crd6-4319;
    
    		Ch1results = SD24BMEMH1 -  16229;//4320;//4323;//crd6-4323;
    		Ch5results = SD24BMEMH5 -  16230;//4317;//4319;//crd6-4317;
    
    		Ch2results = SD24BMEMH2 -  16246;//4320;//4322;//crd6-4318;
    		Ch6results = SD24BMEMH6 -  16228;//4318;//4316;//crd6-4318;
    
    		Ch3results = SD24BMEMH3 -  16228;//4317; //4317;//crd6-4318;
    		frequency_Calc();
    		if(Lets_Start == 1)
    		{
    			Instant_Calculations();
    		}
    
    	}
    }
    

    Thanks 

    Regards

    Abhishek Parikh

  • Abhishek.

    As said, it'd be very difficult for anyone to go through the entire code. Partly because, there won't be hardware available with us.

    Can you please try getting KVA with normal math operations and not IQMath? And if it works, double check each IQMath operation using breakpoints. That should help you get answer.

    Best
    Teja
  • Please change

    _iq12 SinglePhase_FSMul10000 = _IQ9(1251.6922);         // multiply by 10000

    in Line 15 to

     _iq12 SinglePhase_FSMul10000 = _IQ12(1251.6922);         // multiply by 10000

     

    Teja

  • Actually most of the code is initialiaztion only and actually

    _iq12 SinglePhase_FSMul10000 = _IQ9(1251.6922); // I am not using this variable any where
  • Also,  Can you please let me know if there is anything mistake with this fuctions it would be hepful.
    1>


    void Instant_Calculations(void) { //-------------------------------------------------------------------------------------Start Sensed Data Calc //----------------------------------------------------------------------------------------- // Channel 0 for R-phase Voltage Vr.Instx = Ch0results; Vr.Inst = _IQ12mpy(Vr.Instx, SinglePhase_FSMul_Rph); Vr.Square = Vr.Inst * Vr.Inst; Vr.Mean_temp = Vr.Mean_temp + Vr.Square; VR_INST_ARRAY[Counter_20ms] = Vr.Inst; VR_INSTX_ARRAY[Counter_20ms] = Vr.Instx; // Channel 4 for R-phase Current Ir.Instx = Ch4results; Ir.Inst = _IQ12mpy(Ir.Instx, SinglePhase_FSMulCrnt_Rph); Ir.Square = Ir.Inst * Ir.Inst; Ir.Mean_temp = Ir.Mean_temp + Ir.Square; IR_INST_ARRAY[Counter_20ms] = Ir.Inst; IR_INSTX_ARRAY[Counter_20ms] = Ir.Instx; Rphase.KWInst = Vr.Inst * Ir.Instx; Rphase.KWMean_temp = Rphase.KWMean_temp + Rphase.KWInst; //New RKW_INST_ARRAY[Counter_20ms] = Rphase.KWInst; RKW_TEMP_ARRAY[Counter_20ms] = Rphase.KWMean_temp; ++Counter_20ms; // Harmonics Calculation THD for upto 3rd harmonic if(Counter_20ms == 100) //20msec { // every 20 mSecs Counter_20ms = 0; //KW = active power Vr.Mean = Vr.Mean_temp; Ir.Mean = Ir.Mean_temp; Rphase.KWMean = _IQ12div(Rphase.KWMean_temp, Div100); Vr.Mean_temp = 0; Ir.Mean_temp = 0; Rphase.KWMean_temp = 0; Get_Parameter_Start = 1; } }

    2>

    void Get_Parameter_Values(void)
    {
    
    //		Channel 1  ---------		R-Phase
    
    	   Vr.Mean = _IQ18sqrt(Vr.Mean);
    	   Vr.RMS_Get = _IQ9mpy(Vr.Mean,1);
    	   Vr.RMS_Disp = Vr.RMS_Disp + Vr.RMS_Get;
    
    	   Ir.Mean = _IQ18sqrt(Ir.Mean);
    	   Ir.RMS_Get = _IQ9mpy(Ir.Mean,1);
    	   Ir.RMS_Disp = Ir.RMS_Disp + Ir.RMS_Get;
    
    	   Rphase.KW_Get = _IQ12mpy (Rphase.KWMean, SinglePhase_FSMulCrnt_Rph);
    	   Rphase.KW_Get = _IQ12div(Rphase.KW_Get,Div100);
    	   Rphase.KW_Disp = Rphase.KW_Disp + Rphase.KW_Get;
    	   ++index1;
    
    
    }

    and last 3>

    void Display_Parameter(void)
    {
    
        // When index1 = 25
    	Vr.RMS = _IQ12div(Vr.RMS_Disp, Div25);
    	Vr.RMS = _IQ12mpy(Vr.RMS, PT_Ratio);
    	Vr.RMS_LtoL = _IQ12mpy(Vr.RMS, LinetoLine);
    	Ir.RMS = _IQ12div(Ir.RMS_Disp, Div25);
    	Ir.RMS_Disp = _IQ12mpy(Ir.RMS, CT_Ratio);
    	Ir.RMS = _IQ12div(Ir.RMS_Disp, Div100);
    	Rphase.KW = _IQ12mpy(Rphase.KW_Disp, Divideby25);
    	Rphase.KW = _IQ12mpy(Rphase.KW, CT_Ratio);
    
    	Rphase.KVA = _IQ12mpy(Vr.RMS, Ir.RMS);
    	Rphase.KVA = _IQ12div(Rphase.KVA,10000);
    
    	Rphase.Pfactor = (Rphase.KW/Rphase.KVA);
    	Rphase.KW = _IQ12div (Rphase.KW, Div100); //
    	Rphase.KVAR = Rphase.KVA - Rphase.KW;
    
    	Rphase.KW = _IQ12mpy(Rphase.KW, PT_Ratio);
    
    	Vr.RMS_Disp = 0;
    	Ir.RMS_Disp = 0;
    
    	Rphase.KW_Disp = 0;
    
    }

  • If you're using IQMath, you've to continue using IQMath throughout. You can't be mixing _iq variables with non _iq variables. You're doing the same at Vr.Square = Vr.Inst * Vr.Inst;

    Please use _IQMath library for all operations. You can't combine normal math with IQMath.
  • Ok I'll try and let you know soon

    Thanks
  • Please can you help me with if I use all IQmath and find answers and at last I want to get values from that how can I do so?
  • Please find the examples on IQMath. You ca use _IQ12toF to get the floating point results.

    Have a look at my code at github.com/.../LM35_Temperature.c

    Teja
  • I have changed all the multimplication to IQ12mpy also but there is no change in results..
    I am getting 0.4W more at every instance..
  • Dear Abhishek,

    You're going to debug the code yourself now. You may've to read the users guide again, understand how IQMath lib works and do a step-by-step analysis of your code.

    For eg. If you wanna multiply 2 and 3, use normal math and note the result down. Use IQMath for multiplication, get the result back and see if they're matching. Make sure you convert all the Non-IQ variables to IQ Variables.
  • Hello Teja,

    Thanks for your continuous support.

    I have done all the calculation in IQmath now and getting same results.
    I just wanted to ask you that can we calibrate KW just same as we are calibrating V & I.

    Thanks
    Regards
  • My pleasure, Abhishek.

    Can you please use normal math and get KVA? If you're getting accurate values, then I'll help you port the same into IQMath library.

    Teja
  • Hello Teja,

    I have tried with normal math but I am facing some timing issues at instantaneous calculation. So I am not getting proper values.

    Can you tell me how to calebrate KW instantaneous values.

    Thanks
  • I'm sorry, I didn't understand what you mean.

    One approach can be to multiply Vrms, Irms and PF in 1 second timer, accumulation values over time.

    Teja
  • Actually I am doing another way I am accumulating the multiplication of V and I instantaneous and add it for a cycle and repeat it for one scond and average it after.

    Abhishek
  • Can you please do the calculations in 1 second timer (Keep them as optimised as possible) and report us back with the results?

**Attention** This is a public forum