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

Enable Watchdog Timer #204

Open
amcjen opened this issue Nov 6, 2014 · 0 comments
Open

Enable Watchdog Timer #204

amcjen opened this issue Nov 6, 2014 · 0 comments
Assignees

Comments

@amcjen
Copy link
Member

amcjen commented Nov 6, 2014

Prevents weird hung states when unplugging Scouts after configuration.

http://forum.arduino.cc/index.php?topic=63651.0

c++
/* 
Watchdog Timer Basic Example
10 June 2011
Nicolas Larsen
*/
#include <avr/wdt.h>
int loop_count = 0;
void setup()
{
 Serial.begin(9600);
 Serial.println("Starting up...");
 pinMode(13,OUTPUT);
 digitalWrite(13,HIGH);
 delay (500);
 watchdogSetup();
}
void watchdogSetup(void)
{
cli(); # # // disable all interrupts
wdt_reset(); // reset the WDT timer
/*
 WDTCSR configuration:
 WDIE = 1: Interrupt Enable
 WDE = 1 :Reset Enable
 WDP3 = 0 :For 2000ms Time-out
 WDP2 = 1 :For 2000ms Time-out
 WDP1 = 1 :For 2000ms Time-out
 WDP0 = 1 :For 2000ms Time-out
*/
// Enter Watchdog Configuration mode:
WDTCSR |= (1<<WDCE) | (1<<WDE); 
// Set Watchdog settings:
 WDTCSR = (1<<WDIE) | (1<<WDE) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0);
sei();
}
void loop()
{
for (int i = 0; i <= loop_count;i++){
 digitalWrite(13,HIGH);
 delay(100);
 digitalWrite(13,LOW);
 delay(100);
 }
 loop_count++;
 wdt_reset();
 Serial.print(loop_count);
 Serial.print(". Watchdog fed in approx. ");
 Serial.print(loop_count*200);
 Serial.println(" milliseconds.");
}
ISR(WDT_vect) // Watchdog timer interrupt.
{
// Include your code here - be careful not to use functions they may cause the interrupt to hang and 
// prevent a reset. 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants