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 */
}