Timer v pause and sleep in Picaxe.

banda

Member
I am one of the noobies, and I am quick to say that I am ignorant in things Picaxe.
As I've said in other threads I am working ONLY in PICAXE VSM at the moment, but I'm also digesting as much as I can about Breadboarding, and translating my PICAXE VSM to the real world, which I intend to do sometime soon.

At the moment, in PICAXE VSM, I'm using the PAUSE and SLEEP concepts. I read that the timings involved are not precise,
and have had to make large allowances for any mistimings. I make the program SLEEP for an hour at a time, to be able to repeatedly check the time expired over the day, against the DS3232 clock I'm using. I know it will be different when I breadboard, but I'm hoping my hourly adjustments will keep the timing within some bounds.

Just lately I've discovered TIMER, particularly "settimer t1s_4".

Has anyone, using BREADBOARD or equivalent actually checked to see how accurate it is over an hour, say?

I'd welcome anyone's findings or comments as to the measured accuracy of PAUSE, SLEEP, or SETTIMER over a longish period of time in real life breadboarding. Do they lose time, or gain time? How much over say an hour?
 

AllyCat

Senior Member
Hi,

No replies yet, perhaps because not many of us (including me) use VSM. However, I can say something about the general clock accuracy. But you haven't said which PICaxe chip you're using, that's potentially quite important! (M2s have a "Time" variable, X-series use "Timer").

Generally the normal internal oscillator (used for Pause, Time and probably Timer) is within +/- 1%, so better than a minute per hour. The "sleep" clock is certainly not as bad as the manual implies ("-50% + 100%"), perhaps actually around +/- 5% or 10% (~5 minutes per hour). It depends if you're working at "room temperature" with a reasonably stable power supply, or looking at "worst case" situations.

It's not possible to say if a timer will gain or lose (because the target is to do neither), but it's possible to use the CALIBFREQ instruction (but probably not with VSM) to "pull" the frequency if you wish.

Cheers, Alan.
 

srnet

Senior Member
I'd welcome anyone's findings or comments as to the measured accuracy of PAUSE, SLEEP, or SETTIMER over a longish period of time in real life breadboarding. Do they lose time, or gain time? How much over say an hour?
I would not disagree with the figures Allycat has given and I have seen similar, but appreciate that you would need to check against your particular device, do not a assume that because a couple of us say 'around 1%' you will get around the same.

Some indication of how accurate & consistent you want timing, over what temperature range, what the application is and which PICAXE you are using would help as we dont have a lot to go on.
 

oracacle

Senior Member
you may well be better off using, muliple shorter timings in a loop

something like this

Code:
	for b0 = 0 to 60
	pause 1000
	next b0
this will create a i minuite pause, or fairly close.

you could go something similar with the time function, but say in 10 minuite intervals 6 times and see what you get
 

hippy

Technical Support
Staff member
Generic "how accurate is..." are difficult questions to answer because it depends on exactly what one is measuring or assessing.

"How accurate a PAUSE command is" is a little different to "how accurate will/can a programmed hour long interval be".

Even if one has an accurate delay of an hour between repeat checks, those repeated checks won't happen every hour; they will happen every hour plus the time taken to do whatever checks they perform.

The question may better be; "If I have an program which does something with regular repetitiveness, how accurate and/or repeatable can/will that regular repetitiveness be".

The answer to that is probably; it depends on how one does it. There will be raw accuracy issues, how close a SLEEP, a PAUSE or SETTIMER interrupt to how long it is expected to be, and how does or could that vary over time.

There may not be 'ready to go' answers for any of that and it may involve testing and measuring results and assessing PICmicro datasheets.
 

banda

Member
Thanks everyone for your comments and help. It's becoming more and more obvious I'll have to start getting my hands dirty and test my own questions, because my situations are unique to me and my projects. It's just that I'm a braces and belt sort, and want to know the answers before I press any buttons.

My questions have revolved around me using the SLEEP command for an hour at a time for about 20/24 hours, indefinitely. In theory, from reading the manuals, an hour could be anything up to another hour wrong. That means that I'd have to have a buffer of 2 hours before I set the time for another activity to be sure not to step too far into that activity. At 2 hours early I've changed to 1/2 hour sleeps, so that any encroachment is limited to 1/2 an hour at worst. The whole thing seem very messy, but it seems the best I can do with such coarse timing. To complicate matters I'm also using DISABLEBOD to reduce battery use to a minimum, so I want to wake the system up as little as possible.

Talk about punching above your weight !

Anyway, thanks to you all.
 

Circuit

Senior Member
Just a bit of rough and lateral thinking... you could use a PICAXE AXE033 clock module and use the alarm out pin to wake up an X2 chip which you have put into permanent sleep (SLEEP 0); to be woken by a hardware interrupt (HINT pin change) being triggered by the AXE033 module. The AXE033 has a battery life specified as ten years; would that be long enough for you? That way you could trigger a very accurate repeat 24 hour wake-up of your PICAXE, I think. Would that work for you?
 

banda

Member
Thanks for the idea. I started off by using the DS1307 clock which is part of the AXE033 module, but I found out from my reading that it is quite a poor time-keeper over a long period. That's why I'm using a DS3232, which is apparently a much more accurate clock. It also has about a ten year battery life.

Thanks, though. I welcome any help; a bit of rough and lateral thinking as much as any.
 

MartinM57

Moderator
Lateral thinking - use the alarm feature on the DS3232 to "wake up" the PICAXE, which then sets the DS3232 alarm for one hour ahead, does its stuff and goes back to sleep
...almost perfect timing but I have no code or schematic for doing so :(
 

banda

Member
I'm learning something new about Picaxe all the time.
Now I find from MartinM57 that I can simplify the setout and work to an accurate DS3232 time as well.

The trouble is though, that I'm too much a nooby to be able to carry out the ideas.

Can someone make my life complete by writing a (simple) program that will:
1. Show me how to make the DS3232 supply an interrupt at a given time.
2. Use that interrupt to waken a catatonic, deep sleeping picaxe (say 20X2, because that sort appears necessary)
which I can then do something astounding with, like lighting an LED.
3. Restart the the deep sleep, to set the sequence going again.

I can't believe that I could ditch my involved, ponderous, inaccurately timed program for something so straightforward.
I do have enough nous to analyse a working program, but the manuals are too complicated and arcane for a beginner like me.
 

crowland

Member
One way to "wake" a sleeping Picaxe using a signal line would be to use the signal to apply power - a PNP transistor in the power line, pull the base low and it turns on. The PicAxe has a pull down through a resistor to keep it on until it sets the line high. I've not tried this though, maybe there will be enough current through a dead picaxe

The timer sends a signal to turn the power on, the PicAxe starts running, does what it needs to do, and turns it's own power off.

Chris
 

srnet

Senior Member
One way to "wake" a sleeping Picaxe using a signal line would be to use the signal to apply power - a PNP transistor in the power line, pull the base low and it turns on. The PicAxe has a pull down through a resistor to keep it on until it sets the line high. I've not tried this though, maybe there will be enough current through a dead picaxe
The protection diode on the pin controlling the base of the transistor will ensure that the PNP transistor will be turned on when the PICAXE is powered off.
 
Top