Jorge Andres Reyes Alvarez

LCD 2x16 Visualization using MCF51QE and Codewarrior 6.2

Discussion created by Jorge Andres Reyes Alvarez on Apr 21, 2009
Latest reply on Apr 21, 2009 by Jorge Andres Reyes Alvarez

Hi again,


Im using the ADC with 12 bits, single measure, 4MHz. CPU speed 24Mhz. TPM1 to interrupt every 1ms.



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



voltage_mean*=gain_voltage;      //The gain that the sense circuit has



voltage_pow2=voltage_mean*voltage_mean;       //the sum of voltage^2 of samples




   vrms=sqrt(voltage_pow2/numberofsamples_percycle);     //calculating the RMS voltage















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!!!!!!!!!!!!!!!!!