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.
How to Sleep Until Pin Change
How to Sleep Until Pin Change
- Attachments
-
- SleepPinChange.zip
- (1.43 KiB) Downloaded 3566 times
- Don Kinzer