QUOTE(thseiler @ Jan 14 2005, 12:50 AM)
It all boils down to reading the RTC register, addind the apropriate number of seconds one wants
to sleep , and then writing this back into the Alarm Register prior to going to sleep.
Sorry to wander off-topic into reminiscence-land, but this reminds me of the old calculator-style Psion II
from the mid-80s. Its "custom chip" was basically a chain of flip-flops connected to a 32kHz crystal. This provided an interrupt every second while it was switched on, to keep its clock running (no real time clock chip). This in itself was tricky to do right, because a second could be lost each time you switched it on if you weren't careful.
But things really
got interesting when it was powered down. Every time you switched it off, it calculated how many seconds to the next alarm. It then reset the latter part of its counter chain, and
manually clocked it to the right offset
before switching off the machine. (For example, to pre-load it with 100 seconds, the processor would waggle its clock pin 100 times.) When the counter overflowed, it woke the machine up again.
Luckily, the counter chain wasn't too long, but the downside of this was that it would overflow in 34 minutes 8 seconds (which is the period of 32kHz divided by 2^the number of flip flops). The upshot of this was that even when no alarms were set, every 34 minutes and 8 seconds the Psion would be rudely awakened, update its time value by 34 minutes 8 seconds, check whether there was an alarm due in the next 34 minutes and 8 seconds, pre-load the counter if necessary, and then fall asleep again. And it would both snooze like this for months on a PP3 battery, and switch off a lot more quickly when you wanted it to than the Z running PdaXrom does!
If Psion could get that to work, surely it's not beyond the wit of man to get the Z to wake up when you want it to.