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

BrettTibre
Fri May 17 2024, 06:14 pm
Gordonfax
Fri May 17 2024, 10:28 am
Davidspils
Fri May 17 2024, 10:19 am
Patricknoind
Fri May 17 2024, 09:53 am
JeremyCycle
Fri May 17 2024, 09:46 am
FrabSeby
Thu May 16 2024, 07:31 pm
PeterGem
Thu May 16 2024, 06:27 am
Timothywalay
Thu May 16 2024, 04:40 am