Atmega8 Series Sleep mode and Watchdog Timers

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
celebriums
Posts: 125
Joined: Sun Sep 25, 2016 3:50 pm
Has thanked: 71 times
Been thanked: 33 times
Contact:

Atmega8 Series Sleep mode and Watchdog Timers

Post by celebriums »

Dear MatrixMultimedia Family

I hope you're all right. Wish success and happiness to all of 2020.

I tried to do Sleep Mod with Atmega8, but it didn't work out.

Sleep(); when I type the command as code C. I'm getting an error like the one below.

Code: Select all


D:\YandexDisk\(RF Elektroni�i) RF ID Kap� Kart�\Deneme Yaz�l�m MFRC522\Wolfer_Read_Write.c: In function 'main':
D:\YandexDisk\(RF Elektroni�i) RF ID Kap� Kart�\Deneme Yaz�l�m MFRC522\Wolfer_Read_Write.c:3411: warning: passing argument 3 of 'FCD_08061_RFID__Authenticate' discards qualifiers from pointer target type
D:\YandexDisk\(RF Elektroni�i) RF ID Kap� Kart�\Deneme Yaz�l�m MFRC522\Wolfer_Read_Write.c:3461: warning: passing argument 2 of 'FCD_08061_RFID__MifareWrite' discards qualifiers from pointer target type
D:\YandexDisk\(RF Elektroni�i) RF ID Kap� Kart�\Deneme Yaz�l�m MFRC522\Wolfer_Read_Write.c:3461: warning: passing argument 4 of 'FCD_08061_RFID__MifareWrite' discards qualifiers from pointer target type
D:\YandexDisk\(RF Elektroni�i) RF ID Kap� Kart�\Deneme Yaz�l�m MFRC522\Wolfer_Read_Write.c:3511: warning: passing argument 2 of 'FCD_08061_RFID__MifareRead' discards qualifiers from pointer target type
D:\YandexDisk\(RF Elektroni�i) RF ID Kap� Kart�\Deneme Yaz�l�m MFRC522\Wolfer_Read_Write.c:3511: warning: passing argument 4 of 'FCD_08061_RFID__MifareRead' discards qualifiers from pointer target type
C:\Users\Public\Documents\Wondershare\CreatorTemp/cclYk26W.o: In function `FCM_TMR':
Wolfer_Read_Write.c:(.text.FCM_TMR+0x2c): undefined reference to `Sleep'
Error returned from [avr-gcc.exe]
C:\Program Files (x86)\Flowcode\Compilers\avr\batchfiles\avra.bat reported error code 1
Autoclose turned off
FINISHED
Last edited by celebriums on Sun Feb 09, 2020 11:48 am, edited 3 times in total.
Sincerely Regards
Sadık SUME

www.kaandesign.com.tr

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Atmega8 Series Sleep mode

Post by mnf »

Hi Sadik,

You'll need a (in a C block or Supplementary code)

Code: Select all

#include <avr/sleep.h>
and then use

Code: Select all

sleep_enable();
sei();
sleep_cpu();
See https://www.microchip.com/webdoc/AVRLib ... sleep.html

Martin

User avatar
celebriums
Posts: 125
Joined: Sun Sep 25, 2016 3:50 pm
Has thanked: 71 times
Been thanked: 33 times
Contact:

Re: Atmega8 Series Sleep mode

Post by celebriums »

Thank you so much very quckly answer. :D

#include <avr/sleep.h> this command only worked when it was placed in the suplementary code.
Sincerely Regards
Sadık SUME

www.kaandesign.com.tr

User avatar
celebriums
Posts: 125
Joined: Sun Sep 25, 2016 3:50 pm
Has thanked: 71 times
Been thanked: 33 times
Contact:

Re: Atmega8 Series Sleep mode

Post by celebriums »

So how do I wake up this processor?
I couldn't wake him up with the watchdog.
Sincerely Regards
Sadık SUME

www.kaandesign.com.tr

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Atmega8 Series Sleep mode OK, So how do I wake up this processor?

Post by mnf »

Hi Sadik,

What sleep level are you using? Wake can be on interrupt (say rx or WDT or external) - can you post a snippet of code?

Martin

User avatar
celebriums
Posts: 125
Joined: Sun Sep 25, 2016 3:50 pm
Has thanked: 71 times
Been thanked: 33 times
Contact:

Re: Atmega8 Series Sleep mode OK, So how do I wake up this processor?

Post by celebriums »

Mr. Martin.
You can find it on the appendix.

My goal is to read rf id tag, one in the 500ms. If you don't have a TAG, keep going to sleep right away. I have to read tag for a very short time.
Attachments
Wolfer_Read_Write.fcfx
(25.98 KiB) Downloaded 200 times
Sincerely Regards
Sadık SUME

www.kaandesign.com.tr

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Atmega8 Series Sleep mode OK, So how do I wake up this processor?

Post by mnf »

Hi Sadik,

Will take a peek after work (though, with the helpful folk on the forum, you may have an answer by then :) )... In the meantime - can the RFID reader generate an interrupt on card present? If so - could this wake the processor. (A a quick glance at the datasheet didn't reveal one - generates interrupts for other events though)

The wdt interrupt is disabled in some sleep states - would a RTC chip generating an interrupt be an option - this would allow (for example) accurate timestamps when a card is read.

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Atmega8 Series Sleep mode OK, So how do I wake up this processor?

Post by mnf »

I had a brief play with your code - and compiling for ATMega8 - gave a hex too large (by 3k!) using FC8

I fixed this by changing the optimisation of the compiler from the FC default to the maximum for gcc.
(This requires editing avra.bat (in C:\Program Files (x86)\Flowcode\Common\Compilers\avr\batchfiles on my PC) -I changed the -O3 to -Os note that this is the first -O in the first line (not the second lower case))

This allowed me to compile the file.

I then added a

Code: Select all

set_sleep_mode(...)
command - I used SLEEP_MODE_PWR_SAVE - but there are six available - and I think this mode allows the wdt to wake the CPU (might take be worth trying others if it doesn't though)
(SLEEP_MODE_IDLE
SLEEP_MODE_ADC
SLEEP_MODE_PWR_DOWN
SLEEP_MODE_PWR_SAVE
SLEEP_MODE_STANDBY
SLEEP_MODE_EXT_STANDBY)

I don't have an ATMega8 to test however...

I haven't checked the logic of the RFID reader.
Wolfer_Read_Write.fcfx
(25.78 KiB) Downloaded 199 times
Martin

User avatar
celebriums
Posts: 125
Joined: Sun Sep 25, 2016 3:50 pm
Has thanked: 71 times
Been thanked: 33 times
Contact:

Re: Atmega8 Series Sleep mode OK, So how do I wake up this processor?

Post by celebriums »

Dear Martin

My goals, Run the Led connected to the D3 and D4 pin at 500ms range. to put them to sleep in idle times.
If MCU goes into sleep mode and wakes up with a watcdog timer, the software will start over. This will turn on and off at the Led 500ms interval.

Watcdog Timer command doesn't work. Or I didn't do it.

I did the following to the code suplementy before and tried again

Code: Select all

#include <avr/sleep.h>
#include <avr/wdt.h>
#include <stdint.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#define wdt_reset() \
	__asm__ __volatile__ ("wdr") 
#define WDTO_500MS 5 

Then I tried the C code macro in the Software.

Code: Select all

#include <avr/wdt.h>
#define WDTO_500MS 5 
#define wdt_reset() \
__asm__ __volatile__ ("wdr")
Attachments
Wolfer_Read_Write.fcfx
(28.46 KiB) Downloaded 199 times
Sincerely Regards
Sadık SUME

www.kaandesign.com.tr

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Atmega8 Series Sleep mode and Watchdog Timers

Post by mnf »

Hi Sadik,

I created a simple wdt example - note I use an Arduino Nano (and flash the inbuilt led on B5)

I use a custom interrupt handler to set up the wdt and a handler (an empty macro) - not sure on the code to disable the interrupt, so have left this as an exercise...

Try on Atmega8 - hopefully will work....
wdt_example.fcfx
(7.51 KiB) Downloaded 210 times
Martin

User avatar
celebriums
Posts: 125
Joined: Sun Sep 25, 2016 3:50 pm
Has thanked: 71 times
Been thanked: 33 times
Contact:

Re: Atmega8 Series Sleep mode and Watchdog Timers

Post by celebriums »

Dear Martin
Unfortunately, these codes don't work at Atmega8A.

I think the flowcode authorities need to solve this.
@Benj
Sincerely Regards
Sadık SUME

www.kaandesign.com.tr

User avatar
celebriums
Posts: 125
Joined: Sun Sep 25, 2016 3:50 pm
Has thanked: 71 times
Been thanked: 33 times
Contact:

Re: Atmega8 Series Sleep mode and Watchdog Timers

Post by celebriums »

Dear Benj

PPR0 = 0xDF;
PPR1 = 0x3F;

Dear Benj
I tried to cut off the energy of atmega8A's internal regulator and reduce the current it was in sleep mode.
https://microchipdeveloper.com/8avr:low-power-example

I opened the power.h file, the file where the above codes were called, and read it one by one.


C:\Program Files (x86)\Flowcode\Compilers\avr\avr\include\avr\power.h

according to the notes here;
"
54: \note Not all AVR devices have a Power Reduction Register (for example
55: the ATmega8). On those devices without a Power Reduction Register, the
56: power reduction macros are not available..
"

Can you possibly fix this error in this file without the ppr0 and PPR1 undefined?


https://github.com/Synapseware/avr/blob ... vr/power.h
Attachments
SleepMode(Header).fcfx
(35.7 KiB) Downloaded 162 times
power.h
(58.66 KiB) Downloaded 174 times
Sincerely Regards
Sadık SUME

www.kaandesign.com.tr

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Atmega8 Series Sleep mode and Watchdog Timers

Post by Benj »

Hi Sadik,

Our version of the AVR compiler is now quite old. It may be worth trying a newer version and pointing Flowcode at this and seeing how you get on.

You will need to copy the batchfiles folder from here.

C:\Program Files (x86)\Flowcode\Compilers\avr

To be inside the root folder of the compiler files.

Microchip has a version from 2018 here.
https://www.microchip.com/mplab/avr-sup ... -compilers

Not sure if that is the latest.

Post Reply