Crystal Acuracy

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


Hi,
   Im play with a PIC 16F627 and have it wired up with a 4MHz cystal with
two 18pF Caps,
my question is, do the caps affect the acuracy of the oscillation of the
crystal, and I cant find any
data on the acuracy of the crystals, I cant check them as I dont have an
oscilloscope.

Im running at 4MHz and have created a dealy routine that does exactly
1000000 cycles and does some output
have included the output routine cylces to. Im 100% sure the code is correct
and that it should produce exactly 1 second time intervals. But when I run
the chip for 3 hours I lose 1 second. Im using a watch to check the timing
and im sure the watch is very acurate as it cost like $400 and know it keeps
good time.

What could be the cause of the lost time, do i need better quality crystals
or could it be the caps that
are affecting it.

Thanks.





Re: Crystal Acuracy



Quoted text here. Click to load it
with
the

Slightly in this case, but not enough to worry about.  I'd be using a
pair of 33pF caps though.

Quoted text here. Click to load it
an

The scope would probably alter the frequency too.

Quoted text here. Click to load it
correct
run
timing
keeps

If I got the calculation right, that's roughly 93 parts per million.
Your 4MHz crystal should be in the 50 parts per million range.  I bet
you missed a cycle or two somewhere.

That's an awfully difficult way to keep time.  I'm not saying that it
won't work, but it's tough.  Making a mistake counting cycles on this
scale is easy.  Use a timer to generate interrupts on a regular basis
and then you can stop counting cycles.  TMR2 is the easiest to get to
generate perfectly timed interrupts.  If you need more accuracy, then
look at a watch crystal (~20ppm) or even the DS3231 (2ppm), but they
only run at 32.768kHz.

Quoted text here. Click to load it
crystals


Re: Crystal Acuracy



Quoted text here. Click to load it
Ok cool will look into using intterrupt on TMR2, but it should be possible
using cycle counts for instructions which
is what I really wanted to do.

http://synios.com/delays.txt

see anything major wrong with these routines, specificaly the first
routine...

Thanks :)








Re: Crystal Acuracy



"Richard Harris" wrote:

Quoted text here. Click to load it
possible

Get real, I'm not counting cycles.  ;-)  Seriously, I doubt they are
wrong since you are only off by a tiny bit.  The biggest factor is the
loop that's calling these routines, I suspect that you are 1 cycle off
somewhere in that but probably in one of (if not the) outermost loop.
I'd say you are about one iteration off per every ten thousand.

Quoted text here. Click to load it


Re: Crystal Acuracy


Quoted text here. Click to load it

You've either missed a cycle count somewhere (most likely), or your
crystal is being loaded down too much and is slightly off frequency
(not very likely at all).
If you want to be sure then use an external crystal oscillator module
and run the PIC from that.

Do what Anthony says and use a hardware timer with interrupt, that is
precisely what it's there for. Counting cycles is begging Mr Murphy to
bring down his law and ruin your day.

Dave :)


Re: Crystal Acuracy



Quoted text here. Click to load it

The caps do affect the frequency somewhat.  If you want a really accurate
frequency, either buy a TCXO (temperature compensated crystal oscillator)
or an OCXO (oven controlled crystal oscillator), or fit a small variable
capacitor into your oscillator circuit (not sure off the top of my head
which of the two caps you need to adjust), and adjust it to match an
accurate reference e.g. gps, or radio standard.  To measure frequency you
could use a frequency counter though you can't attach it to either of the
crystal pins as this will affect the result.  You have to do something like
what you've been doing and monitor one of the other I/O pins, which as the
other poster noted you should do in a way such that you know that the ratio
between the frequency of the crystal oscillator and the I/O pin is exactly
what you think it is.  If you had a scope you could use it in X-Y mode and
make Lissajous (sp?) figures to compare the frequency of the I/O pin to a
known frequency standard, if you have one available.  If you can receive a
radio station on a known frequency which is an odd harmonic of a frequency
that you can generate from one of the I/O pins of the PIC, then you could
use the radio to 'beat' the signal from a short piece of wire attached to
the I/O pin of the PIC against the radio signal which might be a cheap way
of tuning it, all assuming the radio station is set up right.

The capacitance of the oscillator circuitry inside the chip will affect the
frequency of the oscillator, and this capacitance may be temperature
dependent and will probably also depend on the supply voltage of the chip.
For this reason, if you want to obtain very accurate results right away,
then a TCXO module with its own voltage regulator is a good option, and if
you use the built-in oscillator then you should use a stable supply voltage
regulator and keep the temperature stable also.  If you want to be fancy
then you could attach a temperature sensor to the PIC and make it correct
for its own temperature coefficient, but that seems like too much work.

Chris



Re: Crystal Acuracy


Quoted text here. Click to load it

You say that your delay routine including output uses exactly 1 million
cycles.  I presume that this code then repeats over and over without any
other cycles being used (that is, you've included *everything* in your
cycle count, even the jump back to the start of your code).

You also state that after 3 hours, you've lost one second.  This
suggests to me that your output routine is somehow displaying or
indicating a count of the number of delay periods, rather than just
flipping an output bit or something.

What form does your output take?  Is it a UART or an LCD or something
similar?  Does your output code have to wait on a status bit in a
register while outputting?  If so, have you taken this wait into account
in your cycle counting?

As other posters have indicated, what you're describing is not how this
kind of thing is usually done.  Is there a reason why you've chosen to
implement your code in this particular way?

Peter

Re: Crystal Acuracy



Quoted text here. Click to load it

probably the crystal, crystal oscilators can be trimmed to give higher
precision.

but it may be simpler to use a 32768Hz watch crystal.

or do both.


Bye.
   Jasen

Re: Crystal Acuracy


Ok guys, thanks very must for all your advice, it is very much appreciated.

Thanks


Quoted text here. Click to load it
correct
keeps
crystals



Re: Crystal Acuracy



"Richard Harris" wrote:

Quoted text here. Click to load it
appreciated.

Did you solve it?  Please let us know if/when you find the problem.


Re: Crystal Acuracy


Hi,
   I did the calculations for the crystals as shown below, I figured that i
will have to use a lower
frequency anyway and it should be suitible for my application. I have
located some watch crystals
online and have come accross a detail about them that is different for each
manufacture.
What exacly is the "Load capacitance" of a crystal?

Thanks

Crystal @ 32768 Hz    Tolerance @ 20 ppm
 1hour = ( 32768 * 60 * 60 ) = 117964800
 117964800 / 1000000 = 117.9648
 117.9648 * 20 = 2359.296
 ( 1 / 32768 ) * 2359.296 = 0.072
 Total Possible Loss Per 1 hour = 0.072 seconds

Crystal @ 4000000 Hz   Tolerance @ 50 ppm
 1hour = ( 4000000 * 60 * 60 ) = 14400000000
 14400000000 / 1000000 = 14400
 14400 * 50 = 720000
 ( 1 / 4000000 ) *720000 = 0.18
 Total Possible Loss Per 1 hour = 0.18 seconds


Quoted text here. Click to load it
correct
keeps
crystals



Site Timeline