Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Second Generating

Second Generating

2006-09-25 by musabfakhri

Hi guys,

I hope every thing is going OK.
I`ve question hoping somebody could provide me what I have to do.
How can I generate one second accurately to be applied Digital 
Clock ? by the way, I`ve tried by Timer/Counter0 , T/C Prescaler , 
Timer0 ovf0 (Int. Calling) but I didn`t get a real second .



Plz help as soon as possible .

Re: [AVR-Chat] Second Generating

2006-09-25 by Ralph Hilton

On Mon, 25 Sep 2006 10:08:28 -0000 you wrote:

>Hi guys,
>
>I hope every thing is going OK.
>I`ve question hoping somebody could provide me what I have to do.
>How can I generate one second accurately to be applied Digital 
>Clock ? by the way, I`ve tried by Timer/Counter0 , T/C Prescaler , 
>Timer0 ovf0 (Int. Calling) but I didn`t get a real second .
>
>
>
>Plz help as soon as possible .

If you are using a crystal then there should be no problem getting a second by
dividing down with a timer. If you are using the internal RC then you can't get an
accurate second due to its lack of stability.
--
Ralph Hilton
http://www.ralphhilton.org
C-Meter: http://www.cmeter.org
FZAOINT http://www.fzaoint.net

Re: Second Generating

2006-09-25 by Patrick Timlin

There are a number of ways to generate one second intervals. 

One way is to use a 32.768kHz crystal as your clock source. These are 
often used for this because 32768 is 2^15 power and so your clock is 
easily divided down to give one second intervals. Or put another way, 
you can use run this crystal into your AVR timer pin. If you use an 8-
bit timer, then each time the timer rolls over (256 counts) is 
1/128th of a second. Count 128 of those roll overs and you have a 
second. If you use a 16-bit counter, each roll over of the counter is 
exactly 2 seconds so you want set up the counter with a preloaded 
value of half the full count so you can get a one-second interval.

Another way to do it is to use the utility company's clock. Not sure 
how the rest of the world is, but in the USA the 60Hz frequency is 
pretty accurate, certainly over a period of time. So one way to 
generate a clock is to use a step down isolation transformer and step 
down your 120V/60Hz signal to something like 5V/60Hz or whatever low 
voltage you like. You can then use basic circuitry (optocouplers, 
bridges, etc.) and generate "zero crossing" pulses from the line 
frequency. For the USA, those zero crossing pulses will be 120 pulses 
per second. With Europe and other places that use 50Hz your zero 
crossing will be 100 pulses per second. Count the pulses and every 
120 (or 100) will be a second. As I said, you might get some 
variation from second to second, but over any period of time, you can 
get an accurate clock. By period of time I mean if you are designing 
a desk clock this will work great or if you are making a timer for 
cooking. If you need to be accurate down to the millisecond at all 
times, this method might give a tiny bit of variation from one 
millisecond to the next.

Also, as a final note, some of the AVRs with internal oscillators can 
be calibrated to get a much more accurate internal clock. Atmel has a 
tech note on this, so if you want to use your internal oscillator, 
you can get a much better clock source by going through the 
calibration procedure. See the Atmel document "AVR054" for further 
details. Apparently this method can get you to within +/- 1% of the 
frequency stated on the data sheet rather than the factory 
specification of +/- 3% and within 2% for those devices where the 
internal RC oscillator is only +/- 10%.

Patrick

Re: [AVR-Chat] Second Generating

2006-09-25 by Zack Widup

On Mon, 25 Sep 2006, Ralph Hilton wrote:

> On Mon, 25 Sep 2006 10:08:28 -0000 you wrote:
> 
> >Hi guys,
> >
> >I hope every thing is going OK.
> >I`ve question hoping somebody could provide me what I have to do.
> >How can I generate one second accurately to be applied Digital 
> >Clock ? by the way, I`ve tried by Timer/Counter0 , T/C Prescaler , 
> >Timer0 ovf0 (Int. Calling) but I didn`t get a real second .
> >
> >
> >
> >Plz help as soon as possible .
> 
> If you are using a crystal then there should be no problem getting a second by
> dividing down with a timer. If you are using the internal RC then you can't get an
> accurate second due to its lack of stability.
> --
> Ralph Hilton

You can also use an external crystal oscillator with a trimmer cap for 
frequency adjustment.  I've used a 10 MHz oscillator which I zero-beat 
with WWV here. If you have a known frequency standard like a rubidium 
standard handy, you can hook a scope up to the two outputs and adjust by 
Lissajous figures.

You can find 10 MHz OCXO's on eBay for $20 to $80.  I don't know how 
desperately you need the accuracy; that may be overkill.

The simpler solution would be to use the 1 pps output of a GPS engine, or 
use the 10 kHz output and divide it down.

Zack

Re: [AVR-Chat] Second Generating

2006-09-25 by Ralph Hilton

On Mon, 25 Sep 2006 07:56:11 -0500 (CDT) you wrote:

>On Mon, 25 Sep 2006, Ralph Hilton wrote:
>
>> On Mon, 25 Sep 2006 10:08:28 -0000 you wrote:
>> 
>> >Hi guys,
>> >
>> >I hope every thing is going OK.
>> >I`ve question hoping somebody could provide me what I have to do.
>> >How can I generate one second accurately to be applied Digital 
>> >Clock ? by the way, I`ve tried by Timer/Counter0 , T/C Prescaler , 
>> >Timer0 ovf0 (Int. Calling) but I didn`t get a real second .
>> >
>> >
>> >
>> >Plz help as soon as possible .
>> 
>> If you are using a crystal then there should be no problem getting a second by
>> dividing down with a timer. If you are using the internal RC then you can't get an
>> accurate second due to its lack of stability.
>> --
>> Ralph Hilton
>
>You can also use an external crystal oscillator with a trimmer cap for 
>frequency adjustment.  I've used a 10 MHz oscillator which I zero-beat 
>with WWV here. If you have a known frequency standard like a rubidium 
>standard handy, you can hook a scope up to the two outputs and adjust by 
>Lissajous figures.
>
>You can find 10 MHz OCXO's on eBay for $20 to $80.  I don't know how 
>desperately you need the accuracy; that may be overkill.

For a cheap TCXO Maxim make an inexpensive DS32KHz. They sent me 2 free samples on
request.
--
Ralph Hilton
http://www.ralphhilton.org
C-Meter: http://www.cmeter.org
FZAOINT http://www.fzaoint.net

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.