Timer does not work with high-level interrupt [solved]

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Freaks,

I have run into a strange problem, and I wanted to ask, if someone could tell me why this code does not work in the way I expect it to work. In short, I would like to produce a single pulse with some predefined duration. Here is my code


ISR(TCD1_OVF_vect) {
	// This should disable all timer interrupts, including itself
	TCD1.INTCTRLA &= ~TC_OVFINTLVL_LO_gc;
	//PMIC.CTRL &= ~PMIC_HILVLEN_bm;
	//// Finally, we disable the counter itself
	TCD1.CTRLA = TC_CLKSEL_OFF_gc;
	LED_PORT.OUTCLR = LED_PIN;
}

void Timer_Duration(uint16_t millisecs4) {
	TCD1.CTRLA = TC_CLKSEL_DIV1024_gc;
	TCD1.PER = 125 * millisecs4;
	TCD1.INTCTRLA |= TC_OVFINTLVL_LO_gc;
	//PMIC.CTRL = PMIC_HILVLEN_bm;
	LED_PORT.OUTSET = LED_PIN;
}

At the time of calling Timer_Duration, the low-level interrupts will have been set up, so there is no need to tamper with the PMIC register. This code works as I expect. However, if I replace the low-level interrupts by high-level ones, it will fail. By this I mean that I can no longer communicate with the MCU via the serial port, which is hooked up to a low-level interrupt.
My question is why the high-level interrupts upset the MCU, and whether there is anything wrong with the code above.
Cheers,
Zoltán

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I have figured out what the problem was. This is the offending line:

PMIC.CTRL = PMIC_HILVLEN_bm; 

This actually disables the low-level interrupts, so when the timer interrupt is executed, and the high-level interrupts are cleared, nothing is left, and that is why the serial port would not function any more. So, the correct line is

PMIC.CTRL |= PMIC_HILVLEN_bm; 

which works as it is supposed to.
Cheers,
Zoltán