RTC Accuracy - possible noise

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

Hi everybody again.

I'm having some problems when using TIMER2 as a RTC module with a 32.768 khz crystal.

I already wrote some posts about configuration problems, but those were already solved.

The issue I have now is RTC accuracy.
I read a post, in the AVR forum, where they said that the xtal may need some calibration with external caps.
But the error I am getting is important.. about 1-2 seconds faster per hour.
I read somewhere that this is too big to be a capacity-matching problem, but a noise one.

It's strange since the AVR would sleep most of the time and only wake up every second to increment the "tick" counter.

I compared those ticks with the RTC in my PC, which wouldn't add 2 seconds in an hour! would it?

I correctly took care of the details about TIMER2 in async operation, as said in the datasheet.

To give some more info, I'm using a atmega644 and gcc.
I am 95% sure the code is not the problem,
any ideas?

Thanks in advance,

Carlos

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

I've been making some tests, and it seems that my PC's RTC goes a little slow.

here is a program I used to check that: ClockWatch - http://www.beaglesoft.com/

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

I adjusted the registry in my PC to synch its clock to nist every 4 hours rather than the default of once very day or two. With this, my PC and my "atomic" clock (Oregon Scientific) are always within 2-3 seconds of one another.

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

cbecker:
I can´t believ that the XTAL is that much off, so i think of other reasons:

are you sure you only wake up by the RTC and count up your counter.
Maybe other interrupts are enabled and you count up sometimes without a real RTC interrupt...

Klaus
********************************
Look at: www.megausb.de (German)
********************************

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

I am sure about the counting, since I tried to avoid getting into sleep mode and it's exactly the same.
About other interrupts, I checked it and it's not the problem.
It really looks as if it goes faster than it should, since a few minutes after power up I start to see something like 0.5 sec difference.

I haven't used external capacitors for the clock, since I thought the AVR had them inside. I am now thinking that could be the problem? I already tried 2 different XTALs for the RTC, and still the same.

On the other side, caps missing won't make such a big error, right?

Thanks a lot,

Carlos

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

I think the xtal NEEDS the capacitors.

But i don´t know if the AVR has them built in.

If the XTAL works (becuase of missing capacitors) not at it´s resonance freqency then unstable clock may result.
Noise may have bigger influence then.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

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

Oh I see.
I used no caps because I saw an Atmel Appnote where no caps where used. Maybe because the part used included them inside.. I haven't found much info about that in atmega644's datasheet.

Thanks, I'll buy some 6pf, 12pf and try, since I couldn't find the XTAL's datasheet.

Thanks again,
Carlos

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

You are aware that the crystal is temperature sensitive yes? Not sure what accuracy you are shooting for but the capacitors will have to be different at different temperatures.

Go electric!
Happy electric car owner / builder

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

Yes I know.
I don't need a lot of precision, but particularly 2 seconds per hour is a lot of error!

I'll see if I can fix it with external caps. thanks

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

Well it's working now. Solved it with 20pF caps.
It gets a really good accuracy, an error about 1 sec per 12 hours.

thanks to everyone!

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

1 second per 12 hours is around 23ppm,
or around 2 seconds a day,
or around 1 minute per month,
or around 12 minutes per year.

Quite good. Maybe you can get it even more accurate by fine tuning the crystal capacitors? Sometimes RTC circuits have tunable variable capacitors there for manual fine tuning.

- Jani

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

yes, I did the math too :) quite small error!

About the calibration, maybe I should try and buy some variable caps, but since temperature also introduces som error, I wouldn't mind the 12 min/year.

When adding the capacitors, I tried first with 10pF caps, but was still fast, like 1sec/3hr. Then I put 20pF and now it is -1sec/12hours (it's running slower than it should, but smaller error than before). I think 18pF should do fine. Anyway, as I said before, I can cope with the current error.

Thanks for the info Jani, and thanks everybody too.

Carlos

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

cbecker wrote:
yes, I did the math too :) quite small error!

About the calibration, maybe I should try and buy some variable caps, but since temperature also introduces som error, I wouldn't mind the 12 min/year.Carlos

If you can cope with the current error, then skip the variable cap's. You're better off buying a more precise xtal instead.

For at least some avr's you can program the fuses so that the 32khz clock is output on one of the port pins. You can then use that to measure the xtal frequency with a frequency counter.

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

What I have done once is update the Timer once a day on a calibration value that I have in eerom, this will reduce the tuning by hardware.
And make it possible for production, the only thing is that you have to get a good reference wave to time the Cristal, and measuring the crystal it self will disrupt you measurement.
But an output compare and a divider will do the trick,
And then the next problem to overcome is the calibration of the measuring device.
And then your problems are not totally solved, as the Cristal will difference depending of the temperature.

One way to resolve this is be preheating the crystal and keeping it at that hi temperature.
But I have never used it, but you will find this in some frequency counter.
An other way is to have the temperature curve in the calibration table but that is not so repayable I think.