TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie software

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
jarchie
 
Posts: 615
Joined: Sun Jun 24, 2012 2:16 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by jarchie »

Those constants should not affect your clock. They are used for the automatic learning half of the automatic drift correction method, and automatic learning is disabled when AUTODRIFT_CONSTANT is defined.

The TIME_MAX_DRIFT_TIME macro covers the case where a clock user manually sets time forward or back by over 20 minutes. The reason for such a large time correction is probably not due to time drift. Maybe the time is being adjusted for a different timezone. Maybe the user is correcting for daylight saving changes by manually changing the time. Maybe someone set a wildly inaccurate time when playing around with the clock. Whatever the reason for the large time change, the clock will not use that change to determine how slow or fast it's running. This is just another heuristic to make clock drift learning more robust.

User avatar
russell 27
 
Posts: 242
Joined: Thu Sep 12, 2013 3:59 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by russell 27 »

Okay

That's not exactly what I meant, but I got it.

Thanks

User avatar
russell 27
 
Posts: 242
Joined: Thu Sep 12, 2013 3:59 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by russell 27 »

I did some tests on tuning the crystal load capacitors, directly on the ADAFRUIT ICE TUBE clock board. If anyone has interest, let me know and I will try and put something together.

User avatar
jarchie
 
Posts: 615
Joined: Sun Jun 24, 2012 2:16 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by jarchie »

Russell 27 wrote:I did some tests on tuning the crystal load capacitors, directly on the ADAFRUIT ICE TUBE clock board. If anyone has interest, let me know and I will try and put something together.
Several users have had good luck using 10 pF oscillator caps in the Adafruit design, but if you've discovered a better solution, I'd wager that a lot of people--including myself--would be interested.

User avatar
russell 27
 
Posts: 242
Joined: Thu Sep 12, 2013 3:59 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by russell 27 »

Has anyone else Used John's firmware with automatic time deviation correction. It did not work for me. It is supposed to eventually become right on accurate. May be my measurement of accuracy is more stringent. Interested in your thoughts.

User avatar
jarchie
 
Posts: 615
Joined: Sun Jun 24, 2012 2:16 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by jarchie »

If you describe the problem in detail, I might be able to help.

User avatar
russell 27
 
Posts: 242
Joined: Thu Sep 12, 2013 3:59 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by russell 27 »

There comes a point when accuracy is splitting hairs, Although it is an important issue to some because many have used the GPS. Using such a complex, sophisticated device just to keep accurate time is pretty serious, this is just one small task GPS is capable of. There is some great software compensation. But I find two deficiency's. Unless exact deviation is known, there can be much trial and error. Also the correction factor may never be able to match exactly. While most power outages last several minutes to several hours, when in battery backup Atmega constantly goes in and out of sleep mode, and the program doesn't apply deviation correction during this time. A tuned oscillator may not rival GPS, but it's superior to software correction. The version I put in my prototype clock has gone several weeks without one second in deviation, way beyond my expectation. Either my source clock and clock deviate exactly the same, or it has this kind of accuracy. Even unplugged for long periods of time, no deviation. While I have had success in fine tuning my original posted 2565 AUTODRIFT_CONSTANT to 2100, Auto correction starts to wander if I let it work on it's own. So when I talk about accuracy, my tests have been as hair splitting as I could be to try and rival a GPS'less GPS accuracy. Two advantages of the tuned oscillator circuit over the Maxim time chip are; a tunable frequency and I ordered an SMD Inverter (not) gate that is rated to work at 1.65 Vcc. So it should be able to work in lower battery Vcc conditions than the Maxim. I will also hopefully be able to build it quite small and install it right on my ADAFRUIT Clock very nicely. The breadboard version I bugged onto the Kit board seems to be doing alright. None of this compensates for temperature, my room is an average between 72 to 79 degrees Fahrenheit, and that's where I achieved this accuracy. Most average temperature conditions will not produce the same kind of deviation a de tuned crystal will. I generally don't think in terms of parts per million, but a -.1 hertz deviation equates to a second loss about every 3.8 days. That's 1 minute 36 seconds a year. If I could get under a minute, worth the effort.

