Go Down

Topic: ATtiny13 sleep mode watchdog timer (Read 118 times) previous topic - next topic



I tried to use the attiny13a for switching a LED on after 15 minutes. 
I have fonud a code which should do this every 8s. If that would work, I would try to extend the code to go to the 15 minutes. 
but it just do not work. 
The LED swtiches on noly one time in the beginning, switches of and then the ATtiny seems to go into the sleep mode (~5uA current messuared).
But it never wakes up again. 
I use 1.2MHz internal as clock speed in Arduino IDE.
Can anyone help me?

Code: [Select]
#include <avr/interrupt.h>
#include <avr/sleep.h>
// Pin 4 for LED
int led = 4;
ISR(WDT_vect) {
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);               // wait for a second
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
// prescale timer to 8s so we can measure current
WDTCR |= (1<<WDP3 )|(0<<WDP2 )|(0<<WDP1)|(1<<WDP0); // 8s
// Enable watchdog timer interrupts
WDTCR |= (1<<WDTIE);
sei(); // Enable global interrupts
// Use the Power Down sleep mode
for (;;) {
sleep_mode();   // go to sleep and wait for interrupt...
// the loop routine runs over and over again forever:
void loop() {


The delay() statements don't work  in an ISR and will return immediately, so you will not see the LED flash.
Set it on in the ISR and set if off in the loop() after 1 second.


Nov 21, 2020, 07:18 pm Last Edit: Nov 21, 2020, 07:22 pm by jremington
Don't do this in an ISR:
Code: [Select]

To effectively sleep for longer periods than the watchdog timer allows, your program should just count watchdog wakeups, then go back to sleep until it is time to do something else.

In this case the watchdog ISR should be empty.

Go Up