TCB0 ISR not firing on Tiny817

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

Hi there,

I am getting started with the ATTiny817 on the Xplained Mini board and am having trouble getting the TCB interrupt to work. With reference to my code below, a breakpoint in ISR(TCB0_INT_vect) is never hit and so my calculation loop never completes. It turns out that this is because it is being starved due to TCA0 being serviced because if I set CPUINT.CTRLA = CPUINT_LVL0RR_bm then both ISRs are serviced. However, the code in the TCA0 ISR is so small I'm surprised this is the case. Is there a bigger problem here, for example if I needed a third ISR?

 

Thanks,

Patrick

 

#include <atmel_start.h>
//
void TCA_setup(void);
void TCB_setup(void);
//
int loop_counter = 0;
int loop = 0;
/*
Button = PC5
LED = PC0
QT button 1 = PA6
QT button 2 = PA7
TCA waveform = PB0
*/
int main(void) {
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	//
	// Timer 1 to frequency generation mode on PB0
	TCA_setup();
	// Timer 2 to trigger position calculation every 10 milliseconds
	TCB_setup();
	//
	sei();
	while (1) {
		if (loop) {
			loop_counter++;
 			loop = 0;
		}
	}
}
//
void TCA_setup(void) {
        TCA0.SINGLE.INTFLAGS = TCA_SINGLE_CMP0_bm;
	TCA0.SINGLE.CTRLA |= TCA_SINGLE_CLKSEL_DIV8_gc;
	TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_FRQ_gc;
	TCA0.SINGLE.CTRLB |= TCA_SINGLE_CMP0EN_bm;
	TCA0.SINGLE.CMP0 = 0xFFF;
	TCA0.SINGLE.INTCTRL |= TCA_SINGLE_CMP0_bm;
	PORTB.DIRSET |= (PIN1_bm| PIN0_bm);
}
//
void TCB_setup(void) {
	TCB0.CTRLA |= TCB_ENABLE_bm;
	TCB0.INTCTRL |= TCB_CAPT_bm;
	TCB0.CCMP = 0xFF;
}
//
ISR(TCA0_CMP0_vect) {
    TCA0.SINGLE.INTFLAGS = TCA_SINGLE_CMP0_bm;
    if (command >= 0) position--;
    else position++;
}
//
ISR(TCB0_INT_vect) {
	TCB0.INTFLAGS = TCB_CAPT_bm;        // Breakpoint here never gets hit
	loop = 1;
}
//

 

Last Edited: Sat. Apr 4, 2020 - 11:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you familiar with the volatile type qualifier?

 

In consideration of others, please RTFM!

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

I think your description makes little sense since you have not enabled TCA0. TCA0 will not count if not enabled, and when it is not counting you will get no isr with what you have setup and will be quite a long wait before the counter gets to the compare vaalue.

 

Use TCA_SINGLE_ENABLE_bm, then you can figure out what attribute your isr shared variables need so your main loop continues to check the variable and not cache a copy of it.