ATinny85 Sleep Flowcode

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Matrixv8
Posts: 10
http://meble-kuchenne.info.pl
Joined: Mon Jun 03, 2024 2:51 am
Been thanked: 3 times

ATinny85 Sleep Flowcode

Post by Matrixv8 »

Hi everyone, I have been trying to write a code to put ATtiny85 to sleep but with no success. I would really appreciate an example in Flowcode 10. I am using USBtiny as a programmer.

Thank you.

mnfisher
Valued Contributor
Posts: 1546
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 737 times

Re: ATinny85 Sleep Flowcode

Post by mnfisher »

It is possible to do:

In supplementary code:

Code: Select all

#include <avr/sleep.h>
Then in a code block:

Code: Select all

set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Other modes are available - see sleep.h
sleep_enable();
sleep_cpu();
sleep_disable();
You'll also need something to wake up the MCU - for example a pin change interrupt (or wdt interrupt etc)

Martin

Matrixv8
Posts: 10
Joined: Mon Jun 03, 2024 2:51 am
Been thanked: 3 times

Re: ATinny85 Sleep Flowcode

Post by Matrixv8 »

Thank you for your help.

Matrixv8
Posts: 10
Joined: Mon Jun 03, 2024 2:51 am
Been thanked: 3 times

Re: ATinny85 Sleep Flowcode

Post by Matrixv8 »

Martin it worked perfectly, the supplementary code was key. Now, I have tried everything to wakeup the ATtiny with INT0 pin7, port B2 with no success. Any idea?

PS: I will keep my questions to a minimum.

Regards,

Pierre

mnfisher
Valued Contributor
Posts: 1546
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 737 times

Re: ATinny85 Sleep Flowcode

Post by mnfisher »

Hi Pierre,

Can you post your code.

I'm not at a computer at the moment but something like:

Code: Select all

Enable interrupt 
Loop
  Sleep
  Do something 
End loop
The interrupt macro needs to be short - it doesn't need to do anything (it could be an empty macro) or it could increment a 'wake' counter.

If you are using a rising edge interrupt — the pin needs to be pulled to ground (with a resistor either internal pull-down or external) and if you are using a button watch out for bounce (which might give multiple wakes per press)
Falling edge interrupt needs internal pull up or resistor to VCC

Martin

Matrixv8
Posts: 10
Joined: Mon Jun 03, 2024 2:51 am
Been thanked: 3 times

Re: ATinny85 Sleep Flowcode

Post by Matrixv8 »

Hi Martin, thank you for your help. Attached is my Flowcode. I use a 10K pull up resistor on port B2. I use a digital high low output, so no switch noise. I send a high to low pulse. The INT micro works until the chip goes to sleep then I can not wake the chip unless I reset it.

Thank you for you help.

Pierre
Attachments
Attiny85 Test.fcfx
Feb 25, 20025
(9.96 KiB) Downloaded 25 times

mnfisher
Valued Contributor
Posts: 1546
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 737 times

Re: ATinny85 Sleep Flowcode

Post by mnfisher »

The 'sleep' is outside of your loop, so it when the MCU 'wakes' it will be just 'fall off the end of the program' - this actually just has a while(1) ; loop - NOT a reset. So move the sleep into the loop and it should work as expected (or add a 'reset' after it?)

I also forgot to mention - if using a separate device for waking then ground must be common.

Martin

Matrixv8
Posts: 10
Joined: Mon Jun 03, 2024 2:51 am
Been thanked: 3 times

Re: ATinny85 Sleep Flowcode

Post by Matrixv8 »

Hi Martin, moving the C code in the loop was the first fix to my problem, It would go to sleep but not wake up. I found that the INT0 on Attiny85 with Flowcode 10 was not waking up the micro. I had to use the IOC PortB2 and click on the Port B2 pin 7 of the chip icon inside the Inerrupt command icon for it to work. So both fix created a solution. I am attaching an example for the readers hopping that it will help them as I spent a long time to figure it out.

Again a great thanks for your quick help.

Pierre
Attachments
Attiny85 Sleep And Wake Up Working Example Code.fcfx
ATtiny85 Sleep And Wake Up Working Example Code
(10.3 KiB) Downloaded 24 times

mnfisher
Valued Contributor
Posts: 1546
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 737 times

Re: ATinny85 Sleep Flowcode

Post by mnfisher »

Thanks - glad you got it working...

Martin

Post Reply