Accurate extended sleep?

pete20r2

Senior Member
I would like to use a 28X1, since I have one with me.
All I want is for the chip to sleep for 18 HOURS, accurately, set a servo position and go to sleep for 6 hours, then move it back. It also needs to have the ability to be woken by a switch and run a separate routine, before returning to sleep.

It will need to do the same routine at the same times day in day out, is there a cheap and easy way or do I need a tome chip.

PS: The 28X1 has an OSC
 

SAborn

Senior Member
I would think an RTC would be the easiest, as it is never interupted by other functions and is just called upon for time when ever it is needed.
 

pete20r2

Senior Member
Is it only X2 parts that can doze without waking every 2.3 seconds?
If I must I will get an X2 and one of these DeadOn RTC.
I can program the RTC to interrupt the AXE at certain times of the day, is this right. I can also have another interrupt for my other routine which is independent of the clock.

Please advise.
 

hippy

Ex-Staff (retired)
All PICmicro / PICAXE sleep timers have quite a wide tolerance so you probably won't be able to get the accuracy you want using just SLEEP, NAP and similar.
 

srnet

Senior Member
What the limitation of directly poking registers on the 28x2 firmware ?

The 18F25K22 (28X2) can most certainly be setup for accurate sleep times, up to 16 seconds, by attaching a crystal (and two capacitors) to the SOSCO pins (11,12) and using one of the Timers. The SOSC keeps running in sleep, and I have a routine that wakes up the PIC every 1 - 16 seconds. Its accurate (watch crystal) and sleep current is 20uA.
 

hippy

Ex-Staff (retired)
That may work. A watch crystal and Timer 1 in my experience usually works with the PICAXE but I've never tried it in conjunction with SLEEP commands. I would guess if it keeps running one could NAP then wake up and check if Timer 1 has overflowed which may have variable latency ( the NAP time ) but should have consistent long term accuracy if Timer 1 overflows are used for all the timing. As accurate as the crystal anyway.
 

tracecom

Senior Member
I would like to use a 28X1, since I have one with me.
All I want is for the chip to sleep for 18 HOURS, accurately, set a servo position and go to sleep for 6 hours, then move it back. It also needs to have the ability to be woken by a switch and run a separate routine, before returning to sleep.

It will need to do the same routine at the same times day in day out, is there a cheap and easy way or do I need a tome chip.

PS: The 28X1 has an OSC
I accomplished a similar task without a RTC by using the pause command in a nested for/next loop. The following code should be annotated well enough to see the principle I used. You must determine the "adjustment" for your particular PICAXE by measuring the actual time and comparing it to the program time.

The accuracy was within a few seconds (8, IIRC) each 24 hours, but accumulated each day. If the PICAXE had been reset each day, the accuracy would have been as good as some clocks.
Code:
'Code by Charles R. Hampton
	'Written for PICAXE-08M, but should run (with mods) on any PICAXE with at least 4 outputs.

'Drives 1.8 degree unipolar stepper motor in single 10 ms. steps with increased torque.
	'Turns motor clockwise 60 turns, which takes 2 minutes and 11 seconds.
	'Removes power from motor.
	'Waits 5 hours, 57 minutes, and 49 seconds.
	'Turns motor counter clockwise 60 turns, which takes 2 minutes and 11 seconds.
	'Removes power from motor.
	'Waits 5 hours, 57 minutes, and 49 seconds.
	'Repeats.

'One complete cycle through "main" should take 12 hours, 0 minutes, and 0 seconds.

symbol delay = 10		'pause duration (must be at least 1 ms. or motor will not turn)
						' 10 ms. pauses results in 60 revolutions taking 2 minutes and 11 seconds
let dirs = %10110	'sets pins 4, 2, and 1 as outputs
				'pin 3 is always an input; pin 0 is always an output

main:
for b1 = 1 to 60	'sets number of complete revolutions clockwise
	for b0 = 1 to 50	'50 loops = 200 steps = 360 degrees clockwise
		let pins = %10001	'windings 2b and 1a
		pause delay
		let pins = %00011	'windings 2a and 1a
		pause delay
		let pins = %00110	'windings 1b and 2a
		pause delay
		let pins = %10100	'windings 2b and 1b
		pause delay
	next b0
next b1

let pins = %00000	'removes power from motor

for b1 = 1 to 6	'sets number of "adjusted" hours motor stopped
	for b0 = 1 to 60	'sets number of "adjusted" minutes motor stopped
		pause 59625	'stops motor for 59.636 seconds (- .011 sec. clock adjustment)
	next b0			'See Egg Turner Controller.xls for calculation details.
next b1

for b1 = 1 to 60	'sets number of complete revolutions counter clockwise
	for b0 = 1 to 50	'50 loops = 200 steps = 360 degrees counter clockwise
		let pins = %10100	'windings 2b and 1b
		pause delay
		let pins = %00110	'windings 1b and 2a
		pause delay
		let pins = %00011	'windings 2a and 1a
		pause delay
		let pins = %10001	'windings 2b and 1a
		pause delay
	next b0
next b1


let pins = %00000	'removes power from motor

for b1 = 1 to 6	'sets number of "adjusted" hours motor stopped 
	for b0 = 1 to 60	'sets number of "adjusted" minutes motor stopped
		pause 59625	'stops motor for 59.636 seconds (- .011 sec. clock adjustment)
	next b0			'See Egg Turner Controller.xls for calculation details.
next b1

goto main
 
Last edited:

SAborn

Senior Member
why not just wake up every so often and read a RTC, if the time is close to the exact time needed then stay awake and monitor RTC, if not go back to snoozing (sleep, nap)

Then none of the snoozing times matter and let the RTC do all the time keeping.
 

srnet

Senior Member
If your using a RTC, then just set the RTC with an alarm (most have one), when the time comes it generates an interrupt and wakes up the PICAXE.
 

srnet

Senior Member
I have not tested the temperature dependance of the watchdog timer in the PICAXE myself, but check that the variation in sleep times.

If the PICAXE is to be used in a temperature stable environment, it may not be much of a problem, but testing on the bench versus real life environment can be quite different.
 

pete20r2

Senior Member
Doesn't sound good to go onboard then, the application is a hot water heater. It needs to turn up the thermostat at 8 pm and turn it down to a pilot flame at 12 am. It also needs to have a manual button that turns the thermo stat high for 1 hour then turns it down again.

Since the On-chip timer is temp sensitive, going from 10 C to 70 C will not make it stable.
 
Top