View Full Version : Counter bigger than a var word/65K - overflow
jorge
- 18th January 2006, 23:00
hello "smart people" :-)
i need a var that counts over the 65k limit of the var word and save it to the internal EEPROM of the uC, is there an "elegant way"/smart way of coding it than using and additional var word that increments everytime the main counter var word gets overflow ?
thanks in advance for any info/trick :-)
p5taylor
- 20th January 2006, 14:33
Hi jorge did you solve the problem at the thread listed below as i have the same problem any help greatly recieved thanks
http://www.picbasic.co.uk/forum/showthread.php?t=3127&highlight=COUNTER
TonyCNC
- 21st January 2006, 12:29
hi
maybe you could have two word sized varables say Cnt_a and Cnt_b
when Cnt_a hits 65536 increment Cnt_b ,clear Cnt_a and start counting again
Cnt_b is the number of times you reached 65K add Cnt_a gives you the Total
count.
boboco
- 21st January 2006, 13:12
Hi,
as Tony says, word Cnt-A wrap-around to count up Cnt-B once.
A simple method as example;
IF newcount then Flag = 0 'Flag to prevent first count setting B
WHILE countup 'As long as counting is required
WHILE Cnt-A > 0 AND Flag = 1 'Counting in progress
Cnt-A = Cnt-A + 1 ' Count operation for A
Flag = 1
WEND
Cnt-B = Cnt-B + 1
WEND
in eeprom simply:
WRITE 0, Cnt-A.byte1
WRITE 1, Cnt-A.byte0
WRITE 2, Cnt-B.byte1
WRITE 3, Cnt-B.byte0
Hope it helps,
Rob
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.