User avatar
jarchie
 
Posts: 615
Joined: Sun Jun 24, 2012 2:16 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by jarchie »

The tunable oscillator is a great hack. Of course, I can't resist making specific comments... but really, nice work Russell!

Russell 27 wrote:There is some great software compensation. But I find two deficiency's.
These deficiencies shouldn't apply to the drift correction method implemented in my xmas firmware. But if you've found a bug, please let me know! (More explanation follows.)

Russell 27 wrote:Also the correction factor may never be able to match exactly. [...] I have had success in fine tuning my original posted 2565 AUTODRIFT_CONSTANT to 2100 [...]
With the xmas firmware, you should be able to set the drift correction as accurately as you could reasonably want. Consider your configuration: With a correction factor of 2100, the clock will make a 1/128 second correction every 2100 seconds. Over the course of a year, time will be corrected by 117.32 seconds. Increasing the correction factor by one will cause the clock to make a 1/128 second correction every 2101 seconds. That amounts to a correction of 117.27 seconds over the course of a year--a difference of only 0.06 seconds per year. That's around one millsecond per week--an order of magnitude more than the accuracy of oven controlled crystal oscillators!

Russell 27 wrote:[...] when in battery backup Atmega constantly goes in and out of sleep mode, and the program doesn't apply deviation correction during this time.
With the xmas firmware, drift correction is applied during sleep. The clock crystal frequency, 32768 Hz, is divided by 256 and used to advance timer2. Whenever timer2 matches the value stored in OCR2A, timer2 is reset to 0, and when timer2 has a value of 0, the once-per-second interrupt is triggered. Normally, the value of OCR2A is 127 (128 values, including zero). So the once-per-second interrupt is normally called every second (32768 Hz / 256 / 128 = 1 Hz).

Among other things, the once-per-second advances the time and sets OCR2A to 127--except when the clock needs to make a 1/128 second drift correction. In those cases, OCR2A is set to either 126 or 128 to make the next second faster or slower by 1/128 second. Even when the clock is sleeping, the once-per-second interrupt still wakes the clock each second to advance the time and set OCR2A.

Russell 27 wrote:A tuned oscillator may not rival GPS, but it's superior to software correction.
To me, it still seems like a matter of personal preference, as I get comparable results with software correction. But if you explain your testing methodology in detail, maybe we can figure out why our impressions are different.

Russell 27 wrote:Two advantages of the tuned oscillator circuit over the Maxim time chip are; a tunable frequency and I ordered an SMD Inverter (not) gate that is rated to work at 1.65 Vcc. So it should be able to work in lower battery Vcc conditions than the Maxim.
The tunable frequency solution is certainly an advantage over a DS32kHz without software drift correction. Extrapolating from the Energizer CR1220 datasheet, a clock with the DS32kHz will drop below the recommended voltage after using ~38 mAh of battery power. I'd expect your oscillator circuit to last for ~44 mAh.

A related advantage of your tunable oscillator over the DS32kHz is that the ATmega328p's brown-out detection circuit should kick in at ~1.8v, so the oscillator will function properly until the ATmega328p detects insufficient voltage and shuts down.

Russell 27 wrote:Either my source clock and clock deviate exactly the same, or it has this kind of accuracy.
It doesn't sound like you're using an atomic or GPS time reference. What is the accuracy of the reference?

Russell 27 wrote:I generally don't think in terms of parts per million, but a -.1 hertz deviation equates to a second loss about every 3.8 days. That's 1 minute 36 seconds a year. If I could get under a minute, worth the effort.
So that would be 0.1 Hz / 32768 Hz or 3ppm drift. Keep in mind that crystal speed changes over time; the AB38T datasheet gives a figure of plus or minus 3ppm (0.1 Hz) over the first year. One of the advantages of fully automatic software drift correction is that it will eventually adapt to crystal aging.

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

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by phild13 »

