After countless of tries, I still didn't figure, why I cant get it to work...
I'm using an ATMEGA1608 (Datasheet) with the following code. Pin D6 has a LED connected.
#include <avr/interrupt.h>
#include <avr/io.h>
int main() {
PORTD.DIRSET = (1 << 6); //output
TCB0.CCMP = 128;
TCB0.INTCTRL = 1;
TCB0.CTRLA |= TCB_ENABLE_bm;
sei();
while(1);
}
ISR(TCB0_INT_vect) {
PORTD.OUTTGL = (1 << 6);
}
But no matter, what I am trying, the interrupt is not beeing executed.
What I have tried:
- as per datasheet section "21.3.2 Initialization", I tried without "the line TCB0.INTCTRL = 1;"
- If put the "PORTD.OUTTGL = (1 << 7);" into the while loop, the LED works.
- Thinking, I am missing something, I have resorted to the ArduinoCode-MegaAvr code on github.
From wiring.c init() function I can see, that the timer is initialized in the same way...
_timer->CCMP = TIME_TRACKING_TIMER_PERIOD;
/* Enable timer interrupt */
_timer->INTCTRL |= TCB_CAPT_bm;
/* Clock selection -> same as TCA (F_CPU/64 -- 250kHz) */
_timer->CTRLA = TCB_CLKSEL_CLKTCA_gc;
/* Enable & start */
_timer->CTRLA |= TCB_ENABLE_bm;
sei();
So my question: What am I doing wrong / how to get the periodic timer on TCB0 work?
Edit 1:
I now figured, if I compile it for ATMEGA1608 and then flash the HEX file to my 808 the interrupt is executed - but with a fixed frequency of 46kHz (no matter what I write in the CCMP register or in the TCB0.CTRLA - clock pre-scaler bits)...
Edit 2:
Downloaded ATMEL Studio 7 with the latest device packages 2.0.401 - as I suspected an issue with my buildchain - also not with the desired result. I get the interrupt to be executed - but not with the CCMP value as top. The frequency remains 46kHz...