How to Sleep Until Pin Change

Here you can share completed projects or parts of projects that may be useful to others. You may post files relevant to ZBasic - source code, schematics, etc.
Post Reply
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

How to Sleep Until Pin Change

Post by dkinzer »

The attached code illustrates how to cause a ZX to sleep until a pin change event occurs. Although the example code is specific to ZX devices based on the mega644 and mega644P chips, the code could be modified for other ZX devices that support pin change interrupts. The code can also be modified to awaken on an external interrupt (e.g. INT0), analog comparator interrupt, Timer interrupt, etc.

The particular sleep mode used in the example (Power Down) is one that turns off the main clock. While this results in lower power consumption, it has the disadvantage of a slower startup time upon awakening. Generally, the clock oscillator of the CPU chip is configured for a startup delay of 16,000 clock cycles. At 14.7456MHz, this results in a startup delay of about 1mS. If a faster startup is needed, a different sleep mode can be used that keeps the main clock running, e.g. StandBy mode.
Attachments
SleepPinChange.zip
(1.43 KiB) Downloaded 3567 times
- Don Kinzer
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

I made a minor change to the example code, adding a line to disable the pin change interrupt after execution resumed. The new file replaced the older one - just download it again to get the updated version.
- Don Kinzer
Post Reply