clock beat generator - Page 1
Forum section: electronics / beginners

author: Simon
author_rank: Unknown
timestamp: February 10, 2012, 10:36:26 pm
content: 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 ?

author: Unknown
author_rank: Unknown
timestamp: February 10, 2012, 11:15:28 pm
content: 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.

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 11, 2012, 01:22:13 am
content: 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!

author: ivan747
author_rank: Super Contributor
timestamp: February 11, 2012, 02:11:24 am
content: 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!

author: Rerouter
author_rank: Super Contributor
timestamp: February 11, 2012, 02:12:46 am
content: 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,

author: Zad
author_rank: Super Contributor
timestamp: February 11, 2012, 03:11:53 am
content: Dallas Semiconductor do some great real time clocks with temperature compensated integrated oscillators. They have a 1Hz output on a pin. e.g. The DS3231But (sigh) it requires a micro to talk to the chip over SPI or I2C to turn it on. Typical!

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 08:39:57 am
content: 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

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 11, 2012, 09:10:47 am
content: Quote from: Simon on February 11, 2012, 08:39:57 amdepends... dave has video regarding 10MHz rubidium oscillator.$30$50 in ebay

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 09:12:29 am
content: Quote from: Mechatrommer on February 11, 2012, 09:10:47 amlink ? or is it clearly listed on the episode list, mind you I'm after doing it for a fiver

author: jahonen
author_rank: Super Contributor
timestamp: February 11, 2012, 09:53:17 am
content: 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

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 09:59:56 am
content: bummer, it is nearly a tenner and needs getting in from the USA (+£15) at farnell, RS have it though

author: Bored@Work
author_rank: Super Contributor
timestamp: February 11, 2012, 10:30:21 am
content: 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.

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 11, 2012, 10:34:23 am
content: Quoteits clear in the list (main eevblog homepage). ep#235 & #236

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 11:28:41 am
content: Quote from: BoredAtWork on February 11, 2012, 10:30:21 amwell 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.

author: Jad.z
author_rank: Regular Contributor
timestamp: February 11, 2012, 11:56:30 am
content: Hi Simontake a look at those circuits. They are both simple, cheap and work fine, I've used both of them so i know they work finehttp://www.mcamafia.de/nixie/ncp_en/ncp.htmhttp://www.schematicwiringdiagram.com/t/schematicwiring/1-hz-timebaseAnd of course if the application is AC powered there is always the old method of dividing the 60/50Hz Down to 1Hz.

author: Bored@Work
author_rank: Super Contributor
timestamp: February 11, 2012, 12:08:08 pm
content: 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.

author: Rerouter
author_rank: Super Contributor
timestamp: February 11, 2012, 01:25:15 pm
content: 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,

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 01:34:08 pm
content: 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.

author: Rerouter
author_rank: Super Contributor
timestamp: February 11, 2012, 01:47:08 pm
content: 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,

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 01:47:44 pm
content: sounds good enough

author: deephaven
author_rank: Frequent Contributor
timestamp: February 11, 2012, 01:53:25 pm
content: Usehttp://uk.farnell.com/citizen-america/cfs206-32-768-kdzf-ub/crystal-watch-32-768khz-cyl/dp/1457084with your pic. Set the timer to interrupt every 32768 to give 1 second interrupt, then have a software counter counting 30 seconds.

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 03:44:55 pm
content: well I guess I should get the hang of driving a pic with a quartz to start

author: Simon
author_rank: Unknown
timestamp: February 11, 2012, 04:51:25 pm
content: I'm getting adventurous nowI 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

author: Zero999
author_rank: Super Contributor
timestamp: February 11, 2012, 06:58:24 pm
content: You could use an oscillator/counter/timer IC such as the CD4060, CD4541 or CD4536 and a divide by n counter CD4059 to get1/30Hz from a 32768Hz watch crystal.

author: Zad
author_rank: Super Contributor
timestamp: February 11, 2012, 07:41:00 pm
content: 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.

author: IanB
author_rank: Super Contributor
timestamp: February 11, 2012, 11:43:45 pm
content: Quote from: Rerouter on February 11, 2012, 01:25:15 pmThe mains frequency in the UK used to be required by law to keep perfect time. It has been very common for mains powered clocks to get their timing from the mains. I believe the power companies are trying to get that standard relaxed now, but as far as I know it remains a pretty good time reference for clocks.For Simon my first thought would have been to get the mains frequency and divide it down. It only needs discrete circuitry, not even an MCU.

