I am trying to find a way how to use a timer interrupt with Arduino Every (ATMEGA 4809). I found some code example, but it doesn't work. I need periodically call a timer function, that's all. Please, could you advice or point me to some resources?
I tried this:
void start_timer(void)
{
// Use Timer/Counter TCB3 using a TOP of 10k and prescaler of /2 to run at 1kHz
TCB3.CCMP = 20000;
TCB3.INTCTRL = (1 << TCB_CAPT_bp); // Enable interrupts
TCB3.INTCTRL |= (1 << TCB_CAPT_bp); // Enable interrupts
TCB3.CTRLA |= TCB_CLKSEL_CLKDIV2_gc | TCB_ENABLE_bm; // Enable timer with prescaler of /2 to start with 10MHz frequency.
}
I'm looking / waiting for a C style timer Interrupt function. I don't like such direct register manipulations like the above "TCB3.CCMP ...." This is the way to some incompatibilities.
Is there a timer interrupt function definition for Arduino NANO Every?
An additional info to the Timer Type B at NANO Every:
I did some Experiments with the 4 type B timers in a Sketch with no #include (!). My goal is a simple timer interrupt with 20 ms period.
TCB0, TCB1 and TCB2 will work, TCB3 produces an error:
wiring.c.o (symbol from plugin): In function clockCyclesPerMicrosecondComp': (.text+0x0): multiple definition of __vector_36'
C:\Users\Rudol\AppData\Local\Temp\arduino_build_342235\sketch\TimerInterrupt.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano Every.
The wiring library seems to be automatically included and uses TCB3 exclusive?
I will update the usage description to include the MegaAvr20MHz.h include file.
As long as you don't change the clockspeed to 20 MHz, this file is not needed.
This is my first github/arduino contribution so I'm excited that it could be of
use for somebody else than me :-).
Did it help you to implement the timer interrupt functionality ?