Hi
I’ve discovered that watchdog timer is not 1,2,4,8 sec as it should be.
For 1sec configuration the real time between WDR interrupts is 1.156
For 2sec is 2.312
For 8sec is 9.251
Is it a normal behaviour (9.2sec instead of 8sec) or something’s wrong in my scetch?
#include "Arduino.h"
#include <avr/wdt.h>
volatile uint8_t wdt_h = false; //WDT interrupt flag
void setup() {
noInterrupts();
uint8_t MCUSR_c=MCUSR;//MCUSR mirroring
MCUSR=0; //reset wdt status register
WDTCSR |= (1<<WDE) | (1<<WDCE); //0b00011000; configure mode
WDTCSR = (1<<WDIE) | (1<<WDP3) | (1<<WDP0);//8 sec(WDP0, WDP3), interrupts, disable WDE (reset on timeout)
//WDTCSR = (1<<WDIE) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0);//2 sec(WDP2, WDP1, WDP0), interrupts, disable WDE (reset on timeout)
//WDTCSR = (1<<WDIE) | (1<<WDP2) | (1<<WDP1);//1 sec(WDP2, WDP1), interrupts, disable WDE (reset on timeout)
interrupts();
Serial.begin(115200);
Serial.println("start");
Serial.println(MCUSR_c);
Serial.println(millis());
}
ISR(WDT_vect) {
wdt_h = true; //wdt interrupt happens
}
void loop() {
if(wdt_h) { //if wdt interrupt happens
wdt_h=false;
unsigned long m = millis();
Serial.println("wdt");
Serial.println(m);
} else {
}
}
Output in serial monitor:
start
0
0
wdt
9251
wdt
18503
wdt
27755
...
I’m using Arduino UNO (328p)