XMEGA RTC external crystal, running too fast [solved]

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

Hello fellow freaks

I am using the ATXMEGA256A3U RTC, with a 32kHz crystal, part number ST3215SB32768B0HPWB3.

The main specs of the crystal:
Nominal Frequency: 32768Hz
Load Capacitance: 6pF
ESR: 60kohm
Q-Value: 13000
Shunt capacitance: 0.6-1.2 pF

The main specs of the XMEGA RTC:
ESR Max (crystal load 6.5pF): 60kohm
CTOSC1: 4.2pF
CTOSC2: 4.3pF
Recommended safety factor - capacitance load matched to
crystal specification: 3 (what's this?)

The image below is the PCB, short traces and a ground plane below.

The RTC is running a little bit too fast. The time is gaining a few seconds a day.

I don't have load capacitors. In case I needed to add them, do I need an exact value or is there a range of capacitance that will make the oscillation exactly 32768Hz (+/- 20ppm).

Attachment(s): 

Last Edited: Tue. Nov 19, 2013 - 04:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you should put the capacitors on the board. You can also try adjusting the RTC.PER register.

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

What frequency are you getting and what are you using to measure it?

A few seconds a day is a bit high but depending on the temperature of the environment might not be too far off what you would expect.

For what it's worth I implemented a temperature compensation system for my xtal and it is now better than 0.3 seconds/day, but drifts by a second or more during the day. I correct at midnight so at 23:59 it could be 2 seconds out or something.

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

Oh, and one other thing, your PER register needs to be 1 less than your 2^ cycles per second. For example if you have 1024 cycles/sec the PER register needs to be 1023.

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

mojo-chan wrote:
Oh, and one other thing, your PER register needs to be 1 less than your 2^ cycles per second. For example if you have 1024 cycles/sec the PER register needs to be 1023.

hehe

That extra count made mine count slow. Almost right on now, but I'm using the processor's clock for a time base.

The largest known prime number: 282589933-1

Without adult supervision.

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

I searched online and saw that I needed capacitors:

Ce = 2CL - Ci - Cs

I added 8pF capacitors and now the drift since yesterday is only about half a second, previously it was about 5 seconds.

But now I wonder if I could use 10pF (which I already have on the board), would it still be ok?

I'll test and report later...

mojo-chan: I would be interested in looking at your temperature compensation algorithm.

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

It's pretty simple. I record the temperature once an hour. Then at midnight I have a lookup table I made that matches the curve in the manufacturer's datasheet as best I could make it, and use that to adjust the period of one minute (to get resolution with only 1024 RTC cycles/second). Then I go back to the normal length minute.

Unfortunately I can't post code because it is proprietary (work), but there really isn't much too it. The hardest part was converting PPM to RTC cycles/minute which somehow confused me :-)

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

ganzziani wrote:

I added 8pF capacitors and now the drift since yesterday is only about half a second, previously it was about 5 seconds.

What is your goal? Are you trying to get good accuracy without individual calubration or do the individual calibration with capacitors? +-20 ppm is about +-2 seconds/day, thus you won't get more accurate than that without individual calibration, which is easy to do in software. If you do the individual calibration anyway, you don't need to be within +-20 ppm before calibration.

I have used Xmega without any crystal capacitors and without any temperature calibration using software calibration. The RTC has been less than one minute off when I set it to/from daylight saving time although it is outside thus in varying temperature.

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

That's impressive.

You calibrated it by letting it run for a long time, seeing how far it drifted, calculating the ppm and setting the ppm register?

The largest known prime number: 282589933-1

Without adult supervision.

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

I have a 4 Hz GPS in the system outputting very accurate time pulse and I can compare to that during the calibration and thus "long time" doesn't have to be that long (one night is enough). The GPS is off most of the time and I don't use it to correct the time.

I do the calibration by changing RTC.PER for one second once an hour. In this case I'm adding 136, thus 36.9 ppm.

I have done the same over 10 years ago with an AT908535 using just the 8 MHz CPU crystal and without a GPS. I think it was even more accurate, but it was always indoors.

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

GNSS (GPS, GLONASS, etc.) is one source of 1PPS.
Another is ELF time signal receivers, these are miserly on electrical power, and, IIRC, a better ppm spec.

"Dare to be naïve." - Buckminster Fuller

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

I use a calibrated 10MHz TCXO during PCB testing. I run the micro at 32MHz and use an event on pin change to clock a timer from the 10MHz input. I then use another event to first restart the timer when the RTC overflows, and then capture it on the next overflow.

Some simple maths then converts the captured timer value to the RTC PPM error, or more usefully the RTC error per minute/hour/day or whatever time period you wish to correct over.

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

Mine seems to run slow about 4 seconds a day. Of course, I've never left it running more than about 12 hours yet. Program isn't finished. Don't have a GPS receiver for reference.

The largest known prime number: 282589933-1

Without adult supervision.

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

Quote:

Mine seems to run slow about 4 seconds a day. Of course, I've never left it running more than about 12 hours yet.

4s/day is 2s/12hrs or 2s/43200s. That is 4.6e-5 or 46 ppm. That's about right for a crystal isn't it? They are usually about 50ppm.

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

Most watch crystals are 20PPM these days. Torby, can you do a one-time calibration and store the value somewhere? That's what I do, supply 10MHz from the test jig during factory testing.