Page 1 of 1
Re: Update interrupt of timer when overflow
Posted: Wed Jan 20, 2021 12:37 am
by mrburnette
Re: Update interrupt of timer when overflow
Posted: Wed Jan 20, 2021 4:28 am
by feluga
Read this:
http://docs.leaflabs.com/static.leaflab ... timer.html
This documentation is valid for Roger's Core, which is based on LeafLabs core.
There is an example in the documentation:
Code: Select all
#define LED_RATE 500000 // in microseconds; should give 0.5Hz toggles
// We'll use timer 2
HardwareTimer timer(2);
void setup() {
// Set up the LED to blink
pinMode(BOARD_LED_PIN, OUTPUT);
// Pause the timer while we're configuring it
timer.pause();
// Set up period
timer.setPeriod(LED_RATE); // in microseconds
// Set up an interrupt on channel 1
timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update
timer.attachCompare1Interrupt(handler_led);
// Refresh the timer's count, prescale, and overflow
timer.refresh();
// Start the timer counting
timer.resume();
}
void loop() {
// Nothing! It's all in the handler_led() interrupt:
}
void handler_led(void) {
toggleLED();
}
timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update
TIMER UPDATE event is what you are looking for.