alapmac

alapmac

New Member
I am new to picaxe but have used pics previously using logicator flowcharts. I want to build a tide clock based on the moon phases. Output will be in the form of 8 to 12 LED's lighting on the 'moon hour'.
I was hoping to use a picaxe but it would appear that the internal clock is inacurate. I would like the device to be accurate to within about 5 minutes per month (10 seconds per day).
Do I need to use an external resonator or seperate chip to achieve this accuracy?
Thanks
Tony
 

BeanieBots

Moderator
I've moved your thread to a more appropriate section of the forum.

For accurate timing you should be looking at using a crystal.
A chip with a resonator would be better than one using an internal oscillator but your code would still need to do the hard work. Consider using a clock chip such as the DS1307.

Have a read of this thread for some other ideas:-
http://www.picaxeforum.co.uk/showthread.php?t=7838
 
Last edited:

hippy

Technical Support
Staff member
Two other options are : synchronised to the mains frequency if PSU used ( an AC adapter is needed ), only a simple resistor circuit needed there, or with the right PICAXE (08M, 18A, 18X, and probably 14M ) a watch crystal connected running an internal timer. That gets a bit more complicated software wise.
 

Michael 2727

Senior Member
I was thinking about this application a few weeks ago,
with an 08M you could expect a drift of up to 3.5 mins
each day, from testing an 08M stop watch app.
An accurate time base can be made with a 4040
or 4060 and a 32KHz watch XTL.
I was working on a lunar cycle of 89,424 seconds.
You still need calibration for the particular area
you live or intend to use the unit, e.g. + or - times
from the nearest tidal reference point.
 

hippy

Technical Support
Staff member
I was thinking about this application a few weeks ago,
with an 08M you could expect a drift of up to 3.5 mins each day, from testing an 08M stop watch app.
You really need to look at the PICmicro datasheet. Only at 25'C and running from 3.5V is the 08M's oscillator guaranteed 1% accurate, outside that it's at least 2%. With 24*60 minutes to a day, a 2% inaccuracy is just short of 30 minutes.

A PICAXE-08M will often perform more accurately than that as demonstrated but it cannot be relied upon.
 

alapmac

New Member
Tide clock

Thanks for all your comments. I think I need to do some more reading to catch up with your technical talk!
If I use a clock crystal with 4060 would I be better off using a DS1307. Problem is I do not yet understand how the DS1307 and Picaxe are used together.
Thanks once again
Tony
 

Michael 2727

Senior Member
What Hippy said also,
I only tested 3 or 4, 08M chips and over a 15 min period.
The point being an 08M does not make a very accurate
clock under normal conditions.

I don't know much about the DS1307, (you could read the Spec Sheet)
and I only use 4060s with RC timing components, but over a 1 month
period using a 32KHz XTL I would think the drift would only be a few Secs.
The 50Hz mains option works well but not much good for portable devices.
If I used the 50Hz option here, I'd be better off with an 08M clock, as the
mains drops out on a regular basis, 3 weeks continuous would be a record here.
 

hippy

Technical Support
Staff member
One solution to mains drop-out, which will happen, is to specify a time window in which the mains pulse must have occured, and if it doesn't, switch to PAUSE timing until it comes back again. You'll lose or gain some time while the mains is out but hopefully not too much.
 

papaof2

Senior Member
With a stable ambient temperature, I've been able to trim the code on an 18A (by tweaking a wait loop) to get ~10 seconds/hour (4 minutes/day) accuracy.

First see how long your actual computing code runs (number of passes in 1 hour).

Then add in short delay loops (i.e., for X = 1 to 10: pause 100: next X) and see how much tweaking is needed after a 1 hour run.

Then let the tweaked code run for 24 hours and see how much adjustment is needed.

Then check it after a week and see if more adjustment is needed.

Sample code http://www.picaxe.us/software-clock.html

Of do as previously suggested and add an accurate time base (DS13xx or battery clock).

John
 
Last edited:

hippy

Technical Support
Staff member
@ papaof2 : That's the sort of accuracy I was managing to get with some tweaking. I used PULSOUT on an unused pin ( or a LED if a small amount of flicker can be tolerated ) for finer adjustment. The oscillator errors usually stay fairly constant if the environment does not change.

The problem with tweaking PICAXE code is that changes to any numbers which set the calibration can change the entire program's timing. The way round that is to use a variable instead of a constant and have the variable set to the desired constant value in a subroutine which is at the very end of source code, with a Gosub to it at the start.

Code timing should only alter when changing numbers between 1-bit, 4-bit, 8-bit and 16-bit numbers ( 0-1, 2-15, 16-255, 256-65535 ), but any small change to source code can alter timing quite significantly. Get the code working exactly how it's wanted first, then set about making timing accurate.
 

solderman

New Member
Alapmac...interesting issue, timing. I guess the 4060 is an easy fix as 32k Xtals are really good - ideally keep in a large insulated mass, but that's picky.
+PicAxe does have a "clock" module. . . . . but that's too easy, eh?
Another solution is a cheap alarm clock - most are quartz and "tick" every minute (or every second). Detect with electret mic ( or, a piezo Araldited to the case). This has the advantage the clock can display the time ( so it's easy to check, if it's slipping) - and you get a piece of kit that "says Time-clock".
Because the ticks are infrequent the PicAxe can get on with the calculations between ticks. I suspect the 1-minute tick would suit best, 1-second is rather frequent so you might need to store the tick-count (er, in a 4000-series counter - so there is a place for tick-count, should your program not pick-up the tick. If this counter ran for seveal hours before overflow then, if the mains is interupted, you can "catch-up") - obviously the count IC needs a battery!.
+ Hope that is food for thought.
 
Top