CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Wrapping an int8 Counter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

Wrapping an int8 Counter
PostPosted: Tue Aug 15, 2006 6:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 15, 2006 7:01 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Wrapping an int8 Counter
PostPosted: Tue Aug 15, 2006 7:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 12:31 am     Reply with quote

my advice is it OK to just let it roll over.

done it for years
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 10:40 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group