View Single Post
  #2   Spotlight this post!  
Unread 10-02-2005, 06:33
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Securing interrupt-driven timers

Quote:
Originally Posted by Orborde
In order to ensure that the read operation on an timer+interrupt-driven clock counter variable doesn't get messed up, instead of disabling ALL interrupts, I decided to simply shut off the timer, do the read, and then turn it back on. This should keep the clock counter variable safe while allowing other interrupts to jump in and do their thing during the clock read. Is this insane?
In a word (and in my opinion): yes.

The clock read itself takes less time than an interrupt service routine. Disabling interrupts doesn't ignore them completely; it just defers them until they are reenabled. If you turn off the timer, you lose time; your counter variable runs slow. The more often you read it, the slower it gets.