Better Time Keeping
Philldapill
Posts: 1,283
Hey again. I'm working on making·a simple clock with the prop. I'm displaying it on the TV screen(thanks guys). I am testing to see the accuracy of it and I'm not very pleased. It loses about 1/2 second in three hours. I know this because I have a wall clock that keeps time very well and I'm watching the clock ticks vs. the prop seconds on the screen. I have the setup synchronized at first, but after 3 hours tonight I noticed the lag. The code is below but I have a feeling to regain that 1/2 second, I'll have to use some ASM code... Here is the basis of what I have. I've deleted what I know for a fact makes no difference.
PUB Main |·temp
· temp := cnt·· 'set the tick time to now
· repeat
··· 'Do some code that was deleted
··· text.dec(sec)·· 'output the seconds
··· sec++··· 'Increment seconds
····························
··· WAITCNT(temp)· 'Wait until specified time
··· temp += clkfreq·· 'increment temp 1 second - Maybe make this faster addition?
PUB Main |·temp
· temp := cnt·· 'set the tick time to now
· repeat
··· 'Do some code that was deleted
··· text.dec(sec)·· 'output the seconds
··· sec++··· 'Increment seconds
····························
··· WAITCNT(temp)· 'Wait until specified time
··· temp += clkfreq·· 'increment temp 1 second - Maybe make this faster addition?
Comments
As for the cyrstal, it's fine for what I'm doing. It will only be used as a system clock for scheduling tasks Weekly. I just figured that a clock tick or two that it takes to add the temp and clkfreq was causing the offset. I understand it as this:
Capture clock time and add 1 second(that's where my error was in the a.m. code)...
-Loop-
Wait until temp time
Add 1 second to temp and loop back to starting loop(this seems like it would take a couple clock cycles to add which this cpu time would eventually add up to 1/2 second over 3 hours)
Now, let's just say that the crystal is an atomic clock and perfectly accurate... 2 clock cycles over 3 hours would be... 1/80mhz * 2 cycles * 60sec * 60min * 3hrs = 0.00027 seconds. I guess 2 clock cycles isn't a big deal after all.
Thanks Mike! I guess that wraps up that question.
But I'm not sure this will suffice over the long run. For the ultimate in accuracy, if that's what you're after, you may have to resort to external synchronization (GPS or WWV, for example) or an external chip (TCXO, for example) to do your timekeeping for you.
-Phil
Update: To make the clock run faster, you diminish the time increment, not augment it.
Post Edited (Phil Pilgrim (PhiPi)) : 1/4/2008 8:41:00 AM GMT
-Phil
Crystals - though in principle 100 times more precise - are generally not good adapted to the environment of load to a microcintroller. As most microcontrollers need additional cap loads of around 22pF at each crystal lead anyhow they can easily be tuned to a better adaption by a 30pF trim cap. This will improve accuracy by an order of magnitude (1 sec/day). A software calibration as described by Phil has a similar effect.
To get more you have to compensate for temperature (as Phil already said) using more expensive but still affordable compensated oscilators.
Why is our cheap watch so more precise?
(a) It's crystal is perfectly adpted.
(b) It is only precise when you wear it (30°C)!
WWVB is transmitted at a frequency of 60 kHz, which is within the A/D capabilities of the Prop, and it is amplitude modulated at two different levels to transmit the bits.· Seems feasible with minimal external componentry.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Post Edited (Ken Peterson) : 1/4/2008 4:34:49 PM GMT
To make your life easier, you could tack on a cheap RF front-end module like this one, which DigiKey carries for $9.45.
-Phil
It needs a ferrite coil and a HF transistor. Code is available from Marcel Majoor. I don't know where he posted it, but I have a copy...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
I would imagine that it has to be much better than that. Hundreds of PPM is no better than the crystal that started this thread!
-Phil
A crystal has an evironment dependant bias, accumulating to arbitrary size if unchecked.
As power line networks are most trickily interleaved they need to be phase locked to prevent great demage, but they don't need anything above a certain degree of sync. A small phase shift is unavoidable. Think of the energy involved: It's Peta Watt Hours per Year per nation!
Edit:
In fact the small frequency deviation is used as a control value to adjust the energy production to the consumption.
Post Edited (deSilva) : 1/4/2008 7:22:46 PM GMT
@DeSilva- I found it suprising when I learned what effort they go to to keep the sync on the mains lines. It made sense once I thought about it.
Another time keeping method: I use a GPS receiver to determine the time, then rebroadcast it locally using cheap RF modules. All of the clocks in my house save one run on this timebase. Sweet, never needs setting, comes right back after a power outage (common where I live, the power is out as I type this, I'm on my generator), and is very accurate. I have used a WWVB solution in the past, but where I live I can only sync to WWVB at night.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
If you use UTC transmissions you never have to set the clock, and it will work for battery operated applications too. For this, the CMMR-6 solution seems simple ard reasonably priced. The thought in my mind is how much can be done in software to further minimize hardware.· [noparse][[/noparse]edit] I suppose this is more academic than practical for the average hobbyist[noparse][[/noparse]/edit]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Post Edited (Ken Peterson) : 1/4/2008 8:33:54 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=561-1014-ND
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?