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

SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am