328p Powersave

Discussion specific to the DIP and TQFP packaged ZX devices like the ZX-40, ZX-44, ZX-32 and ZX-328 series. The differences between these devices is primarily the packaging and pinout so most issues will apply to all devices.
Post Reply
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

328p Powersave

Post by sturgessb »

Hello all, long time.

I'm messing about with power consumption on the 328, with mixed results.
Power_down and Standby seems to be working as expected but Power_save doesn't seem to do anything?

Missing something?

Code: Select all

Register.SMCR = &H07
Call CPUSleep()
Cheers
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: 328p Powersave

Post by dkinzer »

sturgessb wrote:Power_save doesn't seem to do anything?
Is Timer2 running, e.g. are software UART channels open?
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Yes I have 2 software com ports open. I presume this is forcing it to wake up?

It's no biggy, I have powerdown working and it counting the number of watchdog resets so I can perform actions after a set number of them. Seems to be working well.

B
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

sturgessb wrote:Yes I have 2 software com ports open. I presume this is forcing it to wake up?
The documentation of PowerSave mode indicates that a Timer2 overflow or compare-match interrupt will bring it out of power save mode. On the mega328P, Timer2 is the software UART timer and it is configured to generate a compare-match interrupt at a rate of four times the bit rate configured by the ComChannels() call. If configured for only one channel (the default) the interrupt rate is four times the baud rate of the channel when it is open. When all software UART channels are closed, the timer is turned off.
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Ok thanks Don.

Powerdown is working well for what I need. However I am having an issue with counting the number of resets (from the watchdog).

Im using the following to find a space of memory which is not being or going to be used, but I have a feeling its not doing its job as I'm getting strange values popping into the variable from time to time.

Code: Select all

PUBLIC sleepcount as Byte Based (Register.userSP + 300)
I'd rather not use persistent mem as this will limit the lifespan of device to around 90days of continuous running (based on 8 second watchdog).

I guess i could rotate the persistent mem space? Or is there a way of reserving volatile space safely?

Cheers

B
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

sturgessb wrote:Im using the following to find a space of memory which is not being or going to be used, but I have a feeling its not doing its job as I'm getting strange values popping into the variable from time to time.
What you need is to define a variable in such a way that it won't be initialized by the runtime startup. There isn't a way to do that directly in ZBasic but you can do it by using a little bit of C code:

Code: Select all

#c
uint8_t myVar __attribute__((section(".noinit")));
#endc
Declare myVar as Byte

Sub Main()
   myVar = 10
End Sub
The variable myVar is defined in the C code with a special attribute that directs the linker to put it in the section of RAM that does not get initialized. The ZBasic Declare statement is then used to allow ZBasic code to refer to the variable.

If you need a 16-bit variable, use uint16_t or if you need a 32-bit variable, use uint32_t.
- Don Kinzer
Post Reply