Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchdog timer with interrupt support #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

simonklee
Copy link
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