I need to measure RMS Current, RMS Voltage and Power factor, please let me know if anybody implemented this. I have to use AN7 ping of ADC.

Thanks in advance.

I need to measure RMS Current, RMS Voltage and Power factor, please let me know if anybody implemented this. I have to use AN7 ping of ADC.

Thanks in advance.

Thanks for your response. actually I have to read from 24 receptacles Instanenous current (I[1] to I[24]) and Three Instaneous voltages V[1] to V[3], I am using MUX to select one of 32 by using 5 GPIO Pins and read I/V on AN7 by selecting one of the device.

average of V[i] = V[1]+V[2]+V[3]/3

average of I[i] = I[1].......+I[24]/24

is this is RMS values or do I have to calculate RMS again?.

I need to measure current 840 samples / second, where as voltage 22800 samples / second. Total I have to measure 3 voltages, 28 currents, 28 power, 28 VA, 28PF, total 195, I have to read calculate those calculations for every half second. Can I use direct timer?

thanks.

TVNAIDU, some details of your application are still unclear for me.

Do you mean 24 three phase mains receptables? Do you mean phase 'A' of each receptable is connected to U[1], phase 'B' of each receptable is connected to U[2], phase 'C' of each receptable is connected to U[3]?

Is the mains frequency 50 Hz or 60 Hz?

Thanks for reply. this is 24 plug ports power strip with 3 input plugs (each input plug controls one group of 8 receptacles)

Basically I am doing power strip with 50Hz/120V input and I have 24 receptcles (each group is 8), like that 3 groups of eight receptacles in each strip, I am reading currents back from 24 receptacle relays, also I am reading 3 voltages, one from each group of eight receptacles. I am using 5 GPIO pins to select one of the receptacle (24 currents + 3 volatges + few for temperature), basically I have to read 24 currents, 3 voltage. 24 Instaneous currents, 3 Instaneous voltages, then I have to VI (voltage * current), also I have to calculate average voltage and current: total readings are:

Three Vrms from Three groups

8 * 3 = 24 rms currents + 3 boards + 1 total

28 Powers

28 VA (V rms * I rms)

28 PF (P / VA)

total 195, I have to read twice a second.

for current 840 samples / second and for voltage 226800 samples per second. I have to find how I get those two numbers (840 and 226800).

I am using 5 GPIO pins (AN0 - AN4) select one at a time and AN7 to read the value. does ADC gives me the value or do I have to calculate again?. Looking for some idea, first time I doing this, apprecaited.

TV.

Let calculate the sampling rate, which is need for measuring of power factor at 24 single-phase receptacles. Demand for the data acquisition resources by the other tasks is significantly lower.

For very modest requirement of 10 pair of (U,I) samples per 50 Hz period:

Each of single-phase receptacle needs 4*10*50 = 2000 raw samples/second.

Coefficient 4 is due to the recommended U[i] -> I[i] -> I[i] ->U[i] sequence of raw samples for each pair of pseudo-simultaneous (U,I) samples at receptacle[i].

24 single-phase receptacles need 2000*24 = 48000 raw samples/second.

Satisfying hard real-time constrains of such sustained data acquisition and calculations is non-trivial task even for experienced embedded software engineer or experienced DSP engineer.

I'd recommend to use some hardware accelerators for your application.The most simple (and most costly) solution is using dedicated RMS and power factor measurement chips. The middle cost alternative can be using a DSP instead of a microcontroller. Possibly, your application will benefit from dual ADC with FIFO on chip.

Your application also needs either hardware or software generated strobe of actual 50 Hz period. This strobe can be generated by zero crossing of well filtered 50 Hz sine wave.

Thanks for your message Yevgeni.

Basically I am using ADG608BR chip (4/8 channel high performance multiplexor), AN7 pin of 52236 chip driven by the above multiplexor, as per you suggested, is there any dedicated RMS and power measurement chips?. Can I get some part numbers who makes them?.

Since my Hardware is laready designed, do you recommend any simple solution to calculate atleast RMS Current and RMS Voltage with current 52236 processor.

Thanks in advance.

> is there any dedicated RMS and power measurement chips?

> Can I get some part numbers who makes them?

I''l search for the part numbers among leading manufacturers of analog chips.

> Since my Hardware is laready designed, do you recommend any simple solution to calculate

> at least RMS Current and RMS Voltage with current 52236 processor.

I am not familiar with 52236 processor. Coldfire family has either MAC or eMAC unit, which can be used as hardware accelerator to calculate sum of the squares. Freescale site contains some source code (assembler) libraries to use MAC and eMAC.

RMS of either U or I can be calculated as the following.

Fill the buffer with samples (using signed short integer format), which represent integer number of the actual 50 Hz periods. If you have enough RAM, storing 500 ms interval of the reporting is convenient. Then, calculate sum of the squares.

Alternatively, you can eliminate the buffers and save the RAM by keeping only sum of the squares. With this arrangement, update the sum with each new sample. No need to use MAC/eMAC in this case.

Any case, you will need to determine in real time, when the needed number of 50 Hz cycles is accumulated.

Then, convert the sum into the regular C float type, divide dy the quantity of the samples and apply ANSI C sqrtf() function.

You will need the pair of the buffers per each RMS: while one buffer is under fill with the samples by either ISR or dedicated task, the other buffer is granted to the RMS subsystem.

Yevgenit:

My question is: I have only instantaneous current and instantaneous voltage readings only I am getting, using those Two can I calculate real power and apparent power, then using those power readings can I calculate power factor?. My goal is to calculate power factor with instantaneous current and instantaneous voltage.

anyway below is my routine to calculate RMS current, RMS voltage from instantaneous current and voltage, also I did actual power and apparent power calculations, also I did power factor calculations. 840 times I took ADC value for inst. current and inst, voltage, the others readings (RMS CURR, RMS VOLT, ACTUAL POWER, APPARENT POWER, POWERFACT) I did for every half-second, please take a look my routine below (sorry for syntax), please see logic and let me know. appreciated.

please point me if I am wrong.

#define SAMPLES 840 /*Total sampes per second*/

int insta_curr_read[27] = 0; /* 24 instantaneous current */

int insta_volt_read[3] = 0; /* 3 instantaneous voltage */float insta_cumulate_curr_read[27] = 0; /* 24 cumulative currents */

float insta_cumulat_volt_read[3] = 0; /* 3 cumulative voltage */int read_adc_val;

float rms_current[27] = 0; /* 24 RMS Current */

float rms_voltage[3] = 0; /* 3 RMS Voltages */

int actual_power[24] = 0;

float apparent_power[24] = 0;

float power_factor[24] = 0;int count, sample_count, curr_count, volt_count;

main_task()

{

for (sample_count=0; sample_count < SAMPLES; sample_count++)

{

for(curr_count=0; curr_count < 24; curr_count++)

{

set GPIO to select curr_count;

read_adc_val = ADC value;

insta_curr_read [curr_count]+ = read_adc_val;

/* below is square the above read and acuumulate into buff */

insta_cumulate_curr_read[curr_count] += (read_adc_val * read_adc_val) ; /* cumulative */

}

for(volt_count=0; volt_count < 3; volt_count++)

{

set GPIO to select volt_count;

read_adc_val = ADC value /*read adc */

insta_volt_read[volt_count] += read_adc_val;

/* below is square the above read and acuumulate into buff */

insta_cumulate_volt_read[volt_count] += (read_adc_val * read_adc_val); /*cumulate */

}

/* these calculations for every Half second - for 420 samples only */

if(sample_count == 419 )

{

/* RMS calculations */

for(count=0; count<24;count++)

{

rms_current[count] = sqrt(insta_cumulate_curr_read[count] / (SAMPLES/2))

}

for(count=0; count<3;count++)

{

rms_volt[count] = sqrt(insta_cumulate_volt_read[count] / (SAMPLES/2))

}/* ACTUAL POWER CALCULATION (V-inst * I-inst) */

/* first 8 plug board actual power )(V-inst * I-inst) */

for(count=0; count < 8; count++)

{

actual_power[count] = int insta_curr_read[count] * insta_volt_read[1];

}/* second 8 plug board use second insta. voltage reading */

for(count=8; count < 16; count++)

{

actual_power[count] = insta_curr_read[count] * insta_volt_read[2];

}/* third 8 plug board use third inst. voltage reading */

for(count=16; count < 24; count++)

{

actual_power[count] = insta_curr_read[count] * insta_volt_read[3];

}

/* APPARENT POWER CALCULATION, (V-rms * I-rms) */

/* first 8 plug board apparent power (V-rms * I-rms) */

for(count=0; count < 8; count++)

{

apparent_power[count] = rms_current[count] * rms_volt[1];

}/* second 8 plug board apparent power (V-rms * I-rms) */

for(count=8; count < 16; count++)

{

apparent_power[count] = rms_current[count] * rms_volt[2];

}/* Third 8 plug board apparent power (V-rms * I-rms) */

for(count=16; count < 24; count++)

{

apparent_power[count] = rms_curr[count] * rms_volt[3];

}/* POWER FACTOR CALC */

for(count=0; count < 24; count++)

{

power_factor[count] = (actual_power[count] / apparent_power[count]);

}

} /* if count == 419 */

}> My question is: I have only instantaneous current and instantaneous voltage readings

> only I am getting, using those Two can I calculate real power and apparent power,

> then using those power readings can I calculate power factor?

> My goal is to calculate power factor with instantaneous current and instantaneous voltage.

To calculate real power, apparent power, power factor, and any other cumulative values, you need to arrange samples of the instantaneous current and voltage in a correct time moments.

> Anyway below is my routine to calculate RMS current, RMS voltage from instantaneous current

> and voltage, also I did actual power and apparent power calculations.

...

> please take a look my routine below (sorry for syntax), please see logic and let me know.

> appreciated.

> please point me if I am wrong.

The referenced code contains too many errors for detail explanation of each error. In brief:

- The samples are taken in incorrect time;

- Real-time constrains are ignored.

Take samples of U at some channel and samples of I at another channel.

Most of ADC can take sample only at one channel at a time. The following trick is useful: instead of the regular sequence

U[i] -> I[i] -> U[i+1] -> I[i+1]

apply the modified sequence

U[i] -> I[i] -> I[i+1] -> U[i+1] .

The average U[j]=(U[i]+U[i+1])/2 wil be referenced to the same time moment as

the average I[j]=(I[i]+I[i+1])/2.

Power factor = RMS( I[j]*U[j] ) / (RMS( I[j] ) * RMS( U[j] )