Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

CRYSTAL TUNING PART II
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CRYSTAL TUNING PART II

by Russell 27 on Wed May 07, 2014 12:46 pm

VARIABLE TUNING.PNG
VARIABLE TUNING.PNG (879.98 KiB) Viewed 925 times

If you had interest in my earlier CRYSTAL TUNING POST, this method is easier to implement, while offering the same type of result. I used two Murata 3-10 Pf SMD Variable capacitors TZC3 MURATA PDF. Really only need one on C9, pin 9 crystal input, just decided to go this route. Oscilloscope image shows measurements after tuned crystal.

CRYSTAL MEASUREMENTS.PNG
CRYSTAL MEASUREMENTS.PNG (6.78 KiB) Viewed 921 times

In first image, top of adjustment slot is pointing to about 1 O'clock. Considering this a reference, Max adjustment is at 3 and minimum is at 9 O'clock. I measured a range of 2.6 -12 Pf though the adjustment range. Turning past that 180 degree arc, capacitance value moves in the opposite direction. After tuning I'm somewhere between 9 and 10 Pico farad, from looking at the slot reference. Turning clockwise slows clock, tuning counter clockwise speeds clock. After installation, clock out fuse can be set to send buffered crystal frequency to pin 14, and frequency can be tuned accurately with a scope or meter. You can do this blind, it will just take some time and experimenting.

SOLDER LEADS.PNG
SOLDER LEADS.PNG (869.2 KiB) Viewed 925 times

Solder pads on capacitor and board do not match up, So I soldered on leads to underside of capacitor. This particular resistor had leads that were perfect, at about 26 AWG. I use a 15 watt soldering iron, with a fine tip. Taping down parts with blue masking tape, cut into small strips, holds the parts down nicely while making a solder joint. Then carefully form leads to fit the holes where original capacitors were. Capacitors will be slightly raised from board surface. You may have a better way. I've been pleased with the original tuned oscillator results, In the short term this looks promising.
Russell 27
 
Posts: 240
Joined: Thu Sep 12, 2013 3:59 pm

Re: CRYSTAL TUNING PART II

by jarchie on Wed May 07, 2014 4:56 pm

I like the elegance and simplicity of this solution. Nice work!

jarchie
 
Posts: 595
Joined: Sun Jun 24, 2012 2:16 pm
Location: Santa Cruz, California, United States

Re: CRYSTAL TUNING PART II

by phild13 on Mon May 12, 2014 12:54 pm

Excellent! That is exactly what I was wanting to do and it even looks good!

I think I will just do the same as you have as I think it may just be easier and it looks good.

Previously (in your other thread), I was thinking of ordering a smaller size trimmer like a TZY2Z100A001R00 which is 2mm vs 3mm in hopes it would sit on the pads and be able to be soldered to the pads directly. Do you think that may also work?

Is there optional code (disabled by default) that can be added to Johns RevD firmware to send buffered crystal frequency to a pin? I think pin 3 is unused on both board versions (Adafruit and RevD) and would be a good pin.

phild13
 
Posts: 247
Joined: Mon Sep 10, 2012 1:05 pm

Re: CRYSTAL TUNING PART II

by Russell 27 on Mon May 12, 2014 1:13 pm

If you just want to read frequency, You don't need code. Just set clock out fuse bit; LOW FUSE A5 sent to pin 14. I can post my method if you need. If you want to send out frequency continuously, you would need some kind of code I guess. I don't see a reason you couldn't solder those particular capacitors on directly, I just liked these TZC3 type.
Russell 27
 
Posts: 240
Joined: Thu Sep 12, 2013 3:59 pm

Re: CRYSTAL TUNING PART II

by phild13 on Mon May 12, 2014 1:43 pm

I like the type you used as I think they look better, but had selected the smaller ones as I think they will fit directly. I think on the next order I make I will get both styles and see what I think.

For me right now I will be using the "that looks about close enough to start with" method as I don't yet have a scope.

As far as the code goes, it was just a thought. When the time comes, I will probably just set the fuse and read it from pin 14 then reset the fuse when done.

phild13
 
Posts: 247
Joined: Mon Sep 10, 2012 1:05 pm

Re: CRYSTAL TUNING PART II

by Russell 27 on Mon May 12, 2014 2:05 pm

