Hi again,
Im using the ADC with 12 bits, single measure, 4MHz. CPU speed 24Mhz. TPM1 to interrupt every 1ms.
LSB=732uV
Im in a trouble. Im planning to show the values that the ADC converts to digital values. I first measure power line voltage, later the current of the phase line, and then i calculate the instantaneous power and accumulate that power to have the energy. Every sine cycle i calculate th RMS voltage (Vrms) and the RMS current (Irms). I defined the variables of Vrms and Irms like "signed long" (That's 32 bit variable), i dont know to use the floating type variables so i decided to do this way.
What im doing is something like this:
*-**-**--**-*-*-*-
static unsigned long vrms,irms,buffer_energy,cont_unit_energy,max_unit;
static signed long inst_power,;
//every 1ms the TPM1 makes a interruption
Measure Voltage1;
Measure Current;
Measure Voltage2;
Voltage_mean=voltage1+voltage2>>1; //to calc the mean voltage v_m=(v1+v2)/2
voltage_mean-=offset; //substract offset value 1.5Volts=2048 LSBs
current-=offset;
voltage_mean*=gain_voltage; //The gain that the sense circuit has
curretn*=gain_current;
voltage_pow2=voltage_mean*voltage_mean; //the sum of voltage^2 of samples
current_pow2=current*current;
if(completed_one_sine_cycle){
vrms=sqrt(voltage_pow2/numberofsamples_percycle); //calculating the RMS voltage
irms=sqrt(current_pow2/numberofsamples_percycle)
}
inst_power=voltage_mean*current;
buffer_energy+=inst_power;
if(buffer_energy>max_unit){
cont_unit_energy++;
buffer_energy-=max_unit;
}
-*-*-**-**-*-*-
That's what im doing.....I want to show the "Vrms", "irms" and the "cont_unit_energy" in the LCD.
* Irms is a long number....i was planning of first calculate how much digits in decimal it has, then show 5 Arms (Amperes RMS), 0.5 Arms, the MAX value would be 9 Arm.
* Vrms, the same, but with a MAX value of 135 Vrms.
* Cont_unit_energy, it's a counter and i think im going to make a lot of "IF" statements and display somethng like this...
10 Wh, 100Wh 1KWh, and a MAX value of 1000KWh
Thanks and appreciate your help!!!!!!!!!!!!!!!!!