-
clock beat generator
Posted by
Simon
on 10 Feb, 2012 22:36
-
Right, I have been volunteered for a task. My dads frind has a clock that needs a circuit to generate a 1s beat for the coil that pushes the second hand round. So I'm thinking that being a clock something like a 555 is no good as the RC components will change with temperatures. I'm thinking a PIC 12F615 as it can run off internal clock and I can easily write some simple code to generate a 1 Hz pulse and control the duty accurately.
Is the internal clock accurate enough for this or should i use a quartz ?
-
#1 Reply
Posted by
alm
on 10 Feb, 2012 23:15
-
I don't know the specs of the internal oscillator by heart, but I believe it's a standard RC oscillator with a stability of 1% or so, worse over temp. This would mean that it could be about 15 minutes off per 24 hours, totally unacceptable for most applications. A 32.768 kHz crystal would be good for this application and should work with the real time clock peripheral in PICs (not sure if the PIC12 supports this).
Even a lousy computer grade (=absolute crap in crystal terms) crystal would be about two orders of magnitude better than the internal RC oscillator. A good watch has an accuracy that is measured in seconds per month. Timekeeping is one of those rare applications where absolute accuracy and tight tolerances are actually important, since it's annoying to set a clock every day, and the error adds up over long time spans.
-
-
i will not give the mcu internal osc (free feature) a first thought if its about accuracy of timekeeping. get the best oscillator you can afford. i have avr running with internal osc like 4MHz at one time and 4.9MHz the other time, not exact value but the point is.... crap!
-
#3 Reply
Posted by
ivan747
on 11 Feb, 2012 02:11
-
Run a PIC12F629 from a 32.768kHz crystal, enable the timer 1 overflow interrupt. This way you will have an interrupt every 8 seconds by default. To change it to a second by write the value 57344 to the timer register pair minus the amount of instruction cycles taken to perform this operation. I recommend you pause the timer during the operation.
An easier way is to make a loop and wait for the second to elapse (8192 instructions must be executed). The amount of non-operational instructions to run is determined by the number of instructions per second (8192) minus the amount of functional instructions, like changing the output to high or low. This will make the code less flexible. You can use a PIC10F200 with this method, but you will have to make some loops instead of coding 8000+ NOP instructions.
When you are done check against a frequency counter just to be sure you are not executing and extra instruction.
I haven't tested any of these, but I would like to hear the results, specially if you use a PIC10F200, assembly language, and you keep the PCB under 2cm x 2cm!
-
#4 Reply
Posted by
Rerouter
on 11 Feb, 2012 02:12
-
a way that is commonly used in some of the modern-ish coil based clocks where a crystal is involved is a 1.024, 2.048 or 4.096Khz crystal and a matching divide by counter chip, e.g. a CD4059,
-
#5 Reply
Posted by
Zad
on 11 Feb, 2012 03:11
-
Dallas Semiconductor do some great real time clocks with temperature compensated integrated oscillators. They have a 1Hz output on a pin. e.g. The DS3231
But (sigh) it requires a micro to talk to the chip over SPI or I2C to turn it on. Typical!
-
#6 Reply
Posted by
Simon
on 11 Feb, 2012 08:39
-
ok so I need a crystal, so a standard 20 MHz crystal is no good either ? I'm definitely using a 12F615 as I'm familiar with it. I'm afraid I'll have to write it with basic as that is al know. My plan was for a looped program and just have "x" time high, "y" time low and fine tune it
-
-
ok so I need a crystal, so a standard 20 MHz crystal is no good either ?
depends... dave has video regarding 10MHz rubidium oscillator.
$30$50 in ebay
-
#8 Reply
Posted by
Simon
on 11 Feb, 2012 09:12
-
ok so I need a crystal, so a standard 20 MHz crystal is no good either ?
depends... dave has video regarding 10MHz rubidium oscillator. $30 in ebay
link ? or is it clearly listed on the episode list, mind you I'm after doing it for a fiver
-
#9 Reply
Posted by
jahonen
on 11 Feb, 2012 09:53
-
Maxim has 32.768 kHz TCXO available which might be suitable here:
http://www.maxim-ic.com/datasheet/index.mvp/id/2940Obviously not as good as rubidium frequency standard but I guess that one might get away with ±2 PPM accuracy (about ±60 seconds/year).
Regards,
Janne
-
#10 Reply
Posted by
Simon
on 11 Feb, 2012 09:59
-
bummer, it is nearly a tenner and needs getting in from the USA (+£15) at farnell, RS have it though
-
#11 Reply
Posted by
Bored@Work
on 11 Feb, 2012 10:30
-
A crystal is a start. But without trimming it, or compensating the frequency offset in software, you will find its accuracy being lacking, compared to what you are used from your wrist watch (while the precision is sort of ok). +/- 10 ppm are still almost +/- 1 second a day, 5 minutes/year.
Factory adjusted RTC ICs, like some of those from Maxim/Dallas are indeed a more accurate, worry free, solution, especially for a one-off. They are more expensive, but can give you 2 minutes/year accuracy.
A rather cheap solution are radio clock receivers. You sometimes get receiver modules very cheap. I think I payed 6 Euro for my last one, but that was a DFC77. I also happen to find separate, salvageable receiver modules in cheap battery operated travel alarm radio clocks.
Decoding the signal from such a module in software is usually simple and it is easy to adjust an internal MCU timer/counter with the result of the decoding. I would recommend to still have a running, crystal clocked timer/counter in the MCU to cope with signal loss. As long as you manage to get a radio signal once a day you can keep the timer/counter very accurate. Commercial consumer radio clocks do a similar thing. To save power they just turn on the receiver a few times a day to adjust their crystal clock.
-
-
link ? or is it clearly listed on the episode list, mind you I'm after doing it for a fiver
its clear in the list (main eevblog homepage). ep#235 & #236
-
#13 Reply
Posted by
Simon
on 11 Feb, 2012 11:28
-
A crystal is a start. But without trimming it, or compensating the frequency offset in software, you will find its accuracy being lacking, compared to what you are used from your wrist watch (while the precision is sort of ok). +/- 10 ppm are still almost +/- 1 second a day, 5 minutes/year.
Factory adjusted RTC ICs, like some of those from Maxim/Dallas are indeed a more accurate, worry free, solution, especially for a one-off. They are more expensive, but can give you 2 minutes/year accuracy.
A rather cheap solution are radio clock receivers. You sometimes get receiver modules very cheap. I think I payed 6 Euro for my last one, but that was a DFC77. I also happen to find separate, salvageable receiver modules in cheap battery operated travel alarm radio clocks.
Decoding the signal from such a module in software is usually simple and it is easy to adjust an internal MCU timer/counter with the result of the decoding. I would recommend to still have a running, crystal clocked timer/counter in the MCU to cope with signal loss. As long as you manage to get a radio signal once a day you can keep the timer/counter very accurate. Commercial consumer radio clocks do a similar thing. To save power they just turn on the receiver a few times a day to adjust their crystal clock.
well if we are talking about worrying about the difference between 2 minutes per year and 5 minutes per year I'll take the cheaper option. The other possibility is that as it is a one off i get a cheap clock mechanism and hack that with an output transistor to interface it to the 12V this old clock runs off.
But are you saying that a micro with a generic quartz will be like 5 minutes per year accurate ? that's fine also.
-
#14 Reply
Posted by
Jad.z
on 11 Feb, 2012 11:56
-
-
#15 Reply
Posted by
Bored@Work
on 11 Feb, 2012 12:08
-
If you can trim your oscillator to +/-10 ppm you get five minutes. A watch crystal is about +/- 20 ppm, a normal crystal +/- 30 or 40 ppm. So some trimming / compensation in software required to get to 5 minutes/year. And don't forget that the frequency is also temperature-dependent.
-
#16 Reply
Posted by
Rerouter
on 11 Feb, 2012 13:25
-
dividing from mains frequency is just horrible, its a 0.2% tolerance,
forgot the values, a 32.786khz signal, a CD4040 can divide by 14 bits, or 16384 leaving only 1 bit of division left able to be done by a second, or a generic flip flop, with a generic crystal with a yearly drift of a 1-3ppm can beat 1.5 minutes per year, once tuned, (variable capacitance in series or parrellel) (untuned you would be looking at about 10 minutes)
this is the simplest and quickest to implement method i know of, sorry about the odd values before,
-
#17 Reply
Posted by
Simon
on 11 Feb, 2012 13:34
-
ok well things have changed slightly. I've just been to see the guy and he has shown me the clock. It needs 30s pulses. There is no second hand and the minute hand does steps of 30 seconds. It is an old fire station clock. so I think I need something like a 0.5s pulse every 30s, perhaps a micro controller will be the best thing ?
So will a basic crystal be fairy accurate ? like a few minutes to the year.
-
#18 Reply
Posted by
Rerouter
on 11 Feb, 2012 13:47
-
if tuned, a cheap 32.768Khz crystal with a yearly drift of 3ppm ends up being about a maximum of 1.5 minutes off per year, without tuning, at 20ppm initial offset is about 10 minutes to a year,
-
#19 Reply
Posted by
Simon
on 11 Feb, 2012 13:47
-
sounds good enough
-
#20 Reply
Posted by
deephaven
on 11 Feb, 2012 13:53
-
-
#21 Reply
Posted by
Simon
on 11 Feb, 2012 15:44
-
well I guess I should get the hang of driving a pic with a quartz to start
-
#22 Reply
Posted by
Simon
on 11 Feb, 2012 16:51
-
I'm getting adventurous now
I should put in a fast forward button so that the time can be set, and I could put in two trim buttons to increase and decrease the speed slightly and a reset button, that way if I'm that far out it can be trimmed and the time set
-
#23 Reply
Posted by
Zero999
on 11 Feb, 2012 18:58
-
You could use an oscillator/counter/timer IC such as the CD4060, CD4541 or CD4536 and a divide by n counter CD4059 to get 1/30Hz from a 32768Hz watch crystal.
-
#24 Reply
Posted by
Zad
on 11 Feb, 2012 19:41
-
UK mains might not be very accurate short-term, but over any given 24 hour period it is very accurate indeed. If you aren't limited to battery power and you want the ultimate accuracy, you can get cheap GPS modules off Ebay that give a 1pps output. Obviously having a 2ppm output requirement now messes that up. Sigh.