If you have a frequency counter in one of your meters, you could use that. But depending on the resolution it could be more rough. For example, the fluke I have only has resolution down to 1 hertz, but it's better than nothing. It should round to about .5 hertz, which would be a decent enough start point. I always set fuses to A5 DF F9; LOW, HIGH, EXTENDED. This might not be necessary, but I always erased program so it wasn't running at 32 Khz in the background, pin 14 is used for settings, and I didn't know if this would cause a problem with that frequency on there. To flash back you will need to set -B bitclock; AVRDUDE example as follows:

Code: Select all | TOGGLE FULL SIZE
avrdude -B 128 -c usbtiny -p atmega168 -u -U lfuse:w:0xE2:m -u -U hfuse:w:0xC6:m -u -U efuse:w:0xF9:m

or with John's clock

Code: Select all | TOGGLE FULL SIZE
avrdude -B 128 -c usbtiny -p atmega328p -u -U lfuse:w:0x62:m -u -U hfuse:w:0xD1:m -u -U efuse:w:0x06:m
Russell 27
 
Posts: 240
Joined: Thu Sep 12, 2013 3:59 pm

Re: CRYSTAL TUNING PART II

by phild13 on Mon May 12, 2014 3:04 pm

yea, I was going to use the Fluke for initial setting as a close enough to start with then see if it clocked fast or slow and go from there.

phild13
 
Posts: 247
Joined: Mon Sep 10, 2012 1:05 pm

Re: CRYSTAL TUNING PART II

by Barry914 on Fri May 23, 2014 2:45 pm

I just swapped out the 20pf caps for 10pf NPO. The clock was running about 2 seconds a day slow. Now it's drift is too low to reliably read after 24 hours. Based on Russell's results with his trimmers it seems 10pf is about right - certainly better than 20pf.

My wife thinks there's something odd about me trying to watch the clock and my laptop for minutes at a time several times a day. I think it's odd she doesn't get it.

Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: CRYSTAL TUNING PART II

by phild13 on Fri May 23, 2014 3:27 pm

I have 11pf in my clocks and they work pretty well, but I am planning on picking up some 10pf and 2 different (physical) size trimmers based on what Russell has posted to give them a try.

phild13
 
Posts: 247
Joined: Mon Sep 10, 2012 1:05 pm

Re: CRYSTAL TUNING PART II

by jarchie on Sat May 24, 2014 2:40 am

By setting the fuses as Russell suggested, the clock output may be compared to a pulse-per-second GPS reference. I've used the pulse-per-second output of the Adafruit Ultimate GPS with the following Arduino sketch:

Code: Select all | TOGGLE FULL SIZE
// attach the pulse-per-second reference to pin 2
// attach the ~32768 Hz signal to pin 3

// note:  first ppm output will be rubbish

#define SECONDS_PER_COMPARISON 31UL  // accuracy of ~1ppm
//#define SECONDS_PER_COMPARISON 310UL  // accuracy of ~0.1 ppm

int32_t xtal_count = 0, pps_count  = 0;

void setup(void) {
  Serial.begin(9600);

  attachInterrupt(0, handlePPS,  RISING);
  attachInterrupt(1, handleXTAL, RISING);
}

void loop(void) {}

void handlePPS(void) {
  cli();
 
  if(++pps_count == SECONDS_PER_COMPARISON) {
    int32_t xtal_copy = xtal_count, pps_copy = pps_count;
    xtal_count = pps_count  = 0;
    sei();
   
    // print the difference in parts per million
    float delta_ppm = xtal_copy - (pps_copy << 15);
    delta_ppm /= SECONDS_PER_COMPARISON << 15;
    delta_ppm *= 1e6;
    Serial.print(delta_ppm);
    Serial.println(" ppm");
  } else {
    sei();
  }
}

void handleXTAL(void) {
  cli();
  ++xtal_count;
  sei();
}


To set Russell's recommended clock fuses, I used the following command:

Code: Select all | TOGGLE FULL SIZE
avrdude -P usb -c usbtiny -p atmega328p -B 128 -e -u -U lfuse:w:0xA5:m -u -U hfuse:w:0xDF:m -u -U efuse:w:0x01:m


On an Adafruit clock with 10 pF caps and an ATmega328p, the clock was within 1 ppm at around 75°F, so 10 pF seems like a reasonable starting point.

jarchie
 
Posts: 595
Joined: Sun Jun 24, 2012 2:16 pm
Location: Santa Cruz, California, United States

Re: CRYSTAL TUNING PART II

by Barry914 on Tue May 27, 2014 11:29 am

