RTC problem in TWR-MCF52259 and MQX

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTC problem in TWR-MCF52259 and MQX

1,040 Views
Victor125
Contributor I

As I described in subject, I found an strange issue running a simple test application with RTC and a ISR every minute. I got the example program of RTC (MQX example) and I modified to just print the time every minute using ISR of RTC. I have noted that every 24h the RTC has a deviation of about 14 seconds in relation an external control watch.

 

Anyone can help me? Is it normal in this RTC? So what's the solution if I want to program a clock with calendar? Must I use another external RTC?

 

I use MQX 3.6 with CW v7.2 for Coldfire and TWR-MCF52259.

 

Regards,

Victor

Labels (1)
0 Kudos
6 Replies

568 Views
mjbcswitzerland
Specialist V

Hi Victor

 

Maybe the 32kHz oscillator is inaccurate - when its loading capacitors are not correctly matched there can be a drift of several seconds a day.

 

If the clock is too fast adding some extra capacitance will slow it; if it is too slow, removing some will speed it up. It may be possible to tune it to run more accurately - about +/- 5 minutes a year can be typically achieved with RTCs (internal or external).

 

Regards

 

Mark

 

0 Kudos

569 Views
Victor125
Contributor I

 

Hi Mark, thank you for you answer.

 

But bad adjustment is possible even in evaluation boards?

 

Regards,

Victor

0 Kudos

569 Views
mjbcswitzerland
Specialist V

Hi Victor

 

Probably bad adjustment is more likely on an evaluation board - when building your own board is is very important to ensure that things match (stray capacitance will be different from one layout to another and can also be affected by the distance to metal housing etc.). Therefore one adjusts it as best as possible so that delivered units meet the expectations (if not it may be necessary to recall boards, which becomes very expensive).

 

An evaluation board is not really a product in that respect that needs to meets such a requirement because it will be played around with by the users anyway and probably has a bunch of wires soldered to it to be able to measure signals as well. Therefore the capacitor values used were probably those recommended for the crystal under typical conditions without any big thought as to whether they are optimal for the board.

 

This has nothing to do with freescale boards, but I did use an evaluation board with a RTC which worked well on my wooden desk. Two of these boards were used in production test equipment and also used to automatically program the time and date to production boards with their own RTC. The RTC on the eval boards also had RTC clock calibration support which was used to get the drift down to a very low level. However, the boards were positioned on a metal surface at a distance of about 2cm to the board's surface (and the crystal). The big surprise was that the RTC was then hugely inaccurate - many minutes in a day!! Increasing the distance from the metal surface to 5cm made it accurate again. To remove this sensitive dependency to the metal surface the original crystals were removed and new ones soldered directly to the RTC oscillator pins - after that it was possible to lay the board right flat on the metal surface (with something insulating of course) with no negative effects.

 

In another case (again not freescale) a design was made with a RTC with the 32kHz crystal and the standard capacitances as recommended by the crystal manufacturer. The accuracy was not good and so had to be modified with a large deviation from the recommended/typical values; in the data sheet to the processor with the RTC there was in fact a note with recommended capacitance values for standard crystals and these were also very different - they did match better with the practically defined values - and made it obvious that the RTC oscillator circuitry in the processor was not using the crystal at it standard oscillation mode.

 

Therefore I don't expect eval boards to be optimised in respect to such things - there are more a (useful) starting point rather than a perfect design.

 

Regards

 

Mark

 

0 Kudos

569 Views
TomE
Specialist II

That was both educational and enthralling, Mark!

 

Crystal oscillators are something we treat as a "black box" and just hope they work. Sometimes that's good enough, sometimes not.

 

I've worked on a design for a clock that needed to keep time within 1 second per day at 20C and within 4 seconds per day between -30C and 65C. That's 11 ppm and 44 ppm respectively.

 

Crystals are typically specified with a manufacturing tolerance of 30-50ppm and a temperature sensitivity depending on the specific angle of cut. The circuit board, microprocessor and capacitors are going to have manufacturing tolerances as well, adding up to the same order of variation. The crystals also change their specs a little as they age.

 

So on the production line we had an Agilent Function Generator calibrated to 1 ppm and periodically sent off for certification. It generated a 1Hz reference signal that was fed into a timer pin on the micro. It measured the period of that signal to better than 0.5ppm, calculated a correction factor and stored that in its EEPROM. About once per second it would add that correction factor to the calculated time, as well as adding in a cubic correction factor derived from an on-board temperature sensor.

 

If you find you really need to know how these things work, start here:

 

http://www.ieee-uffc.org/frequency_control/teaching.asp

 

Especially, starting at page 664:

 

http://www.ieee-uffc.org/frequency_control/teaching/pdf/fcdevices.pdf

 

Tom

 

 

0 Kudos

569 Views
mjbcswitzerland
Specialist V

HI Tom

 

Yes, time keeping is quite a complicated subject when it needs to be more accurate than the simple throw in a crystal and hope that it works approcach :smileywink:

 

I have an old Marconi spectrum analyser with high impedance probe. The instrument can measure down to quite low frequencies and can just detect the 32kHz oscillation from the quarz when positioned close to it, making verifications quite easy. Some processors (like NXP) have a special clock output pin that can be internally attached to various clock sources, including the 32kHz RTC oscillator, and thus allows unintrusive frequency measurements (nice square wave output for calibration purposes) with frequency measurement equipment - their RTC prescaler also includes a calibration value (needs to be stored in non-volatile memory) which effectively skips or adds clocks to each 1Hz period to allow for adjustments as you do.

 

As you probably know, when much higher accuracy is needed the crystals are put into a temperature controlled oven to keep them at a constant temperature to avoid the need for compensating over termperature ranges. It takes some time to get to the operating temperature though - and doesn't really fit well in low power embedded applications... :smileywink:

 

Regards

 

Mark

 

0 Kudos

569 Views
Victor125
Contributor I

 

Thanks a lot for your explanations. Now I can relax about this problem in my firmware and I can make the application with this knowledge. The adjustment of the capacitors will be at the final board.

 

Regards,

Victor.

0 Kudos