Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Attiny85 - sleep problem

2 posters

Go down  Message [Page 1 of 1]

1Attiny85 - sleep problem Empty Attiny85 - sleep problem Mon Jan 24, 2022 9:34 am

stedrum



Hi all,

I'm trying to simulate a simple circuit with use of a attiny85.
The goal of circuit is to put mcu into sleep mode and wake only on pin change interrupt.

I tried the code with real hardware and it works; but when I put the firmware into simulated attiny85, the code runs infinitely without enter sleep mode. It seems tha simulide ignores the sleep part

This is the code:
Code:
#include <PinChangeInterrupt.h>

#include <avr/sleep.h>    // Sleep Modes https://goo.gl/WJUszs
#include <avr/power.h>    // Power management https://goo.gl/58Vdvv

#define LED 3 // D3
#define SWITCH 4 // D4

void setup () {
  pinMode (LED, OUTPUT);
  pinMode (SWITCH, INPUT_PULLUP); // internal pull-up
  // Valid interrupt modes are: RISING, FALLING or CHANGE
  attachPCINT(digitalPinToPinChangeInterrupt(SWITCH), wakeUpNow, FALLING);
}

void loop () {
  digitalWrite (LED, HIGH);
  delay (2000);
  digitalWrite (LED, LOW);
  delay (2000);
  goToSleep ();
}  // end of loop

void wakeUpNow() {
  // execute code here after wake-up before returning to the loop() function
  // timers and code using timers (serial.print and more...) will not work here.
  // we don't really need to execute any special functions here, since we
  // just want the thing to wake up
}

void goToSleep () {
  //    * The 5 different modes are:
  //     *     SLEEP_MODE_IDLE         -the least power savings
  //     *     SLEEP_MODE_ADC
  //     *     SLEEP_MODE_PWR_SAVE
  //     *     SLEEP_MODE_STANDBY
  //     *     SLEEP_MODE_PWR_DOWN     -the most power savings
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // <avr/sleep.h>
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface <avr/power.h>
  sleep_enable(); // <avr/sleep.h>
  sleep_cpu(); // <avr/sleep.h>
  //---------------  THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP ---------------
  sleep_disable();// <avr/sleep.h>
  power_all_enable();    // power everything back on <avr/power.h>
}


EDIT: I'm using simulide_0.4.15-SR9.AppImage

EDIT 2: Found the problem:
Tried with unstable simulide version and in console I see this message:
ERROR: AVR SLEEP instruction not implemented

Will this instruction be implemented in next version?
Can you help me?
Thanks



Last edited by arcachofo on Mon Jan 24, 2022 11:10 am; edited 1 time in total (Reason for editing : Mark as unsolved (Red color).)

2Attiny85 - sleep problem Empty Re: Attiny85 - sleep problem Mon Jan 24, 2022 11:05 am

arcachofo

arcachofo

Will this instruction be implemented in next version?
Yes, I will have a look and let you know when it's done.

stedrum likes this post

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum