View previous topic :: View next topic |
Author |
Message |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
Wrapping an int8 Counter |
Posted: Tue Aug 15, 2006 6:47 pm |
|
|
Hello All,
I'm going to use an int8 variable to number packets and simply increment the packet number with each packet sent. Is there any need to catch when the counter equals 255 and reset it to zero? Or is it safe to just allow it to roll over?
Thanks,
John |
|
|
theteaman
Joined: 04 Aug 2006 Posts: 98
|
|
Posted: Tue Aug 15, 2006 7:01 pm |
|
|
well at 8 bits 255 is the highest number representable.. so it should work a long as its unsigned |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: Wrapping an int8 Counter |
Posted: Tue Aug 15, 2006 7:10 pm |
|
|
jecottrell wrote: | Is there any need to catch when the counter equals 255 and reset it to zero? Or is it safe to just allow it to roll over? |
I never had PIC crash or reset due to roll over, but don't take my word for it. |
|
|
MikeW
Joined: 15 Sep 2003 Posts: 184 Location: Warrington UK
|
|
Posted: Wed Aug 16, 2006 12:31 am |
|
|
my advice is it OK to just let it roll over.
done it for years |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Aug 16, 2006 10:40 am |
|
|
Counters and Timers pretty much use the same hardware. When the counter/timer register rolls over from 255 to 0, if enabled, an interrupt will occur allowing an event or special code to be executed. This type of 'roll over' is perfectly natural for the PIC. In fact, you could take advantage of this event to tell the rest of your program that it actually has rolled over.
Ronald |
|
|
|