Discussion in "Project Help" started by    cameronasmith    Dec 8, 2015.
Tue Dec 08 2015, 04:29 pm
#1
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:
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
#2
The problem is probably in the rest 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.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am