8051 timer inconsistant
Discussion in "Project Help" started by cameronasmith Dec 8, 2015.
Tue Dec 08 2015, 04:29 pm
Hi,
I have timer2 running on an interrupt and 99% of the time it works correctly, but sometimes the timer doesn't start or at least it doesn't enter this forever loop, Please could anyone give me any suggestions?
This is my interrupt:
I have timer2 running on an interrupt and 99% of the time it works correctly, but sometimes the timer doesn't start or at least it doesn't enter this forever loop, Please could anyone give me any suggestions?
This is my interrupt:
void timer2_ISR (void) interrupt 5 { timer2Count++; if (timer2Count > 50) { if (speedSensorCount < MIN_SPEED_DISC_TIMER) { // stop timer2 TR2 = 0; // turn motors off FMOTOR = 1; BMOTOR = 1; GREENLED = 0; REDLED = 0; // loop forever for(;;) { beep(); delayApplication(30); REDLED = !REDLED; GREENLED = !GREENLED; } } else { timer2Count = 0; } } TF2 = 0; /* Clear the interrupt request */ }
[ Edited Tue Dec 08 2015, 04:30 pm ]
Wed Dec 09 2015, 12:51 am
The problem is probably in the rest of the code,
most likely in how speedSensorCount is set.
I would not put
in an interrupt handler, it belongs in the main body of the code.
most likely in how speedSensorCount is set.
I would not put
// loop forever for(;;) { beep(); delayApplication(30); REDLED = !REDLED; GREENLED = !GREENLED; }
in an interrupt handler, it belongs in the main body of the code.
Powered by e107 Forum System