PropTime: Unix style RTC using one cog
Rayman
Posts: 14,589
This code uses·one cog·to make a native RTC by keeping Unix time...
It offers a few different string formats of the current time.
It keeps track of time zone and daylight savings time.
I'm now testing this to see how accurate the clock on my demo board is...· If there is some fixed error, I believe I can compensate by adding or subracting a second or two whenever the time is read...
Post Edited (Rayman) : 9/3/2008 7:59:31 PM GMT
It offers a few different string formats of the current time.
It keeps track of time zone and daylight savings time.
I'm now testing this to see how accurate the clock on my demo board is...· If there is some fixed error, I believe I can compensate by adding or subracting a second or two whenever the time is read...
Post Edited (Rayman) : 9/3/2008 7:59:31 PM GMT
zip
20K
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.com
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again
BTW: I type as I'm thinking, so please don't take any offence at my writing style
now you just need to tie into NIST radio broadcasts and set the time automatically.
http://tf.nist.gov/stations/wwvb.htm
http://tf.nist.gov/general/pdf/1383.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
--Micah
Assuming this is a fixed offset due to crystal error, it should be easy to add in a drift correction...
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
pretty easy to cascade two counters to give a 64-bit counter running at the system clock
frequency.
For a 80MHz clock, 64 bits is some 7,000 years.
I think the clock could be easily integrated into any of the commonly used drivers (vga, mouse, keyboard, etc..)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
BTW, I tried the WWVB approach with my Prop-Radio, using the special ferrite that DigiKey sells for the purpose, and it didn't work. I'm at the edge of the WWVB coverage area, though. I also bought a WWVB receiver module from DigiKey. It didn't work either. :-( (It may just be from too much RFI in my shop.) I'd be interested in hearing if others closer to the transmitter in Colorado have a better experience
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
····16_777216 / 80_000_000 = 0.209...
Let that unit of time be your increment. (There's nothing magical about seconds, after all.) You can program a counter to output that exact frequency, which can then feed a second counter to count (in PHSx, w/ FRQx = 1) how many of them have transpired. Then, in the same cog, you can convert to seconds simply by reading the second counter's PHSx register, multiplying by $35AFE535 (treated as a hex fraction = 0.209...) and adding a constant (to get the time since the beginning of the Unix epoch). This will be more accurate than approximating seconds, since the correction is performed on the final result, not on each "tick".
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.
modulo scaling, and I figured the scaling would be pretty obvious/transparent.
As far as reading two counters reliably, that's easy; read hibits, read lobits, read hibits again. If the hibits have changed
(and this will very seldom happen), do the whole thing again.
Yes. The only problem there is that you don't have all 32 bits... So, you may have trouble in 2038 or so...
I have attached by version. I "borrowed" your conversion routines since mine didn't to month/year/timezone stuff, my original used 1 sec counter. I added Phil's .2097152 timer for 80Mhz but leave 1 sec timer if the prop speed is not 80Mhz. I haven't tried a long time period to see if there is any accuracy problems.
But, this is probably not a real issue for most applications...
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
In lieu of that, I'm inclined to modify a standard driver to do the counting...
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!