Seems right, It's been several days since I replaced the 20pf caps with 10pf caps, and the drift is still too small to accurately estimate. No scope, no frequency meter, so comparison to my NTP synched laptop is pretty much all I have to go by. I doubt I could get it closer with trimmers, since in my experience they tend to mechanically drift a bit after tweaking them, even if they are otherwise stable.

Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: CRYSTAL TUNING PART II

by jarchie on Tue May 27, 2014 2:06 pm

Barry914 wrote:Seems right, It's been several days since I replaced the 20pf caps with 10pf caps, and the drift is still too small to accurately estimate.

You're using the kit-provided ATmega168v, correct? I vaguely remember trying 10 pF caps with that chip also, and the timekeeping was nearly perfect.

jarchie
 
Posts: 595
Joined: Sun Jun 24, 2012 2:16 pm
Location: Santa Cruz, California, United States

Re: CRYSTAL TUNING PART II

by Barry914 on Wed May 28, 2014 12:12 am

Correct, it's the kit-supplied ATmega168v. I'm very happy with how it turned out and I have really enjoyed getting it to this point, so I am going to focus on a new clock project for a bit. This one's kind of different from the Ice Cube Clock and it poses a whole new set of challenges. Should keep me busy for a while.
Attachments
IMG_20140526_130833.jpg
IMG_20140526_130833.jpg (103.68 KiB) Viewed 809 times

Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: CRYSTAL TUNING PART II

by Barry914 on Tue Jun 17, 2014 11:13 am

Just wanted to post an update to this thread. My clock drift is still too low to call by eye, although it seems it might be running just a tiny bit fast, or maybe it drifts both ways with temperature, moon phases or whatever. Perhaps I am extremely lucky, but it seems replacing C8 & C9 with 10pf NPO's is something I'd recommend to anyone building this clock. Kudos to John and Russell for their contributions to making this yet another fun Adafruit project.

Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: CRYSTAL TUNING PART II

by jarchie on Tue Jun 17, 2014 6:52 pm

Thanks for the info! And if you ever feel like playing with xmas, just email me and I'd be happy to mail you a preprogramed chip.

Going back to my notes, my clock ran slow by ~0.4 ppm with the 10 pF caps--and a bit slower while sleeping (~3.2 ppm).* As you noted, other factors are probably the primary source of error with such high accuracy. In fact, the crystal datasheet only guarantees an accuracy of ±20 ppm at 25˚C! Thankfully the crystals seem to be more accurate in the real world. When playing with software temperature compensation, I took some measurements, and below is the subset at room temperature (18-30˚C / 65-85˚F):

error-roomtemp.jpeg
The solid lines represent the theoretical range of error given the center temperature and parabolic coefficient ranges given in the datasheet. The crosses represent actual measurements.
error-roomtemp.jpeg (15.7 KiB) Viewed 778 times

The measurements were taken by heating a room-temperature circuit to ~50˚C, cooling to ~0˚C, and heating to room temperature. Most of the slower frequencies at cooler temperatures were measured while the circuit was warming up, and the crystal may have been slowed by slight water condensation on the circuit.

Interestingly, Adafruit seems to have switched to an external RTC in later kits like the Timesquare Watch and Monochron. Their rationale is "...the main microcontroller chip [can] keep track of the time, but its not as good at it (both in terms of power and precision)." Although that is true, I have to wonder if these later kits would still use the DS1337 if Adafruit had used 10 pF caps with the earlier Ice Tube Clock kit... (In terms of power, the newer ATmega328p used in those projects can keep track of time while only consuming 1-2 uA--translating to years of sleep on a small coin cell. The DS1337 does consume less--a difference of about three fold.)



* Russell's fuse settings by themselves were not sufficient to get accurate frequency measurements while on battery power. The crystal frequency was unstable, probably because the battery load was too high. I was able to get consistent measurements by programming the microcontroller with the following code to reduce power consumption:

Code: Select all | TOGGLE FULL SIZE
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/wdt.h>

int main(void) {
    power_all_disable();
    wdt_disable();
    sleep_enable();
    set_sleep_mode(SLEEP_MODE_IDLE);
    sleep_bod_disable();
    for(;;) sleep_cpu();

}

jarchie
 
Posts: 595
Joined: Sun Jun 24, 2012 2:16 pm
Location: Santa Cruz, California, United States

Please be positive and constructive with your questions and comments.


cron