Can't seem to find any information on the timers. I have an application working on a Leonardo that I want to use the wifi for but I need a timed interrupt between 3 and 5k per second. With this board none of the usual timer1 keywords are recognized. Only cli(); and sei(); don't trigger errors.
I thought maybe I could change the timer number to what the rev2 uses but so far that doesn't seem to be the case.
Anyone know of a page detailing the use of the rev2 timers?
// TIMER 1 for interrupt frequency 5000 Hz:
cli(); // stop interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
// set compare match register for 5000 Hz increments
OCR1A = 3199; // = 16000000 / (1 * 5000) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12, CS11 and CS10 bits for 1 prescaler
TCCR1B |= (0 << CS12) | (0 << CS11) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); // allow interrupts
pmeloy:
I did look through it but there's exactly three mentions of timers with no actual information... Just that there's TCA, TCB, RTC and WD timers.
By default TCA0 (there is only one timer of type A) is in use for the standard millis() etc functions. It's clocked at 250000 ticks per second, and you can use that timer as a base for timers of type B.
Here's example code for configuring Timer B0 to 10 Hz, which is what I currently use in my project. This is based on the documentation in the second PDF that was linked. Also don't count on this ever being in the standard Arduino library, they don't support timers on the most common boards either.
TCB0.CTRLB = TCB_CNTMODE_INT_gc; // Use timer compare mode
TCB0.CCMP = 25000; // Value to compare with. This is 1/10th of the tick rate, so 10 Hz
TCB0.INTCTRL = TCB_CAPT_bm; // Enable the interrupt
TCB0.CTRLA = TCB_CLKSEL_CLKTCA_gc | TCB_ENABLE_bm; // Use Timer A as clock, enable timer
And the interrupt handler:
ISR(TCB0_INT_vect)
{
// Do something
// Clear interrupt flag
TCB0.INTFLAGS = TCB_CAPT_bm;
}
Oh, it seems like i've stumbled upon the Wifi Rev2's fatal weakness. I already use interrupts in my sketch for my robot and it seems like this board is not yet ready for what i need if i have to swap my UNO for this one with Wifi connectivity. This is sad.
DryRun:
this board is not yet ready for what i need
What do you mean by that?
As far as Arduino's attachInterrupt(), detachInterrupt(), interrupts() and nointerrupts() functions go, the Uno WiFi Rev2 should be as "ready" as the Uno.
I'm sure if you're working directly with the registers, the Uno WiFi Rev2 is just as "ready" as the Uno.
If you're using a 3rd party library or tutorial to make it easy to work with interrupts then you very well might not consider it as "ready" as the Uno, since the community support for this board is still in the early stages