ghattas.akkad
Member level 1
- Joined
- Apr 30, 2013
- Messages
- 39
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,555
hello i am using p18f4520 to design a watt meter
after reading the voltage at AN0 and AN1 i was able to display them separately on the LCD
but whenever i multiply them together
the displayed value is always 0 i don't understand why
this is the code i am using
each acquisition ResultV and ResultI can be displayed separately but when multiplying to InstP it shows 0
after reading the voltage at AN0 and AN1 i was able to display them separately on the LCD
but whenever i multiply them together
the displayed value is always 0 i don't understand why
this is the code i am using
each acquisition ResultV and ResultI can be displayed separately but when multiplying to InstP it shows 0
Code:
while (1)
{
Delay100TCYx(4);
count=count+1;
ADCON0 = 0b11000001; // A/D on, RC clock, select RA0
ADCON0bits.GO = 1; // start A/D conversion
while (ADCON0bits.NOT_DONE); // wait until A/D conversion is complete
ResultV = ((unsigned short long) 250*ADRES+125+256)/512;
ADCON0 = 0b11000101; // A/D on, RC clock, select RA1
ADCON0bits.GO = 1; // start A/D conversion
while (ADCON0bits.NOT_DONE); // wait until A/D conversion is complete
ResultI = ((unsigned short long) 250*ADRES+125+256)/512;
InstP = ((unsigned short long)(ResultV * ResultI));
//if (count==100){
Bin2AscE(InstP, Digits); // convert voltage to ASCII
DispVarStr(&Digits[2], Ln2Ch6, 1); // display digit before DP
DispVarStr(&Digits[3], Ln2Ch8, 2); // display 2 digits after DP
//count=0;
//InstP=0;
Attachments
Last edited: