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.
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?
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.
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.
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.
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:
#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.