Searching \ for '[PIC] making a quartz clock' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=clock
Search entire site for: 'making a quartz clock'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] making a quartz clock'
2007\02\23@161630 by picnoob

flavicon
face

ok, i am doing a new project, u guessed it...a clock.

now, i have read some guides about this on the www, but the give different
info. Is it true that the frequency of the oscillator used is divided by 4,
and instructions are executed at this new frequency? im using a pic16f84a.

also, i wanted to know, what is different between 16f and 16c etc....?

ty.
--
View this message in context: www.nabble.com/making-a-quartz-clock-tf3281293.html#a9126956
Sent from the PIC - [PIC] mailing list archive at Nabble.com.

2007\02\23@163117 by Harold Hallikainen

face
flavicon
face

>
> ok, i am doing a new project, u guessed it...a clock.
>
> now, i have read some guides about this on the www, but the give different
> info. Is it true that the frequency of the oscillator used is divided by
> 4,
> and instructions are executed at this new frequency? im using a pic16f84a.
>
> also, i wanted to know, what is different between 16f and 16c etc....?
>
> ty.

Yes, Fosc is divided by 4. So, if you have a 4MHz oscillator, the PIC runs
at 1,000 instructions per second (some instructions take twice as long,
like those that modify PC).

16F uses flash memory. It can be erased electrically. 16C uses eprom. If
in a ceramic case, it can be erased with UV. If in a plastic case, it
cannot be erased and is considered "one time programmable."

Harold


--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2007\02\23@163607 by Maarten Hofman

face picon face
Redwood Shores, 23 februari 2007.

Clock sounds nice. First the answers to your questions: on the 16F84A the
speed of each instruction is indeed 1/4 of the clock speed. In 18F this
isn't always the case, but most 12F and 16F are like that. 16F means it uses
some form of flash memory, allowing you to rewrite the program a number of
times (100-1000x for some types, 100000x for other types). 16C usually means
that the part can be written only once (it is OTP - One Time Programming)
although there are exceptions.

Now for additional comments:
1) Don't use the 16F84A. I personally like the 16F628A, but you could
immediately switch to the 16F648A, or the very universal 16F88 if you want
something similar. If you don't care about similar, you might want to focus
on the 18F and skip the 16F alltogether. Personally I also like using the
16F688, which is a very neat 14-pin device.
2) A clock based on a 4 MHz resonator won't work very well. A 4 MHz crystal
might be better, but is still quite temperature sensitive and consumes a lot
of power. I believe the consensus is that a 32768 Hz crystal is ideal.
3) There still is a power issue, however. I personally really like
interfacing with a DS1302 or DS1307 and have that part handle the time
keeping. If you add a supercap it can keep the time for very long periods.
The PIC can then turn itself off while the DS130x keeps the time and date
(and possibly 128 bytes of additional information).

Greetings,
Maarten Hofman.

2007\02\23@165018 by Herbert Graf

flavicon
face
On Fri, 2007-02-23 at 13:16 -0800, picnoob wrote:
> ok, i am doing a new project, u guessed it...a clock.
>
> now, i have read some guides about this on the www, but the give different
> info. Is it true that the frequency of the oscillator used is divided by 4,
> and instructions are executed at this new frequency? im using a pic16f84a.

Yes, the instruction clock is /4 the oscillator clock.

Normally ever clock tick of the instruction clock equals one instruction
being run, however, ANY instruction that changes the PC (program
counter) will result in that instruction taking TWO instruction clocks
to run.

Examples are the GOTO or RET op codes. Also, BSFSZ and BSFSC will result
in 2 instruction clocks being needed if the "skip" is done.

> also, i wanted to know, what is different between 16f and 16c etc....?

If you are referring to the 16f84 and 16c84 the differences are very
minimal. Since you mention the 16f84a you've got the "newest" f84 and
you don't have to worry about what the differences were.

That said, many here will recommend switching to a newer PIC, the 84 is
very old and things can be done much easier with the newer parts.

TTYL

2007\02\23@165144 by Herbert Graf

flavicon
face
On Fri, 2007-02-23 at 13:31 -0800, Harold Hallikainen wrote:
> >
> > ok, i am doing a new project, u guessed it...a clock.
> >
> > now, i have read some guides about this on the www, but the give different
> > info. Is it true that the frequency of the oscillator used is divided by
> > 4,
> > and instructions are executed at this new frequency? im using a pic16f84a.
> >
> > also, i wanted to know, what is different between 16f and 16c etc....?
> >
> > ty.
>
> Yes, Fosc is divided by 4. So, if you have a 4MHz oscillator, the PIC runs
> at 1,000 instructions per second (some instructions take twice as long,
> like those that modify PC).

Oops, I think you mean 1,000,000 instructions per second.

> 16F uses flash memory. It can be erased electrically. 16C uses eprom. If
> in a ceramic case, it can be erased with UV. If in a plastic case, it
> cannot be erased and is considered "one time programmable."

True, except for the 16c84, which was EEPROM based (basically same
features as the 16f84).

TTYL


2007\02\23@171950 by Jinx

face picon face
> ok, i am doing a new project, u guessed it...a clock.

'noob, good h/w - s/w project to start with. Endless possibilities
for mechanical and functional imagination

> and instructions are executed at this new frequency? im using a
> pic16f84a

The f84 was the first PIC I used and all of my clocks built with it
at that time (1996 ? and similar Motorolas before that) are still out
there, working away as good as new. The f84 is fine to use if you
have one, but for future projects there are better and cheaper
alternatives (628, 88, 688, 18F, 12F etc). For a simple clock or
timer, you can get by with just TMR0

I'd suggest you not use a 4MHz time-base, but 32768Hz. This
makes counting and rollover IRQs from TMR0 very easy. A crystal
will drift though and is not a good long-term solution. Fine for power
outages though. If you see this drift, and you will, make the reset
feature set a particular time, eg 6pm

The best you can expect is that the crystal works at an average of
32768Hz. But 1Hz high will be (32769/32768) * 86400 = 86402.6
or 2.6 seconds per day fast

If you want this to keep good time, use an AC wall-wart so that you
can count mains cycles. A loaded unregulated DC one may also
have enough ripple to use for this, or you could get into the wall-
wart and remove the filter cap and bridge. These can be used in your
circuit for rectification, but you'll have the AC accessible to the PIC
before that

2007\02\23@172921 by William Chops Westfield

face picon face

On Feb 23, 2007, at 1:50 PM, Herbert Graf wrote:

>> i wanted to know, what is different between 16f and 16c etc....?
>
> If you are referring to the 16f84 and 16c84 the differences
> are very minimal.

> That said, many here will recommend switching to a newer PIC...

Note that the 16F84 vs 16C84 is the ONLY instance where there are
only "minimal" differences between 16F and 16C; the 16C84 was the
very first pic with "electrically erasable" program memory, and
microchip hadn't yet settled on the "F" designator for that...

For ALL other "C" chips, you're stuck with one-time-programmable,
or at best "expensive but UV erasable" chips.

Summarizing:

A microcontroller beginner should choose a flash-based electrically
erasable and reprogrammable chip.

Among Microchip PIC chips, electrically erasable chips are designated
by including an "F" in the part name.

Except for the 16C84, which is so old that it should be avoided anyway.

BillW

2007\02\23@173627 by Byron A Jeff

face picon face
On Fri, Feb 23, 2007 at 01:16:22PM -0800, picnoob wrote:
>
> ok, i am doing a new project, u guessed it...a clock.

Been there. Done that. Got the tee shirt.

> now, i have read some guides about this on the www, but the give
> different
> info. Is it true that the frequency of the oscillator used is
> divided by 4,
> and instructions are executed at this new frequency?

That's true for PICs.

>im using a pic16f84a.

What exactly is this clock supposed to do? There's probably better
choices than the 16F84 if you want to perform this activity. One
reason is that other PICs have multiple timers. In particular 16F
PICS with timer 1 can be driven from an external oscillator independant
of the PIC oscillator

> also, i wanted to know, what is different between 16f and 16c etc....?

Marketing. Nothing really worth talking about.

I'd advise you take a read on newer PICs if PIC are where you are
planning to work. I've argued over the years that the 16F84 limitations
makes getting tasks done difficult.

Finally just so you won't go away empty handed you can take a look
at my code for my sunrise/sunset outdoor light controller, which is
basically a calendar/clock that turns outdoor lights on about dusk
and off around dawn. Code is here:

http://www.finitesite.com/d3jsys/clock.asm
It's written for a 16F877 and drives timer 1 with a 32 khZ watch
crystal to generate a 2 second counter.

Accuracy is a bit problematic. Crystals will vary in oscillation
rates based on temperature. I always planned to update the project
to use the 60 Hz power line signal, but just never got back to it.

Hope this helps,

BAJ

2007\02\23@174342 by Byron A Jeff

face picon face
On Fri, Feb 23, 2007 at 05:36:23PM -0500, Byron A Jeff wrote:
> > also, i wanted to know, what is different between 16f and 16c etc....?
>
> Marketing. Nothing really worth talking about.

Actually let me amend this. I read the question as the difference
between the 16C84 and the 16F84. That's marketing.

The 16C series was Microchip's initial PIC offering. They used
EPROM for program memory. They came in two packages: plastic one
time programmable (OTP) and ceramic EPROM style cases with the
quartz window that allowed for erasure.

The point is somewhat moot because virtually all of Microchip's
current PIC offerings are flash based. But from what I understand
you can still buy 16C parts if you need them. As a hobbyist, you
probably won't ever need 16C parts.

> I'd advise you take a read on newer PICs if PIC are where you are
> planning to work. I've argued over the years that the 16F84
> limitations
> makes getting tasks done difficult.

Worth reiterating. For a tutorial on newer 16F parts take a look
a Nigel Goodwin's PIC tutorial at http://www.winpicprog.com. That
tutorial uses 16F628 and 16F876/877 parts with has much better
peripheral packages than the anemic 16F84.

BAJ

2007\02\23@174817 by Harold Hallikainen

face
flavicon
face
Thanks for catching my typo! I wasn't aware of the 16c84. Have never used
it. Most of my stuff is now 18F or 24H unless it's a very simple cost
sensitive device, when I go back to 16F.

Thanks!

Harold


{Quote hidden}

> -

2007\02\23@181635 by Jinx

face picon face
I wrote -

> I'd suggest you not use a 4MHz time-base, but 32768Hz. This
> makes counting and rollover IRQs from TMR0 very easy

The other advantage is power consumption. The slower the PIC
runs, the less it uses

eg ~ 1000 - 2000uA 4MHz 5.5V (XT mode) versus 35uA 32kHz
3V (LP mode), a substantial saving

2007\02\23@183524 by Bob Axtell

face picon face
Byron A Jeff wrote:
> On Fri, Feb 23, 2007 at 01:16:22PM -0800, picnoob wrote:
>  
>> ok, i am doing a new project, u guessed it...a clock.
>>    
>
> Been there. Done that. Got the tee shirt.
>  
Get the DVD, too?
{Quote hidden}

If you want a clock that is ALWAYS accurate to a second or two, you
might consider
using WWVB (if you are in the US/CA at 60Khz), DCF77 (Germany at
77.5Khz), HGB (switzerland
at 75Khz), MSF60 (UK at 60Khz), or two Japanese transmitters, one at
40Khz and the second at
60Khz. They provide worldwide coverage. Tests indicate that WWVB reaches
well into South America,
for exanple, and Japanese signals reach Australia easily.

C-MAX sells modules that will extract the time information, or even
smaller modules that act as receivers
only, and you can extract the time code.

I am designing a solar tracking system that uses accurate time and a
known position to determine where
the sun is at all times. The tracking math has all been solved, but an
accurate time source was undetermined. I have
now concluded that the above time service is cheaper and more reliable
than GPS, as GPS requires an
expensive antenna & GPS receiver, at about $90 USD, while this module
and antenna in a plastic box
costs less than $10 USD. For reliability, I only use WWVB once a day in
the middle of the night to SET
the time, and a separate timekeeping chip maintains it during the day.

So, funnel this time data into your clock once a day to re-calibrate the
clock.

--Bob

2007\02\24@004343 by Rikard Bosnjakovic

picon face
On 2/23/07, Harold Hallikainen <spam_OUTharoldTakeThisOuTspamhallikainen.org> wrote:

> Yes, Fosc is divided by 4. So, if you have a 4MHz oscillator, the PIC runs
> at 1,000 instructions per second (some instructions take twice as long,
> like those that modify PC).

I read about this (and some other crystal-based text) in my PIC-book,
but what I cannot understand is why a 32768Hz-crystal is magical
enough to use for clock-applications. Dividing 32768 with 4 gives me
8192, and that's a value that I certainly don't connect with anything
that's got to do with timing.

On the other hand, I haven't yet got a good grip of why to use
crystals. To time the controller, sure, but...how?  I have read that
an xtal oscillates due to some quartz-magic in it, but that's all. No
clue of how it works.

This is probably a good incitament to start this day with a visit to Wikipedia.


--
- Rikard.

2007\02\24@015503 by Richard Prosser

picon face
Rikard,
Yes, but if you divide 8192 by 2^11 you get 1. i.e 1Hz and that is
useful. And dividing by 2,  11 (or 15)  times is easy.

32.767kHz is commonly used I think because a small crystal cut in the
right way can be very stable and requires low drive power and so is
useful for all manner of clocks, watches and computer RTCs.

RP

On 24/02/07, Rikard Bosnjakovic <.....rikard.bosnjakovicKILLspamspam@spam@gmail.com> wrote:
{Quote hidden}

> -

2007\02\24@020531 by scott larson

picon face
On 2/23/07, Rikard Bosnjakovic <.....rikard.bosnjakovicKILLspamspam.....gmail.com> wrote:

> I read about this (and some other crystal-based text) in my PIC-book,
> but what I cannot understand is why a 32768Hz-crystal is magical
> enough to use for clock-applications. Dividing 32768 with 4 gives me
> 8192, and that's a value that I certainly don't connect with anything
> that's got to do with timing.

2^16 = 65536.
2^15 = 32768.

Timer1 in PICs is a 16 bit timer which can be driven by an external
source, in this case a 32768 Hz crystal. Preloading the timer1 high
register with 0x80 (set the 7th bit), and running the timer will
overflow after 32768 cycles. Configure an interrupt on overflow and
you get an interrupt every 1 second.

-Scott

2007\02\24@034630 by Jinx

face picon face
> but what I cannot understand is why a 32768Hz-crystal is magical

As others have said, it's divisible by binary powers, as can be seen
if you look at it in hexadecimal

32768 = $8000

This is good for a clock as a large number of cycles is a whole or
easy fraction of a second when used to clock one of the PIC's timer/
counters. On the F84 you have TMR0. When assigned to count
instruction cycles, it will count 256 (00 to FF) and then rollover to
00, setting T0IF, which can be used as an interrupt flag. A 32768
crystal will cause this rollover 32768/256 = 128 times per second.
If you set the pre-scaler to 1:128, then it now takes 32768 cycles
to set T0IF, or IOW a 1Hz interrupt

Note that the $8000 above can be broken down like this -

The 00 is the low byte, and in the above example is what is counted
by the TMR0 register. The 80 (= d128) is the high byte, and that
is what is counted by the pre-scaler

Another hex one is 9.8304MHz = $960000, which is good for high-
speed RS232 (most baud rates are hexadecimally-based), especially
if used with the 4 x PLL on an 18F

4MHz, 10MHz or 20MHz is better for shorter, exact periods, for
example 100us, because the cycle times are respectively 1us, 400ns
and 200ns. You might use something like this in a timer capture to
measure a fast event (eg ultrasonic sounding) or generate pulses. A
crystal like a 19.6608MHz, good for a clock/RS232, has a cycle
time of 203.45052083ns, which is not a pretty number to work with
if you want exactly 10us, 50us or 100us

So you choose your crystal based on the jobs the micro has to do

2007\02\24@043013 by Rikard Bosnjakovic

picon face
On 2/24/07, Jinx <EraseMEjoecolquittspam_OUTspamTakeThisOuTclear.net.nz> wrote:

> So you choose your crystal based on the jobs the micro has to do

Thank you for your very descriptive post. I will print it out and keep
it for reference when I start with my first PIC-circuit. Still waiting
(too long...) for the programmer to arrive by post.

--
- Rikard.

2007\02\24@045217 by Jinx

face picon face

> Thank you for your very descriptive post

You're most welcome. Good luck with the programming, I'm
sure you'll just rocket along when you can see the PIC working

If you get stuck, the list is here for you


2007\02\24@053725 by Tony Smith

picon face
> Another hex one is 9.8304MHz = $960000, which is good for
> high- speed RS232 (most baud rates are hexadecimally-based),
> especially if used with the 4 x PLL on an 18F
>
> 4MHz, 10MHz or 20MHz is better for shorter, exact periods,
> for example 100us, because the cycle times are respectively
> 1us, 400ns and 200ns. You might use something like this in a
> timer capture to measure a fast event (eg ultrasonic
> sounding) or generate pulses. A crystal like a 19.6608MHz,
> good for a clock/RS232, has a cycle time of 203.45052083ns,
> which is not a pretty number to work with if you want exactly
> 10us, 50us or 100us


Something to add to your "may come in handy but unlikey to" list is that
some car tools (diagnostics stuff etc) use RS232, and do so at 8192 baud.

Tony

2007\02\24@061530 by Rikard Bosnjakovic

picon face
On 2/24/07, Tony Smith <ajsmithspamspam_OUTrivernet.com.au> wrote:

> Something to add to your "may come in handy but unlikey to" list is that
> some car tools (diagnostics stuff etc) use RS232, and do so at 8192 baud.

This recalls another question I had in mind. Given that timing is not
a critical issue, does it matter what crystal you chose for your
particular project (provided it's within the range specified by
Microchip)?


--
- Rikard.

2007\02\24@065829 by Jinx

face picon face
> This recalls another question I had in mind. Given that timing is
> not a critical issue, does it matter what crystal you chose for your
> particular project (provided it's within the range specified by
> Microchip)?

If you're just like turning things on and off ? No (apart from the
power consideration of fast vs slow). And if you want to cut
costs you might use one of the RC modes

2007\02\24@074517 by Byron A Jeff

face picon face
On Sat, Feb 24, 2007 at 06:43:42AM +0100, Rikard Bosnjakovic wrote:
> On 2/23/07, Harold Hallikainen <@spam@haroldKILLspamspamhallikainen.org> wrote:
>
> > Yes, Fosc is divided by 4. So, if you have a 4MHz oscillator, the PIC runs
> > at 1,000 instructions per second (some instructions take twice as long,
> > like those that modify PC).
>
> I read about this (and some other crystal-based text) in my PIC-book,
> but what I cannot understand is why a 32768Hz-crystal is magical
> enough to use for clock-applications. Dividing 32768 with 4 gives me
> 8192, and that's a value that I certainly don't connect with anything
> that's got to do with timing.

It's magical because it's a power of 2. You divide it enough and you get a
nice round number to work with without having to do anything special.

Let me talk about my clock application. I applied a 32768 Hz watch crystal
to timer 1 of a 16F877, which is a 16 bit timer that counts up to 65536.
If you divide 32768 Hz/65536 you get exactly 0.5 Hz. Note that Hz is the
inverse of seconds, so if you invert 0.5 Hz you get 2 seconds. And if the
crystal is exactly on time at 32768 Hz then that time would be exactly 2
seconds.

Now the other point is that by using timer 1, I can decouple that 2 Hz clock
from the speed of the controller, which can now use a separate clock.
It's useful to be able to compute things faster without having to worry about
counting oddball frequencies in order to get exactly one second.

That's the magic of the 32768 Hz crystal.

> On the other hand, I haven't yet got a good grip of why to use
> crystals.

Supposedly they are a stable time base. That's the theory. I can tell you
that in practice crystal timebases drift especially based on temperature.

> To time the controller, sure, but...how?  I have read that
> an xtal oscillates due to some quartz-magic in it, but that's all. No
> clue of how it works.

You can treat it as a black box in this application. The PIC has all of the
necessary circuitry to make the crystal do it's job, with the exception of
the crystal capacitors required to get the circuit to oscillate.

>
>This is probably a good incitament to start this day with a visit to Wikipedia.

Don't bite off more than you can chew here. All you need to know right now is
that the crystal provides a stable time base. Over researching minute details
is a project killer.

BTW you never did tell me your application, which I think I asked about in
a previous post. All I've seen so far is you're using a 16F84 to build a
clock.

I have a page that describes why the 16F84 may not be your best starting point.
You can find it here:

http://www.finitesite.com/d3jsys/16F88.html

The peripheral packages (including the multiple timers which you should use
for this clock project) extends across many of the new PIC parts. The 16F84
will limit you in a lot of ways.

I'm starting to test what I think should be the gold standard for the PIC 16F
family: the 16F886 and 16F887. Full peripheral packages, nanowatt features
which means a decent internal oscillator up to 8 Mhz and the ability to add
up to 3 more I/O pins (well 2 I/O and one input) by repurposing the MCLR and
CLK pins, and bigger hobbyist friendly DIP packages (28 and 40 pins). Also
for the bootloader crowd (of which I am a member), they are self programmable.

I reiterate my thought that a newbie should start with the biggest, best
package and work their way down instead of the other way around. By doing so,
when you need a feature (more timers, more I/O pins, PWM, ADC, serial, etc)
then it's already there for you to use instead of having to hunt up another
part with the feature you need. Hobbyist generally build a series of one off
projects, so the bigger packages and the slightly higher costs are small
factors in the usage decision.

The upshot is that if you start with the 16F84, then you'll learn from
tutorials and webpages all of the twisted, convoluted ways to program stuff
around the part's limitations. Then you'll start thinking that's the normal
right way to go about handling serial, multiple timers, PWM and the like.
However, if you start with the best, right part from the start, then you'll
start designing with best practices from the start.

One last point. You need to download, print, and read the 16F midrange manual.
You can find it here:

http://ww1.microchip.com/downloads/en/DeviceDoc/33023a.pdf

It'll be a much better use of your study time than trying to understand the
ins and out of Colpitts and Pierce crystal oscillators.

BAJ

2007\02\24@080243 by Byron A Jeff

face picon face
On Sat, Feb 24, 2007 at 10:30:11AM +0100, Rikard Bosnjakovic wrote:
> On 2/24/07, Jinx <KILLspamjoecolquittKILLspamspamclear.net.nz> wrote:
>
> > So you choose your crystal based on the jobs the micro has to do
>
> Thank you for your very descriptive post. I will print it out and keep
> it for reference when I start with my first PIC-circuit. Still waiting
> (too long...) for the programmer to arrive by post.

My impatience is one of the reasons why I developed the Trivial PIC
programming series. You can get started with a single I/C and a handful of
discretes in a short period of time. It's not a good permanent programming
soluion (I'm partial to bootloaders myself), but it does have the quality
of near instant gratification.

http://www.finitesite.com/d3jsys

BAJ

2007\02\24@080426 by Byron A Jeff

face picon face
On Sun, Feb 25, 2007 at 12:58:01AM +1300, Jinx wrote:
> > This recalls another question I had in mind. Given that timing is
> > not a critical issue, does it matter what crystal you chose for your
> > particular project (provided it's within the range specified by
> > Microchip)?
>
> If you're just like turning things on and off ? No (apart from the
> power consideration of fast vs slow). And if you want to cut
> costs you might use one of the RC modes

This is also another good point in favor of the multispeed internal
oscillator that many PIC parts carry. You can pick a speed and you
don't even need to add any external parts.

BAJ

2007\02\24@101417 by peter green

flavicon
face

> > On the other hand, I haven't yet got a good grip of why to use
> > crystals.
>
> Supposedly they are a stable time base. That's the theory. I can tell you
> that in practice crystal timebases drift especially based on temperature.
They are FAR better than ceramic resonators or RC cuircuits.

One thing to remember is that we put much tighter requirements on timebases than on almost anything else. A clock whose speed was 1% off (and for most components 1% is considered good) would be gaining or losing about a quarter of an hour per day which most people would find totally unacceptable!


2007\02\24@101417 by peter green

flavicon
face

> This recalls another question I had in mind. Given that timing is not
> a critical issue, does it matter what crystal you chose for your
> particular project (provided it's within the range specified by
> Microchip)?
the exact speed isn't critical

in general selecting the clock speed is a compromise between power consuption and processing speed.


2007\02\24@101417 by peter green

flavicon
face


> -----Original Message-----
> From: RemoveMEpiclist-bouncesTakeThisOuTspammit.edu [spamBeGonepiclist-bouncesspamBeGonespammit.edu]On Behalf
> Of Rikard Bosnjakovic
> Sent: 24 February 2007 05:44
> To: Microcontroller discussion list - Public.
> Subject: Re: [PIC] making a quartz clock
>
>
> On 2/23/07, Harold Hallikainen <TakeThisOuTharoldEraseMEspamspam_OUThallikainen.org> wrote:
>
> > Yes, Fosc is divided by 4. So, if you have a 4MHz oscillator,
> the PIC runs
> > at 1,000 instructions per second (some instructions take twice as long,
> > like those that modify PC).
>
> I read about this (and some other crystal-based text) in my PIC-book,
> but what I cannot understand is why a 32768Hz-crystal is magical
> enough to use for clock-applications. Dividing 32768 with 4 gives me
> 8192, and that's a value that I certainly don't connect with anything
> that's got to do with timing.
you clearly aren't used to thinking in powers of two yet

1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536

devide 32768hz by 2 15 times and you end up with 1hz.




2007\02\24@101920 by michael brown

picon face
Rikard Bosnjakovic wrote:
> On 2/24/07, Tony Smith <RemoveMEajsmithspamTakeThisOuTrivernet.com.au> wrote:
>
>> Something to add to your "may come in handy but unlikey to" list is
>> that some car tools (diagnostics stuff etc) use RS232, and do so at
>> 8192 baud.
>
> This recalls another question I had in mind. Given that timing is not
> a critical issue, does it matter what crystal you chose for your
> particular project (provided it's within the range specified by
> Microchip)?
Not really, it's more a matter of convenience, need and personal
prefference.  When I first started, I used nothing but 4MHz xtals with the
16F84.  Now, the main 18 pin PIC that I tinker with is the 16F88, I suggest
you look into those as they are way nicer (and allot cheaper) than the F84.
They have an internal oscillator that is trimmed to 1% accuracy.  It can run
from 31kHz to 8MHz and can be changed on the fly, much more convenient than
external crystals, but still accurate enough to do serial comms and the
like.  For small stuff, I like the 12F683 (8 pins) but it lacks a built in
UART.

Now, I only use an external xtal when I need the accuracy.  For example, I
have a circuit used for timing mechanical clocks and watches that I have
managed to tweak within a couple of ppm (at room temperature) using an
external xtal and by playing with the loading caps.  I used a quartz analog
watch of known accuracy to tweak it all out by measuring the spacing of the
impulses to the stepper motor.  In this case I wanted uS precision with high
accuracy.

By using the extra oscillator that is part of the TMR1 module, you can use a
32kHz watch crystal to clock TMR1 so that the PIC can shut everything else
down (including its internal oscillator) and go to sleep, only waking up on
TMR1 rollovers.  This makes for very, very low power consumption (as in
batteries lasting for many months).  When awake, you can run at any speed
from 31kHz to 8MHz using the INTOSC module.

Right now I'm tinkering with a propellor clock type thingy.  For that
project, I'm likely to use a Dallas 1307 real-time clock chip in the "final"
version.

2007\02\24@121104 by Dario Greggio

face picon face
I can add that Higher frequency Clocks call for higher Power
consumption. Don't know if it's an issue...

--
Ciao, Dario

2007\02\24@160548 by Jinx

face picon face
> > and also, how do i wire the 32768Hz crystal into the t0clk pin?
>
> I don't think you can

On my first clocks, because of that and the lack of the fully-featured
PICs of today, I used (and still do occassionally in logic circuits) the
HA7210 as a driver for T0CKI

http://www.datasheetcatalog.com/datasheets_pdf/H/A/7/2/HA7210.shtml





'[PIC] making a quartz clock'
2007\03\01@224909 by Rikard Bosnjakovic
picon face
On 2/24/07, peter green <plugwashEraseMEspam.....p10link.net> wrote:

> in general selecting the clock speed is a compromise between power consuption and processing speed.

Higher clock speed = higher power consumption?


--
- Rikard.

2007\03\02@021714 by peter green

flavicon
face


> -----Original Message-----
> From: EraseMEpiclist-bouncesspammit.edu [RemoveMEpiclist-bouncesEraseMEspamEraseMEmit.edu]On Behalf
> Of Rikard Bosnjakovic
> Sent: 02 March 2007 03:49
> To: Microcontroller discussion list - Public.
> Subject: Re: [PIC] making a quartz clock
>
>
> On 2/24/07, peter green <RemoveMEplugwashspam_OUTspamKILLspamp10link.net> wrote:
>
> > in general selecting the clock speed is a compromise between
> power consuption and processing speed.
>
> Higher clock speed = higher power consumption?
yep


2007\03\02@033114 by Jinx

face picon face

> Higher clock speed = higher power consumption?

That's the beauty of multi-speed PICs. Low when you want
to save power, high when you want quick instructions

There's some debate though about a case like when the PIC's
asleep and you wake it to do a task. Wake it up in low gear
and it will use less power but it's on for longer. Wake it up in
top gear and it uses more power but it's on for a shorter time.
Sometimes the maths will prove the opposite of what you
instinctively think

2007\03\03@064957 by Howard Winter

face
flavicon
picon face
BAJ,

On Sat, 24 Feb 2007 07:45:15 -0500, Byron A Jeff wrote:

>...
> > On the other hand, I haven't yet got a good grip of why to use
> > crystals.
>
> Supposedly they are a stable time base. That's the theory. I can tell you
> that in practice crystal timebases drift especially based on temperature.

And in the Good Old Days you could get things called "Crystal Ovens", a little thermostatically-controlled housing that the crystal sat in, at a constant
temperature so at a much more stable/accurate frequency than one just sitting in the air.  Unfortunately they seemed to go the way of Thermionic
Valves ("vacuum tubes" for the left-ponders) so we're stuck with trying to do temperature compensation in other ways.

Jinx also came up with the idea of using the solenoid pulses from an MSF/DCF/WWVB wall-clock as a source of accurate 1 second pulses, but using a
clock to provide the signal to a clock seems a bit strange in this context!  :-)

Cheers,


Howard Winter
St.Albans, England


2007\03\03@071125 by Marsh James

picon face
Has anyone tried using a temperature compensating capacitor across the xtal?

Howard Winter <RemoveMEHDRWTakeThisOuTspamspamH2Org.demon.co.uk> wrote:  BAJ,

On Sat, 24 Feb 2007 07:45:15 -0500, Byron A Jeff wrote:

>...
> > On the other hand, I haven't yet got a good grip of why to use
> > crystals.
>
> Supposedly they are a stable time base. That's the theory. I can tell you
> that in practice crystal timebases drift especially based on temperature.

And in the Good Old Days you could get things called "Crystal Ovens", a little thermostatically-controlled housing that the crystal sat in, at a constant
temperature so at a much more stable/accurate frequency than one just sitting in the air. Unfortunately they seemed to go the way of Thermionic
Valves ("vacuum tubes" for the left-ponders) so we're stuck with trying to do temperature compensation in other ways.

Jinx also came up with the idea of using the solenoid pulses from an MSF/DCF/WWVB wall-clock as a source of accurate 1 second pulses, but using a
clock to provide the signal to a clock seems a bit strange in this context! :-)

Cheers,


Howard Winter
St.Albans, England


2007\03\03@094453 by Byron A Jeff

face picon face
On Sat, Mar 03, 2007 at 11:49:52AM +0000, Howard Winter wrote:
> BAJ,
>
> On Sat, 24 Feb 2007 07:45:15 -0500, Byron A Jeff wrote:
>
> >...
> > > On the other hand, I haven't yet got a good grip of why to use
> > > crystals.
> >
> > Supposedly they are a stable time base. That's the theory. I can tell you
> > that in practice crystal timebases drift especially based on temperature.
>

> And in the Good Old Days you could get things called "Crystal Ovens", a
>little thermostatically-controlled housing that the crystal sat in, at a
>constant temperature so at a much more stable/accurate frequency than one
>just sitting in the air.  Unfortunately they seemed to go the way of
>Thermionic Valves ("vacuum tubes" for the left-ponders) so we're stuck with
>trying to do temperature compensation in other ways.

My controller is in an unheated basement, so it is subject to varied
temperature swings.


> Jinx also came up with the idea of using the solenoid pulses from an
>MSF/DCF/WWVB wall-clock as a source of accurate 1 second pulses, but using a
>clock to provide the signal to a clock seems a bit strange in this
>context!  :-)

I had similar ideas. My first crack was using a $2 quartz clock movement to
adjust my clock. I tried passing the hour hand through a LED/photodiode
interruptor. Proved to be mechanically unstable.

If I ever decide to redo the project, I plan to use the 60 Hz power line
frequency as a time base with the 32 Khz crystal as backup when power fails.

As it is I simply go an reset the time every 5-6 weeks or so after it's
drifted far enough that the lights are coming on while it's still bright and
going off when still dark. Not enough of an annoyance to redo the project...
yet.

BAJ

2007\03\03@122146 by Mark Rages

face picon face
On 3/3/07, Howard Winter <EraseMEHDRWspamspamspamBeGoneh2org.demon.co.uk> wrote:
> BAJ,
>
> On Sat, 24 Feb 2007 07:45:15 -0500, Byron A Jeff wrote:
>
> >...
> > > On the other hand, I haven't yet got a good grip of why to use
> > > crystals.
> >
> > Supposedly they are a stable time base. That's the theory. I can tell you
> > that in practice crystal timebases drift especially based on temperature.
>
> And in the Good Old Days you could get things called "Crystal Ovens", a little thermostatically-controlled housing that the crystal sat in, at a constant
> temperature so at a much more stable/accurate frequency than one just sitting in the air.  Unfortunately they seemed to go the way of Thermionic
> Valves ("vacuum tubes" for the left-ponders) so we're stuck with trying to do temperature compensation in other ways.
>

Could you make a simple oven by epoxying the crystal to a PTC
thermistor run in self-heating mode?  Not a good choice for battery
operation.

Digital cell phones use a "temperature-compensated crystal oscillator"
that is good to a PPM or so across temperature.   One of these could
be salvaged for a hobby project, although you would have to design
around the frequency you get.  These parts are reasonably low-current.

Regards,
Mark
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2007\03\10@052156 by Vasile Surducan

face picon face
On 2/23/07, Rikard Bosnjakovic <RemoveMErikard.bosnjakovicKILLspamspamgmail.com> wrote

> but what I cannot understand is why a 32768Hz-crystal is magical
> enough to use for clock-applications.

32768 is not magical enough. There are a few crystals really magical:

14.7456MHz or 7.3728MHz because it could be divided exactly to 10mS
and offers also zero error for USART at 115200bps.

Vasile

More... (looser matching)
- Last day of these posts
- In 2007 , 2008 only
- Today
- New search...