Author Topic: clock beat generator  (Read 13660 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
clock beat generator
« on: February 10, 2012, 10:36:26 pm »
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 ?
 

alm

  • Guest
Re: clock beat generator
« Reply #1 on: February 10, 2012, 11:15:28 pm »
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.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11537
  • Country: my
  • reassessing directives...
Re: clock beat generator
« Reply #2 on: February 11, 2012, 01:22:13 am »
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!
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2045
  • Country: us
Re: clock beat generator
« Reply #3 on: February 11, 2012, 02:11:24 am »
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!
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: clock beat generator
« Reply #4 on: February 11, 2012, 02:12:46 am »
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,

 

Offline Zad

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: gb
    • Digital Wizardry, Analogue Alchemy, Software Sorcery
Re: clock beat generator
« Reply #5 on: February 11, 2012, 03:11:53 am »
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!

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #6 on: February 11, 2012, 08:39:57 am »
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
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11537
  • Country: my
  • reassessing directives...
Re: clock beat generator
« Reply #7 on: February 11, 2012, 09:10:47 am »
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 ;)
« Last Edit: February 11, 2012, 09:14:43 am by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #8 on: February 11, 2012, 09:12:29 am »
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
 

Offline jahonen

  • Super Contributor
  • ***
  • Posts: 1052
  • Country: fi
Re: clock beat generator
« Reply #9 on: February 11, 2012, 09:53:17 am »
Maxim has 32.768 kHz TCXO available which might be suitable here:

http://www.maxim-ic.com/datasheet/index.mvp/id/2940

Obviously 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
« Last Edit: February 11, 2012, 09:55:06 am by jahonen »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #10 on: February 11, 2012, 09:59:56 am »
bummer, it is nearly a tenner and needs getting in from the USA (+£15) at farnell, RS have it though  :)
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: clock beat generator
« Reply #11 on: February 11, 2012, 10:30:21 am »
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.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11537
  • Country: my
  • reassessing directives...
Re: clock beat generator
« Reply #12 on: February 11, 2012, 10:34:23 am »
Quote
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
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #13 on: February 11, 2012, 11:28:41 am »
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.
 

Offline Jad.z

  • Regular Contributor
  • *
  • Posts: 83
  • Country: 00
Re: clock beat generator
« Reply #14 on: February 11, 2012, 11:56:30 am »
Hi Simon

take a look at those circuits. They are both simple, cheap and work fine, I've used both of them so i know they work fine  :)

http://www.mcamafia.de/nixie/ncp_en/ncp.htm

http://www.schematicwiringdiagram.com/t/schematicwiring/1-hz-timebase


And of course if the application is AC powered there is always the old method of dividing the 60/50Hz Down to 1Hz.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: clock beat generator
« Reply #15 on: February 11, 2012, 12:08:08 pm »
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.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: clock beat generator
« Reply #16 on: February 11, 2012, 01:25:15 pm »
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,
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #17 on: February 11, 2012, 01:34:08 pm »
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.
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: clock beat generator
« Reply #18 on: February 11, 2012, 01:47:08 pm »
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,
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #19 on: February 11, 2012, 01:47:44 pm »
sounds good enough
 

Offline deephaven

  • Frequent Contributor
  • **
  • Posts: 796
  • Country: gb
  • Civilization is just one big bootstrap
    • Deephaven Ltd
Re: clock beat generator
« Reply #20 on: February 11, 2012, 01:53:25 pm »
Use http://uk.farnell.com/citizen-america/cfs206-32-768-kdzf-ub/crystal-watch-32-768khz-cyl/dp/1457084 with your pic. Set the timer to interrupt every 32768 to give 1 second interrupt, then have a software counter counting 30 seconds.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #21 on: February 11, 2012, 03:44:55 pm »
well I guess I should get the hang of driving a pic with a quartz to start
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: clock beat generator
« Reply #22 on: February 11, 2012, 04:51:25 pm »
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
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19345
  • Country: gb
  • 0999
Re: clock beat generator
« Reply #23 on: February 11, 2012, 06:58:24 pm »
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.
 

Offline Zad

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: gb
    • Digital Wizardry, Analogue Alchemy, Software Sorcery
Re: clock beat generator
« Reply #24 on: February 11, 2012, 07:41:00 pm »
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.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf