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:
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:
Will this instruction be implemented in next version?
Can you help me?
Thanks
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).)