Skip to content

Watchdog timer with interrupt support#3

Open
simonklee wants to merge 2 commits intoesmil:masterfrom
simonklee:watchdog
Open

Watchdog timer with interrupt support#3
simonklee wants to merge 2 commits intoesmil:masterfrom
simonklee:watchdog

Conversation

@simonklee
Copy link
Copy Markdown
Contributor

Was playing around with watchdog resets and added support for the watchdog interrupt timers. <avr/wdt.h> has watchdog timer reset support, but lacks the possibility to set the watchdog timer for interrupts. An example application follows.

wdt_interrupt {                    
    wdt_reset();         
    wdt_interrupt_enable();                                                                  
}                                                                         
__attribute__((noreturn)) int main (void) {                      
    wdt_reset();                                                                    
    wdt_interrupt_enable();                    
    wdt_change_clock(1024);

    sleep_mode_power_down();                                                                            
    sei();                                                                                        

    while(1) {
        /* bring avr to sleep code */
    }
}

The watchdog interrupt wakes the avr from power-down sleep mode every ~8 sec. I'm not really sure if the code I've written here is any good, especially in regards to the enabling/disabling the WD and changing prescaler settings. These routines need some extra care (see datasheets) and I solved that in the most straightforward way I could think of. So if you have some suggestions to how to do this in a better way I'm happy to modify the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant