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

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am