PDA

View Full Version : Overflows "counter" in a loop



flotulopex
- 11th September 2010, 09:26
Hello,

I assume something and don't know how to test it.

While counting in a loop, how do I check, or even better count, if one ore more overflows have happened?

WHILE State = 1
Counter = Counter + 1 'Counter is WORD sized
WEND

As I use this loop as a time counter, the accuracy of the count is important. Inserting a line such as

...
IF Counter > 65535 THEN Flag = 1
...will make my timer give a wrong result.

For orientation, I have a 4MHz clocked PIC and need a count for a 1,5 second (1'500ms) period. Hoping I'm not wrong, the count should be 150'000.

So 150'000 would mean my counter has overflown 2 times and the remainder would be 18900 or so.

Again, how can I visualise the overflow(s) count and preserve the counter's accuracy?