Skip to content

millis() prevents entering to sleep #155

@lazarevd

Description

@lazarevd

If millis() function appears anywhere in loop(), it prevents enetering to sleep mode. The position of millis() doesn`t matter, it could be after sleep_cpu().
micros() works normally.

#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/power.h>
#define LED PB0

void setup() {
  pinMode(LED, OUTPUT);
  delay(500);
}

void loop() {
  analogWrite(LED, 0);
  delay(200);
  analogWrite(LED, 250);
  delay(200);
  analogWrite(LED, 0);
  system_sleep();
  millis();//commenting this line let attiny13 enter to sleep, if i uncomment it, led blinks continously
}

void system_sleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sei();
  sleep_cpu();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions