Reply
Posts: 48
Registered: ‎03-22-2017
Accepted Solution

C8051F501 Timer 2 Overflow Interrupt not firing

In the attached project, Timer 2 is set up as 16 bits, auto-reload, with overflow interrupt enabled at high priority.

It fires the first time the timer overflows, but after that it never fires again. I can see that the overflow bit has been set, but it doesn't fire.

Can you please look at this and tell me what's wrong? 

Thank you.

Posts: 11
Registered: ‎08-28-2017

Re: C8051F501 Timer 2 Overflow Interrupt not firing

Looks like Timer 2 over flow flag is not cleared after the first interrupt. Timer 2 overflow flag is not automatically cleared, user has to clear it

 

If this did not solve the problem, please copy and paste the Timer 2 related code in your response using insert code option

Posts: 48
Registered: ‎03-22-2017

Re: C8051F501 Timer 2 Overflow Interrupt not firing

Here is my code. I am clearing the overflow bits (even clearing the lower bit, but that shouldn't matter). You'll see a bunch of stuff commented out as I've been trying to make it work.

P37 is a #define that turns P3.7 on and off. Using that to troubleshoot with a scope on the pin.

 

INTERRUPT(Timer2_ISR, TIMER2_IRQn)
{
//U8 SFR_Temp = SFRPAGE;
//SFRPAGE = ACTIVE_PAGE;

//IE  &= ~0x80;		// disable interrupts

	   P37_On;
//	   Timer0_wait(1);
	   P37_Off;


	   Timer2_Counter++;
   if (Timer2_Counter > 20)
   {
	   Timer2_Counter = 0;
	   Timer2_Flag = 1;
	//DNM   Send_Terminal_Data();
   }
TMR2CN_TF2H = TMR2CN_TF2L = 0;                    // Clear Timer2 interrupt flags


   // SFRPAGE = SFR_Temp;
//IE |= 0x80;	// enable interrupts
}
Posts: 8,134
Registered: ‎08-13-2003

Re: C8051F501 Timer 2 Overflow Interrupt not firing

16 bit overflow is not TF2L but TF2H

erik
Posts: 48
Registered: ‎03-22-2017

Re: C8051F501 Timer 2 Overflow Interrupt not firing

I know. That's why I am resetting it.

Posts: 11
Registered: ‎08-28-2017

Re: C8051F501 Timer 2 Overflow Interrupt not firing

Are you using system clock for timer 2?

 

In Timer_Init() - you have assigned CKCON  with  0x12 (indicates system clock), but Oscillator_Init() reassign the value  0x06 .   

 

Posts: 48
Registered: ‎03-22-2017

Re: C8051F501 Timer 2 Overflow Interrupt not firing

Thanks for catching that. Fixed. But doesn't solve my ISR problem unfortunately because the Timer2 was still being clocked. I can watch the timer value overflow, and the flag set, and the interrupt settings seem to be correct, but the ISR never fires after the first time.

Still trying to figure it out. For  now I am polling the overflow flag, but of course that isn't very accurate.

Thanks

Posts: 8,134
Registered: ‎08-13-2003

Re: C8051F501 Timer 2 Overflow Interrupt not firing

[ Edited ]

if you click 'stop' , 'step', 'step' when the thingy has run a minute, does it stop in an ISR?

erik
Posts: 48
Registered: ‎03-22-2017

Re: C8051F501 Timer 2 Overflow Interrupt not firing

Yes, if I "Halt", it is always in one of the ISRs. Either the Timer0 ISR (which is used to generate delays) or in the UART ISR.

In fact, if I put a break point in the UART ISR, even when no data is being transmitted or received, it continuously breaks there. 

Is there an issue with using printf for transmitting?

Highlighted
Posts: 8,134
Registered: ‎08-13-2003

Re: C8051F501 Timer 2 Overflow Interrupt not firing

OK, I guessed right

 

either of your ISRs do not clear the flag.

 

find it, and if you can't, post the two ISRs mentioned above 

erik
Posts: 339
Registered: ‎09-22-2009

Re: C8051F501 Timer 2 Overflow Interrupt not firing

I'm guessing erikm's last post was the solution to your problem so I'm marking it as the solution. Let us know if that is not the case!