Update interrupt of timer when overflow

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Update interrupt of timer when overflow

Post by mrburnette »

feluga
Posts: 64
Joined: Wed Mar 18, 2020 2:50 am

Re: Update interrupt of timer when overflow

Post 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.
herrylauu
Posts: 1
Joined: Fri Apr 21, 2023 1:33 am

Re: Update interrupt of timer when overflow

Post by herrylauu »

Set up the timer with the desired prescaler and the period for which it should count.
stumble guys lolbeans
Post Reply

Return to “General discussion”