To answer the question does anyone else use John's REVD firmware drift correction.
Yes I do and find it pretty accurate.

I understand the quest to make the clock as accurate as possible and it's a good exercise in learning more about the clock hardware and firmware.

To more fully answer the question. I have an Adafruit clock with 10 pf (+- 0.5pf) caps on the crystal and I have a REVD board with 10 pf (+- 0.5pf) caps from John of his design that I also use the temp compensation with. One other board I have is similar to Adafruits design, but with a board layout change (which is not necessary for his mod for others reading) work with Russell's recommended transistor and it also has the 10pf (+- 0.5pf) caps. All have a Atmega 328p and use John's firmware. I have been using John's defaults in the firmware and once I understood how the firmware was supposed to work in keeping time accurate, I would say that they all keep good time and probably better than many clocks you can buy commercially. I also have the temp compensation enabled on the REVD board which may help some. I could probably gain some additional accuracy if I wanted to spend the time, but I think the default settings are good for most to realize reasonably good accuracy.

Earlier I reported the REVD clock ran fast then ran slow after adjustments. I think some of this was due to my not understanding what the firmware was doing and how to properly set the time so the correction would work.

User avatar
jarchie
 
Posts: 615
Joined: Sun Jun 24, 2012 2:16 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by jarchie »

jarchie wrote:
Russell 27 wrote:A tuned oscillator may not rival GPS, but it's superior to software correction.
...I get comparable results with software correction. But if you explain your testing methodology in detail, maybe we can figure out why our impressions are different
Maybe it will help if I explain my testing methodology for short tests of the automatic drift correction, like the one I did for this post.
  1. Compile the xmas firmware and program the clock as described in the firmware/README file. The essential part is to program both the FLASH and EEPROM and ensure that both the FLASH and EEPROM are from the same firmware build. Since the test takes weeks, ensure the chip is correctly programmed with the optional final verification step described in the firmware/README file.
  2. Set the time as accurately as possible with an atomic-synchronized clock. I use a WVVB-synchronized wall clock. (WVVB is a radio station broadcasting time from an atomic clock in Colorado.)
  3. Wait for the longer of (a) one week or (b) until the time is wrong by more than fifteen seconds. The fully automatic drift correction is only intended to correct about 100 ppm of time drift (8 seconds per day). If time drifts by more than that, abort the test and fix the oscillator.
  4. Correct the time as accurately as possible with an atomic-synchronized clock.
  5. Wait for at least one week.
  6. Compare the time to the atomic-synchronized clock to judge accuracy.
With this test method, you should expect to get an accuracy within 3ppm (2 seconds per week). For better accuracy, wait longer than one week in the calibration step (step 3 above). I hope Phil will correct me if I'm wrong--or oversimplifying here--but the secret to getting highly accurate drift correction with the fully automatic algorithm is to set the time as accurately as possible.
PhilD13 wrote:I also have the temp compensation enabled on the REVD board which may help some.
I suspect that the effect of software-based temperature compensation is barely noticeable. In a typical living area, the day-to-day temperature is fairly consistent, and I'd expect improvement to be less than 1-3 ppm (1/2-2 seconds per week). Even in a garage or other area without climate control, I would expect improvement to be less than 5-10 ppm (3-6 seconds per week). I can, of course, think of contrived scenarios where the improvement from temperature compensation would be much more significant, but I don't think those scenarios are realistic.

In my experience, an unmodified Adafruit clock typically runs slow by around 35 ppm (21 seconds per week), so when compared to systematic time error, the single-digit ppm improvements from software-based temperature compensation is quite small.

User avatar
russell 27
 
Posts: 242
Joined: Thu Sep 12, 2013 3:59 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by russell 27 »

The automatic deviation correction would never do better than +2 to +2.5 seconds a day for me, no matter how many times I reset. I don't want to wait for weeks for accuracy to set in anyway. You are a software person, if you think this is a better way to go about it, by all means. Hardware does all the work, Id rather approach it that way. You told me once my eeprom was corrupted, it worked the same with your files. This is why I had interest in others who had used the software correction. I don't really want to argue about it. I really hoped this would encourage others to try tuning the crystal, unfortunately not the case. Also, the clock I built with your board does deviate time if I leave it unplugged for a day, My external oscillator clock did not.