author: ejeffrey
author_rank: Super Contributor
timestamp: February 11, 2012, 11:57:51 pm
content: Quote from: Rerouter on February 11, 2012, 01:25:15 pmIn the US and Europe mains frequency is controlled by atomc clocks. There can be short term fluctuations where short term could be weeks. Over the long term it is more stable than any crystal. If you plug your clock in and set it while the grid is a couple of minutes behind, it will gradually slew forward and then stay permanently a few minutes fast.

author: Rerouter
author_rank: Super Contributor
timestamp: February 12, 2012, 12:30:48 am
content: well atleast its offset here, all the grid connected solar inverters really mess with the grid in aus, not just voltage but frequency,

author: Simon
author_rank: Unknown
timestamp: February 12, 2012, 11:30:42 am
content: Quote from: IanB on February 11, 2012, 11:43:45 pmI was starting to consider that but now i also need a very small duty cycle although I guess a monostable can sort that (555).The clock coil does use 0.17 to 0.22 amps so I also need to look carefully at power consumption and the type of batteries I use.the original setup of this clock in a firestation was that there were a number of clocks in series connected to a battery and a switch that was worked by a pendulum to give the timing. Obviously the timing bit was the more expensive so it was easier to wire all clocks in series and used one central reference. The battery voltage is unknown and i guess was possibly changed according to how many clocks were in series so that is probably why there is a min/max spec for the coil on the back of it

author: SeanB
author_rank: Super Contributor
timestamp: February 12, 2012, 01:43:46 pm
content: Simple method is to take a clock ( Cheap single cell wall clock is perfect, and looks of the clock don't matter here) and rip apart the clock mechanism, to get the small PCB with the crystal, divider and clock driver out of it. Make a note of which pads go where. Power it from a 1.5V supply ( a resistor driving a red LED and a 100uF bypass capacitor) and use a single NPN transistor with a 10k base resistor and 10k collector resistor as a level shifter. Gives a simple source of pulses at 2 second intervals, now you just use 2 4017's to divide by 5 and 3 respectively, using the output from 2 ( or 1) from the second divider to trigger a 0.5 second monostable to drive the clock coil. Being a slave clock in a master slave system you probably will need a simple 24V DC supply to drive the coil, which does not need to be regulated, an 18VAC transformer and a bridge with 1000uF/50V capacitor will work fine . Use a 7812 to make 12V for the dividers, and drive the clock from the 12V rail, the LED will double as a power indicator.

author: siliconmix
author_rank: Frequent Contributor
timestamp: February 12, 2012, 05:07:13 pm
content: Quote from: Simon on February 12, 2012, 11:30:42 ammake a extra special job of it simon and drop one of these in there.use the pic to decode the signalshttp://www.ebay.co.uk/itm/MSF-Atomic-Clock-Receiver-Module-Rugby-Atomic-Clock-/230740011322?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item35b92d293a#ht_2314wt_932

author: Simon
author_rank: Unknown
timestamp: February 12, 2012, 05:33:20 pm
content: no sure I need to go that far lol

author: IanB
author_rank: Super Contributor
timestamp: February 12, 2012, 05:58:45 pm
content: Quote from: Simon on February 12, 2012, 11:30:42 amThat was a very common thing once upon a time--I think it was called a master clock system. My school had such a system and probably every other school did too. It permitted every clock in every building to show exactly the same time, so all the lessons could keep to the same timetable and start and end exactly on cue. You would find clock systems like that in offices, factories, stations, everywhere. I'm not sure its even obsolete today because even quartz clocks can't keep time that accurately. And imagine if you had to go around and manually adjust dozens of clocks to adjust them, rather than just adjusting the central master clock?

author: siliconmix
author_rank: Frequent Contributor
timestamp: February 12, 2012, 06:00:51 pm
content: the rugby signal is still used it's on digital watches and weather clocks

author: Simon
author_rank: Unknown
timestamp: February 12, 2012, 06:11:14 pm
content: Quote from: IanB on February 12, 2012, 05:58:45 pmSadly this is a single clock hence he needs the timing generator.