Butterfly and External Crystal

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was following a thread on the 4 megabit memory that is included with the Butterfly and asked myself why am I not using this for my Telescope project. Then I remembered the internal IC is not accurate enough for my purpose. So the question is: Can I connect an external crystal (7.328 MHz) to the Butterfly?

I searched the archives but did not see anything that mentioned this. If this is possible it would make things easy.

Thanks

Bob Parry

Bob Parry

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doesn't the Butterfly have a 32kHz crystal built-in that is used to tune the internal oscillator for reliable UART comms? You should be able to get decent timing off of that for all but the most demanding of requirements.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, the Butterfly has an 32.768 kHz crystal and example code for using it to calibrate the internal oscillator. But, I don't know the absolute accuracy in calibrating to something like 7.328 MHz. Even calibrated, the internal oscillator isn't as accurate as a crystal is it? I'm not sure how demanding the telescope application would be.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm assuming that this is a tracking-telescope application, so it is "RTC"-type functions that are needed rather than tuning to exactly, say, 7.3728MHz.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To drive the servo motors I need a pulse train to the Gecko controller. With my gearing I need 130.32 pulse per second. With the 7.328 MHz Crystal I can get to 99.99 for sure and maybe another 9 but I would have to check. For visual use the RC oscillator would be adequate, however for photography it needs a crystal.

Bob Parry

Bob Parry

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe Lee is suggesting either running the step timing off of the 32kHz(TOSC2) irq, or running the regulation loop against the 32kHz.
This will give you a frequency error of some +/- 8 ppm over a 0-40 deg.C temperature range (after calibration against a frequency standard), with a jitter of +/- 16 usec.
The jitter is less than the timing uncertainty in the gecko drives, so it's not relevant. The +/- 8 ppm error is actually less than you can expect to get from a cheap 7MHz AT cut xtal over the same temperature range, so that's good too.

Without calibration of the resonator on the butterfly you can expect a 20 ppm error, with an uncalibrated AT cut crystal 50-100 ppm.
A 6000 mm focal length onto a 10mm CCD is 0.1 degrees viewing angle, and a star would traverse the CCD in 23 seconds. With 1024 pixels, the single-pixel-smear time error would be 22 ms, which, with a 20ppm error, allows an exposure time of 19 minutes.
So, the butterfly 32kHz resonator ought to be enough.

If you need more, you likely also need an absolute time input in order to be able to point the telescope; a GPS receiver with PPS output as an example.

Edit: temperature plot of a tuning fork similar to the one on the butterfly: http://n1.taur.dk/602ur.gif

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting. With that few pulses/second each pulse is severl ms. apart anyway so each individual tick of the system clock isn't grossly important--there is a bit of "jitter" each pulse even if right-on 130.32. So if a pulse is skipped/added every rollover to adjust it should come out well.

Is the 130.32 exact, or only to 0.01?

Anyway, the 32kHz itself can't get too close (according to a session with AVRCalc). 130.5498 is the closest; that would be skipping one pulse every 394.

8 MHz best is 130.32075--dammm close, eh? A skip every 173333, about every 22 minutes.
7.3728 best is 130.32135. That would mean skipping one pulse every 96296, about every 12 minutes.

Just as a guess the latter numbers are probably within the precision of your backlash, etc.

AVRCalc also suggests 4.433619 MHz as a "standard" value. DigiKey shows 4.433618, 619, & 620 so these values must be normal in some app area. All these can get to 130.3200nnn so they would be good candidates for you.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Every 8* clocks of the 32kHz watch crystal oscillator:
Add 68325212 to a 32 bit integer. Test if it's gone negative. If so, xor with 0x80000000 and take a step.

Resulting theoretical rate would be 130.32 to 10 places, and completely irrelevant compared to the crystal error.
Jitter would be 125 usec peak, or 1,6%, which is also irrelevant.

*arbitrarily chosen. That'll give you 244 clocks to work with at 1MHz RC oscillator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is getting very interesting. If I could use the 32 KHz crystal at +/- 8 ppm I would be happy.

Here are the calcs for the required pulse rate.

500 count quadrature encoder on motor shaft
19.7 : 1 reduction on servo motor
285 : 1 worm wheel
86,164.1 seconds per Sideral Day (RASC Observers Handbook)

Number of tics per revolution (day) = 500 x 4 x 19.7 x 285 = 11,229,000

Divide this by 86,164.1 and we get130.321097

I have used AVRCalc to setup the timer for my drive and it works well. However the Butterfly has some things built right in at a price that is unbeatable if I can get the same accuracy. The easiest would be to connect an external crystal if that is possible. If not some idea on how to procede using the watch crystal.

I'm a better mechanic than programmer so I may need a little hand holding.

Thanks

Bob Parry

Bob Parry

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look at timer 2. It can be programmed for asynchronous mode (in which case it'll be running off of the 32kHz watch crystal).
The pulse rate will be 32768(crystal) / 8(irq interval) / 2^31(number of bits below sign) * 68325787(the number you add) = 130,321096.
If you have a frequency normal and counter, measure the output with a window of several minutes. If you don't, find a bright star and adjust the number you add until it stops drifting. We're not talking high drift rates to begin with, I'm imagining placing it at the edge of the viewport (or whatever structure is close to the focal point) and waiting an hour..

If you need better, there is the (cheap!) DS3231. It's an everything-integrated RTC module with temperature compensation. With two resistors and power, it'll output a 2ppm accurate 32kHz you can feed onto the butterfly's xtal pin. Beyond that there's the realm of precision timekeeping and the cost goes up fast.

(I just remembered a no-cost method for oscillator calibration I used once; I'll see if I still have the software and post it here..)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Can I connect an external crystal (7.328 MHz) to the Butterfly?

You can attach an external clock, but it requires some surgery. There are several 0 ohm resistors (and empty places to put one) on the board that are used to configure things. For an external clock you remove the resistors R203 (which disconnects the 32.768khz crystal) and R404 (which disconnects pin 10 of the JTAG header from ground). You then add a 0 ohm resistor to R204 (which connects XTAL1 to JTAG pin 10). You can then attach the output of a crystal oscillator to JTAG pin 10. There is no easy way to get to XTAL2 though, so a straight crystal would be harder.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I ran the numbers that KKP provided and damn if they are not correct. I am not sure what magic you are doing here.

If I have to divide and mulitply by all these enormous numbers, I can see a problem. However I do not think that is what you are thinking of doing.

Do you have some pseudo code or something to explain this interesting procedure?

Thanks again

Bob Parry

Bob Parry

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been doing some research on PLL which I believe this is.

From what I understand every 8th clock of the 32768 crystal is added to a 32 bit buffer, 68325787 is then added to this buffer and checked to see if it has overflowed if so then xor with a number 0x80000000 and step. Is this correct? The xor I believe does the Phase Correction?

Now then, I do not know how to calculate these numbers.
From what I have been able to discover PLL is a course in itself, so I am looking for a cookbook version that will get me going.

Thanks again for your help.

Bob Parry

Bob Parry