User avatar
jarchie
 
Posts: 615
Joined: Sun Jun 24, 2012 2:16 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by jarchie »

I honestly think that your tunable oscillator is a nice bit of work. It's accurate and a significant contribution to the community. I also agree that making the hardware as accurate as possible is a more elegant solution than software correction.

My only significant criticism was with the comparison to software drift correction. To make a fair comparison, I think it is necessary to figure out why automatic drift correction is not working under your test conditions. If the reason turns out to be a problem with the automatic drift correction, there may be good reason to believe that the hardware solution is superior. But if the reason turns out to be a problem with the testing methods, then the testing methods need to be fixed before a fair comparison can be made. I firmly believe that it is impossible to reasonably claim either method to be superior without first doing a fair comparison.

But I also believe that your tunable oscillator is an accurate and reasonable alternative to software drift correction. Some people will, no doubt, prefer the elegance of a hardware solution to software correction. It's good work, Russell.

User avatar
russell 27
 
Posts: 242
Joined: Thu Sep 12, 2013 3:59 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by russell 27 »

My bad here. All I wanted to do was offer another way to tune your clock, mines been tuned. Go with the software

User avatar
jarchie
 
Posts: 615
Joined: Sun Jun 24, 2012 2:16 pm

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by jarchie »

Russell 27 wrote:My bad here. All I wanted to do was offer another way to tune your clock, mines been tuned. Go with the software
Maybe I'm being too sensitive here, but it seems like you believe that I'm criticizing your hardware solution. That is not my intent!

A hardware tunable oscillator is a good solution, and some people will, no doubt, want to go that route.

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

Re: TUNE your Ice Tube CRYSTAL: HARDWARE or J. Archie softwa

Post by phild13 »

Russell,
I'm thinking of trying a couple different things.

First I am thinking of trying a couple of 8pf caps for C8 and C9 in one clock to see how they work and if time accuracy is better or worse than the 10 pf caps I use now.

Second, while I realize you designed a separate oscillator circuit, (which your connecting to Pin 9?) but can C8 be replaced by a 2 terminal trimmer that will more or less fit in place even if this means it has to be installed on the board bottom? I have not found any through hole with less than 5mm lead spacing and current lead spacing on the board for C8 and C9 is about 2.4mm. Maybe a surface mount could be squeezed on the bottom? Provided something can be found to squeeze in, would that work to fine tune the clock if the other cap is left at 10pf?

Do you know of any trimmers that would be suitable in the application? I think there may be enough room to slightly offset a surface mount trimmer towards the battery holder if it is installed on the board bottom and get it to work.


John,
You generally say that your firmware initially needs to be kick started in order to begin to work for drift correction and this is done by the user making a manual correction after a period of time of about a week or two or after greater than a 15 second difference is noted. Is it possible to kick start the drift correction automatically by something along the lines of the following?
Since seconds per hour is probably way too granular for accurate time keeping adjustment, how about ticks in an hour (3600 * 128 = 460800).

Let the clock stabilize in operational temp for a period of time doing a loop until 6 hours is reached,
then record the ticks in the next (7th) hour,
then record the ticks in the next (8th) hour and compare to the first hour,
make an initial adjustment fast or slow based on the difference,
now software is kick started after 8 hours to auto correct,
proceed with the normal auto correction.

This is probably more accurate than someone manually making a time correction. I can only get two clocks to within about a quarter to half second of each other and the time base when manually setting them or initially correcting time.

At any rate, these clocks when C8 and C9 are changed to 10pf or an external circuit is used, and/or software correction is used tend to be more accurate than some commercial clocks are, especially during a power outage. I have one clock that during a 2 hour outage the other night gained 9 minutes. At least it did not loose 9 minutes.

Give it some thought.

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”