Author Topic: RTC initialization  (Read 8879 times)

Offline Richard

  • Newbie
  • *
  • Posts: 44
    • View Profile
RTC initialization
« on: March 24, 2009, 07:23:15 PM »
When I tried to use the RTC, I found that the one-minute interrupt occurred every 12 seconds.  Changing the value stored in the Real Time Clock Divide Register from
    MCF_CLOCK_RTCDR = (OSCCLK-1);
to
    MCF_CLOCK_RTCDR = (CRYSTAL_FREQ-1);
when I initialized the RTC fixed the problem.

I don't understand the theory behind the problem and its solution, since the manual clearly says that the RTC gets its 1 Hz frequency by dividing the oscillator clock by a factor of RTCDF+1, but empirically, I needed the crystal frequency -- at least that's what the macro names imply.

I should point out that I'm using my own board, not one of the Freescale (Axiom) DEMO boards, and maybe the difference is to be found there.

Best regards,
    Richard
« Last Edit: March 24, 2009, 09:57:41 PM by Richard »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: RTC initialization
« Reply #1 on: March 25, 2009, 02:27:55 PM »
Hi Richard

Thanks for this input. You are correct that this change is necessary in the latest version.

I check into the history of the RTC use, which was introduced in SP5. Initially it was in fact correct since OSCCLK was fixed at 25000000.
In later versions a more flexible PLL set up was added and the crystal stepped was introduced and the OSCCLK became equal to the PLL input, which is generally a pre-divided version of the crystal input frequency. The pre-divide value is fixed to 5 on the M52233 as you were testing on and so the 1Hz signal was no longer 1Hz but 5Hz!!

I have made this correction in the master copy. The correction is also valid in all SPs from (and including) SP7 when the PLL is used and the RTC is not driven from 32kHz (which is possible in some devices).

Thanks again.

Regards

Mark