View Full Version : 24 hour timer system
Chris DeHut
31-01-2006, 17:17
Hi All,
I am working on a new project that will need to be fairly accurate regarding real time. I am not worried about tracking calender days and such, but rather accurately knowing when 48 hours have passed by. If it's within a few seconds, that would be accurate enough for this application.
Which way would you approach this
1) Realtime clock
2) Loops and Waits within the PICAXE
Thanks
Chris
Any PICAXE which uses an internal oscillator will be highly inaccurate if not using a reference source - at just 1% error, that's 30 mins over 48 hours. To keep within 2 minutes error over 48 hours requires an accuracy of 0.07% or better, to be within 2 seconds over 48 hours requires 0.00116% accuracy.
A PICAXE with crystal or resonator would have problems self-timing, because even if "PAUSE time" etc are 100% accurate, errors will creep in because the time of other commands being executed are not known.
PULSOUT could be used to tweak times, but altering those may also alter the timing itself, so calibrating it could prove challenging, but not impossible. I wouldn't discount it as a solution.
It would be possible for internal PICmicro timers to be monitored for overflow and counted so keeping time would be as accurate as the crystal or resonator, and that's the way I'd go, but it's not documented, nor recommended by Rev-Ed.
As an alternative to a proper RTC, mains gives a convenient 50Hz or 60Hz reference which can be polled or drive interrupts. If you have a transformer in your PSU, it should be possible to take a feed off that with nothing more than a diode and current limiting resistor.
Edited by - hippy on 1/31/2006 4:39:17 PM
Edit: Damn! Left it up too long and hippy beat me to it. Ahh well...I like his idea better anyways. About the mains I mean. A comparator and counter would do very nicely. Long term stability of an atomic clock! Just remember..short term stability of a leaf in the wind ;)
My orig. post:
well..your not going to get much mroe accurate than a crystal controlled oscillator, and for that a real time clock is the easiest way to go. Problem is the crystal. At 10ppm the thing will be out by about 1.5 seconds after 48 hours, either high or low (or could balance itself out, but that's not likely). at 50ppm the thing would be out by 8.64ish seconds. All this provided a constant temperature. It's usually not that bad, though, due to the +/- factor...it does balance itself out to an extent, but not exactly.
You could probably multiply this all by a whole lot with the picaxe, unless you used a stable crystal with a 28x or 40x, even then the timing of the commands will throw things off.
In the end, my recomendation...an RTC chip. If you can tolerate the max time skews stated above, its the way to go. If you want to pop for it, I use a DS32KHZ with a DS1307 and have been pretty happy with the results. It's worst stability is 2ppm, and they claim 2 min/year but I havn't run it long enough to back any of that up.
--Andy P
Edited by - andypro on 1/31/2006 4:47:45 PM
It's amazing how often I find I'm typing whan others are and it's luck of the draw who gets there first.
When trying to find official frequency standards on UK mains I hit a brick wall a decade ago, but with the web, you can now even watch the frequency on line ...
http://www.dynamicdemand.co.uk/grid.htm
Some interesting real world monitoring here from the Netherlands, and that worse casse 50 sconds out over as many days is still quite impressive ...
http://www.vf.utwente.nl/~ptdeboer/misc/mains.html
Now to test the "conspiracy theory" that the grid slows down during the working day and speeds up at night to extract extra work out of people for free ...
PS : Does anyone know what time standard Rev-Ed's Forum Cloxck is synched to ??? :-))
Chris DeHut
31-01-2006, 18:51
Man you guys are GREAT! I never though about the fequency of AC current as a time keeper - that is really clever!
The downside is I am too stupid to trust myself doing it that way. So, perhaps I will have to go the way of a RTC. I guess it wouldn't be bad either to that - it would be another learning experience with micros and interfacing to other stuff.
Side notes - Andy,,,
I did up a couple of I/O board using the MCP23017 chip - thank you so much for suggesting that over the 23016 - my layout is much simpler and the part count is less too!
Hippy....
Here in the U.S. it isn't a question of "IF" they slow down the clocks - it's how much they slow them down! :-)
Thanks again guys - much appreciated.
Chris
The interface is fairly straight forward, and you aren't using mains AC, only the safe seccondary side. The transformer can be a wall-wart giving AC out ...<code><pre><font size=2> |\ | ___
.---| >|--------|___|------------------------> Din
| |/ |
| VREG
| |\ | .-------.
L ----. .----^---| >|-----.------.-----| I O |-----.----> +V
) || ( |/ | __|__ __|__ `---.---' __|__
) || ( ===== --.-- | --.--
) || ( | | | |
N ----' `-----------------^------^---------^---------^----> 0V </font></pre></code> The value of resistor depends on the secondary voltage, but uses the same principle as the download circuit does.
Edited by - hippy on 1/31/2006 7:04:05 PM
Chris DeHut
31-01-2006, 21:56
You have tempted me to give it a go. Seeing as I will be needing to have a power supply of some sort, I might as well give it a try.
I can setup it on bread board and give it a run for a while to see how well it keeps time.
Again, please forgive my ignorance...
I have only built one power supply from mains to 44 volts DC. I used a bridge rectifier on that and didn't see on in your very cool ASCII schematic. So I am a bit confused.
Then, how would I calculate that resistor value. I am thinking it would be something to the effect of
Secondary voltage of Xformer - 5 Volts
then divide that by 10 milliamps for the resistor value.
Probably wrong, but I would rather try (while embarrasing myself) than to just get the answer :-(
Chris
If you copy the ascii picture and paste it into notepad, it lines itself up better, and is more clear. There are two diodes in there..I think...I dind't copy into notepad to be sure. They're just kinda garbled because of the forums formatting.
If you really need 10 ma, then your resistor calc is fine. One thing you have to be careful about, though, is that the diode will have capacitance because A) it's inherent, and B) it will be reverse biased 50% of the time, acting as a very bad varactor. Make sure that you dont choose a resistor so high that the total impedence messes up your counting scheme. Also, dont choose one so low that you burn everything up.
--Andy P
Edited by - andypro on 1/31/2006 9:56:16 PM
The single diode gives half-wave rectification and wastes half of the potential oomph, but seems to work well when I've used it with PICAXE's. The single diode is handy anyway, because it means that AC, DC or batteries can be used with no change. One disadvantage is not so frequent peaks so more ripple and can need more smoothing / bigger cap.
To calculate the resistor, it should limit the current into the pin to about 500uA ( based on docs I've read and the download cicruit ). The peak voltage is about 1.4x the average ( read by a DMM ), so, V=IR ...
[ Edit : Corrected equation ]
R = Vavg * 1.4 * 2000
A bit higher shouldn't be a problem. I'd start doubled and work down.
Edited by - hippy on 2/1/2006 12:40:13 PM
HamRadioAddict
01-02-2006, 00:48
Hello Chris,
Just a bit of food for thought. Maybe check the AC mains frequency for accuracy and stability before using it for accurate time keeping.
When I used to live in a tiny tiny Australian outback gold mining town which produced it’s own power, I constantly had to adjust my alarm clock. It’s been a long time ago but I think it was about once every two or three weeks. Always seemed to find myself getting up for work a little bit earlier every morning until it got ridiculous. Then I’d change the alarm clock back to the correct time.
I’m sure any big city AC mains would be just fine.
Steve VK6HV
premelec
01-02-2006, 03:00
A "quartz clock" has accurate crsytal controlled 1 second [often alternating pos and neg] timing pulses to the hands driver motor... 1.2VDC volts runs it 'forever' and they can be got cheap...
Jeremy Leach
01-02-2006, 08:21
Just picking up on Hippy's comment:
<i>A PICAXE with crystal or resonator would have problems self-timing, because even if "PAUSE time" etc are 100% accurate, errors will creep in because the time of other commands being executed are not known </i>
Ok, we haven't got a list of accurate command times, but I would have thought that with crystal control a set of commands will always take virtually exactly the same duration to run.
So there would be scope to experiment with loops until an exact timing mechanism could be worked out. I'm not saying it would be easy though !
Chris DeHut
01-02-2006, 12:43
Wow,
This is really turning into a facinating subject (thread). I live outside the Chicago IL area. Our electric service is usually over volted a bit - and pretty reliable. As we have a Nuclear reactor about 50 miles west, I suppose that is where my electricity orignates from.
While reading through this and getting really excited about trying it (using the AC wave as a "clock signal"), it dawned on me that there could be another problem :-(
If the AC power failed during a storm or something, the "time keeper" would be lost, even with a battery back up system. So, I don't know how to overcome that problem.
Even so, I still think I am going to do it with the AC time keeper thing just because it is so darn neat. Perhaps I could incorporate both a realtime clock and the AC circuit time keeper and have the one check the other.
Darn it, what started out as a fairly boring project I have to do (it's on the "Honey-do" list) is certainly getting more and more interesting by the day!
Thanks guys
Chris
Mycroft2152
01-02-2006, 13:01
Premelec, have you interfaced the quartz clock to a picaxe> If so, what circuit did you use?
Myc
Jeremy : Most PICAXE commands are fairly consistent, but not all if they may depend upon data values, ie, "b0=b0*b1", "IF b0 > 256 THEN" <i>may </i> be faster if b0 is zero. But I agree, it's not impossible.
Chris : Loss of mains is a problem. If you diode mix batteries into the VREG, as long as the rectified AC is greater than battery voltage you have a backup supply. You could also diode mix the VREG output and batteries to achieve the same.
You should be able to create a free-wheeling internal clock which isn't as accurate as mains, and let that take over when mains is lost. Another ideal scenario in which to use multiple PICAXE's - Here's an untested PICAXE-08M example which gives a 1Hz signal out synchronised to mains when available or free-running otherwise ...<code><pre><font size=2>; Pin0 1Hz output
; Pin1 Mains input
; Pin2 Used for PULSOUT timing </font></pre></code> <code><pre><font size=2>PowerOnReset:
INPUT 1
SETINT %00000010,%00000010 ; Interrupt when Pin1 High </font></pre></code> <code><pre><font size=2>FreeWheel:
PULSOUT 2,??? ; Make whole loop 10mS
w0 = w0 + 10 ; Count 10mS's
IF w0 < 500 THEN FreeWheel ; Toggle every 500mS
TOGGLE 0 ; 1Hz on Pin0 output
w0 = 0 ; Reset counter
GOTO FreeWheel ; Keep going forever </font></pre></code> <code><pre><font size=2>Interrupt:
IF pin1 = 1 THEN Interrupt ; Wait until interrupt pulse is gone
w1 = w1 + 1 ; Count mains cycles
IF w1 < 25 THEN NoToggle ; Toggle every 30 (60Hz) or 25 (50Hz)
TOGGLE 0 ; 1Hz on Pin0 output
w1 = 0 ; reset mains cycle counter
NoToggle:
w0 = 0 ; Reset the free-wheeling counter
SETINT %00000010,%00000010 ; Interrupt on next Pin1 High
RETURN ; Finished interrupt </font></pre></code>
premelec
01-02-2006, 18:48
I haven't had occasion for accurate timing on a PICAXE yet - did use clock electronics several years ago on a STAMP - My recolection is that I fed the clock drive pulse into the base of a bipolar transistor with resistor in collector [emitter grounded]to +5 volts and that went to a CMOS flipflop clock input to square up and lengthen the 1 second period [or 2 seconds for same pulse polatity from clock]. There also used to be a chip which turned a 32.x KHz crystal into a 60HZ output and also a chip to 50Hz - I used that on a Commodore VIC20 running on battery. Sorry I don't have the chip #s - I think they were National Semiconductor products.
BTW a 555 can be used as a synchronized 60Hz or whatever source and is quite stable free running IF you use quality temperature stable timing cmponents [R & C]. CMOS 555s draw very little current and there's a 3v version also if I recall correctly......
Edited by - premelec on 2/1/2006 5:54:17 PM
Mycroft2152
02-02-2006, 01:21
I remember that chip from my VIC 20 days too!. I probably have it still in one of my junk boxes.
Yes the ol' 555 can be also be used for a stable time base with a 32.xxx crystal.
I realse that an RTC chip is the proper way to go, But for a simple stable time base the clock guts would be ideal.
Myc
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.