ADGAN
Full Member level 5
- Joined
- Oct 9, 2013
- Messages
- 295
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 18
- Activity points
- 1,837
Hi! I need some help with the algorithm of my code. I want to read a meter reading from the EEPROM and add it up to the monthly consumption. After that I want to add the timer1 value to it when it increments to the meter reading. This is how I have done it.
But suppose temp = 10, at the beginning pulses = 1, then Monthly consumption is 11. In the while loop if pulses 3, then Monthly consumption is 14. But my problem is when I add pulse 3 it contains the 1st pulse also. So I'm counting the same pulse again & again. How do I solve this?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 temp = EEPROMReadInt(0x00); pulses = (count*65535)+ (TMR1H<<8 | TMR1L); Monthly_consumption = temp+ pulses; while(1){ pulses = (count*65535)+ (TMR1H<<8 | TMR1L); Monthly_consumption = Monthly_consumption + pulses; }
But suppose temp = 10, at the beginning pulses = 1, then Monthly consumption is 11. In the while loop if pulses 3, then Monthly consumption is 14. But my problem is when I add pulse 3 it contains the 1st pulse also. So I'm counting the same pulse again & again. How do I solve this?
Last edited by a moderator: