Author Topic: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?  (Read 7229 times)

0 Members and 1 Guest are viewing this topic.

Offline DoomkeksTopic starter

  • Newbie
  • Posts: 5
  • Country: de
Heello Forum  ;)

The (32768Hz) crystal is connected to a µC (16F1508):



The firmware generates a 64Hz square wave (prescaled from the 32768Hz) on a DO pin of the µC which is probed by the Analog Discovery.
(You can't probe a crystal directly without affecting it's frequency.)

The idea is to precisly measure the frequency and adjust the trimmer cap until it's 64.00000....Hz.
To do this you would run a frequency counter for some minutes and then divide the elapsed time through the #of pulses to get a very precise average.

The only thing I have is the Analog Discovery. Suprisingly, I could not find a frequency counter function yet.  ??? (It should be easy for the devs to implement one.)
It comes with an frequency average tool in the scope section, but you can only use it for relatively small time spans and not in a minute range.
So it is not precise enough.

The record feature of the scope section would be helpful, but you can't trigger data entries with the signal edges. (Recording only with fixed sampling rates. => not helpful)

I can get good results with averaging just some ms with the scope feature but I need a little more precision. (see screencap)

Does anyone have an idea how to do this with the Analog Discovery? I'm sure there is a way...
Thank you!
(Background: binary clock project)





(NOTE: Of course it makes no sense to calibrate the circuit on a breadboard ;) This is just for testing purposes, the circuit will be calibrated on the final pcb.)
 

Offline babysitter

  • Frequent Contributor
  • **
  • Posts: 893
  • Country: de
  • pushing silicon at work
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #1 on: February 21, 2015, 03:45:59 pm »
A relatively modern soundcard can sample the 32768 Hz, record for a longish time and count the zero crossings. Or use one of those spectrum analysis tools. Analog discovery might sleep during that or work on better things.

I'm not a feature, I'm a bug! ARC DG3HDA
 

Offline DoomkeksTopic starter

  • Newbie
  • Posts: 5
  • Country: de
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #2 on: February 21, 2015, 08:26:10 pm »
Danke!
I did not think of this.
The soundcard method should do the trick ;)
Problem: my signal looks like this:
(pulsating dc)



...but my soundcard needs this:
(ac)



Is there an easy way to generate a -2.5V offset?
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #3 on: February 21, 2015, 08:31:58 pm »
Danke!
I did not think of this.
The soundcard method should do the trick ;)
Problem: my signal looks like this:
(pulsating dc)



...but my soundcard needs this:
(ac)



Is there an easy way to generate a -2.5V offset?

So capacity couple the signal.
 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: us
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #4 on: February 21, 2015, 08:50:47 pm »
You can't really use the Analog Discovery or a computer to calibrate the oscillator for your clock, because neither of them has an accurate oscillator to use as a standard.  Why not just build your clock and then see how much it drifts in a day compared to an accurate time source (NTP)?  Then you will know how much you need to adjust the oscillator.  (An even better way is to leave the oscillator alone, and do the calibration in the clock software.)


 

Offline DoomkeksTopic starter

  • Newbie
  • Posts: 5
  • Country: de
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #5 on: February 21, 2015, 10:38:06 pm »
So capacity couple the signal.
:-+

Quote
neither of them has an accurate oscillator to use as a standard
Yes, you might be right...

The problem is I would not even know in which direction I'd have to adjust the trimmercap (It has no stop). A live monitoring device would be helpful.

My clock is based on Timer1 overflow, which triggers an interrupt every second. The Timer1 clock tick comes from the 32768Hz crystal.
Calibrating it via software would require pausing the Timer / incrementing it in the ISR. This seems to be a little dodgy  :D

Adjusting the trimmercap via trail and error should be the best solution for me. I will post some pics when it sits in the final box.

Thank You ;)
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #6 on: February 21, 2015, 10:41:51 pm »
Quote
The idea is to precisly measure the frequency and adjust the trimmer cap until it's 64.00000....Hz.

You will need a more accurate timing source, like a ocxo or a tc-vcxo -> they can do 2.5ppm or better.

Short of that, try WWV - but it can be messy.

Another approach is to use a gps to generate a 1pps signal.
================================
https://dannyelectronics.wordpress.com/
 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: us
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #7 on: February 21, 2015, 11:32:34 pm »
My clock is based on Timer1 overflow, which triggers an interrupt every second. The Timer1 clock tick comes from the 32768Hz crystal.
Calibrating it via software would require pausing the Timer / incrementing it in the ISR. This seems to be a little dodgy  :D

There are a lot of other ways.  You could have the tick interrupt add a fixed point value which represents the measured tick duration to a software accumulator, then increment the time when that accumulator overflows.
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 19468
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #8 on: February 21, 2015, 11:43:47 pm »
One way or another, you will end up comparing two frequencies - one from your circuit and one "golden" reference.

Your circuit's frequency cannot be more accurately set than the reference frequency.

You could use the Analog Discovery's waveform generator as the reference frequency, in which case the accuracy is determined by the onboard MEMS resonator.

A traditional way to compare frequencies using an analogue scope is to apply one frequency to channel 1, the other to channel 2, and set the scope display in XY mode. If the frequencies are identical then the trace will seem stationary. If there is a frequency offset the trace will rotate clockwise or anticlockwise. So you simply twiddle your calibrator until the rotation slows down and ideally stops.

I haven't tried that with a digital scope such as the Analog Dscovery, but traditionally digital scopes XY displays are "tricky" to the extent that some use it as a way of demonstrating the benefits of analogue scopes.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #9 on: February 22, 2015, 01:05:49 am »
Quote
The only thing I have is the Analog Discovery. Suprisingly, I could not find a frequency counter function yet.

I looked at the manual and it does have a clock generation function - 20Mhz clock.

So one way to do it, if you think the discovery's clock is more accurate, is to program the PIC to measure the discovery's clock generation, with the 32Khz crystal as the gate.

Adjust the trimmer until the read-out matches your expectation.

If you don't want to learn to program the PIC, you can use a counter as well.
================================
https://dannyelectronics.wordpress.com/
 

Offline babysitter

  • Frequent Contributor
  • **
  • Posts: 893
  • Country: de
  • pushing silicon at work
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #10 on: February 22, 2015, 09:23:05 am »
If you are living close to the rhein main area, come over, you can do the adjustment here.

I'm not a feature, I'm a bug! ARC DG3HDA
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5125
  • Country: nl
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #11 on: February 22, 2015, 10:01:16 am »
Divide the output by 64, let it count seconds for as long as you can, compare with a real clock, adjust, repeat.  :)
Keyboard error: Press F1 to continue.
 

Offline Stigaard

  • Contributor
  • Posts: 36
  • Country: dk
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #12 on: February 22, 2015, 10:22:59 am »
You can't really use the Analog Discovery or a computer to calibrate the oscillator for your clock, because neither of them has an accurate oscillator to use as a standard.  Why not just build your clock and then see how much it drifts in a day compared to an accurate time source (NTP)?  Then you will know how much you need to adjust the oscillator.  (An even better way is to leave the oscillator alone, and do the calibration in the clock software.)
If the computer is sync'ed with ntp and he is counting pulses, he does not need to use the soundcard sample clock, therefore he will only by relying on the pc's watch accuracy which with a ntp client should be more than good enough for the synchronization of another watch, only issue is that trimming will be far from realtime so that part might be very difficult. It may in fact be easier to change between fixed caps and keeping notes on errors for each value on a piece of paper, this should allow for reasonable fast trimming using educated guesses based on prior values.
 

Offline DoomkeksTopic starter

  • Newbie
  • Posts: 5
  • Country: de
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #13 on: February 22, 2015, 12:34:09 pm »
Quote
A traditional way to compare frequencies using an analogue scope is to apply one frequency to channel 1, the other to channel 2, and set the scope display in XY mode
Good Idea! The Analog Discovery has a xy feature. I could try that. Although the frequency of the Analog Discovery would propably not be accurate enough.

Quote
close to the rhein main area
Unterfranken

Quote
I looked at the manual and it does have a clock generation function - 20Mhz clock.
Yes it has a function generator, but I was looking for a feature which counts rising edges on the Input for a long period of time.

Quote
Short of that, try WWV - but it can be messy.
Thats of course the holy grail, but it need more periphery and is harder to implement in software. Same with GPS. Maybe in a future project ;)

Another sweet way to build an extremely precise clock is using the mains AC frequency as a reference. It is synced to the Coordinated Universal Time (UTC). (My country does this.)
Although it fluctuates more than a crystal, the long time average is very precise. It just needs a small transformer, a fuse for safety and a diode.   

My binary clock is running for some time now and I'm really happy with the accuracy. (less than 1s in 5 hours compared to a radio clock.)
Bevore I got the crystal I tried to use just the internal Osc of the Pic but the accracy was very bad. ~1s /h fluctuation no matter what.

My clock will be a wallmount design, around 210 x 110mm in size. I'm using those cheap, white 5mm strawhat LED's from China. They are amazing for diffsional applications. (Ebay link)
Each Led will light up a 30x 30mm chamber behind a frosted acrylic glassplate. All in a wooden cabinet.
 

Offline babysitter

  • Frequent Contributor
  • **
  • Posts: 893
  • Country: de
  • pushing silicon at work
Re: Calibrating a Crystal OSC with the Digilent Analog Discovery and µC ?
« Reply #14 on: February 22, 2015, 12:56:49 pm »

Quote
close to the rhein main area
Unterfranken


"Bayrischer Untermain" ? Slowly homing in... to be exact, Aschaffenburg!
I'm not a feature, I'm a bug! ARC DG3HDA
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf