View Single Post
  #4   Spotlight this post!  
Unread 23-01-2008, 00:58
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Second clock/timer causes red light of death

A nit, but it could cause unpredictable program results - no red-light-of-death - but weird things on occasion.

The timerSecondCount is a multibyte variable. Reading it's value needs to be protected by disabling the timer interrupt enable to avoid issues.

For example, code reads lower byte and its 0xFF - before the code can operate on the upper byte a timer interrupt happens and the upper byte gets changed. The user code then reads the upper byte and completes whatever operation its working on but now it believes the timer count is a lot larger than it really is. (For example code thinks the value is 0x1FF when it is 0x100).

Code:
PIE1bits.TMR1IE = 0;
temp_int = timerSecondCount;
PIE1bits.TMR1IE = 1;
True, you're not likely to hit this... but its always better to practice safe variable access otherwise you can go bald pulling your hair out trying to find the glitch that happens every so often and apparently at random.

You only need to do this for multibyte variables that are written to within the ISR routine AND which you access at non-interrupt level.