Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help with the algorithm of the code

Status
Not open for further replies.

ADGAN

Full Member level 5
Full Member level 5
Joined
Oct 9, 2013
Messages
295
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Visit site
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.


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:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top