Author Topic: Coldfire RTC Init Code  (Read 9994 times)

Offline dkg

  • Newbie
  • *
  • Posts: 48
    • View Profile
Coldfire RTC Init Code
« on: December 14, 2009, 10:23:03 PM »
Hi Mark,

We discovered a timing issue with when the RTC is initialize during power-up.

But first, I wanted to ask about the two writes to MCF_CLOCK_RTCCR. The reference manual shows an example where the difference between the two writes is that the first one does not include the RTCSEL_OSC bit. I was wondering why your init code has identical values for both writes to MCF_CLOCK_RTCCR. If there is a reason I would also like to know why then the register needs to be written to twice.

Now, on to the timing problem we have. Our board design uses a super-cap as the power source for Vstby. If the super-cap discharges below 1.8 volts, we lose the RTC and battery-backed SRAM as expected. Unfortunately, it take significant time to recharge the super-cap when power is applied to the board (up to 750mSecs). While the voltage is still below the 1.8v threshold, the init code for the RTC does nothing and that, unfortunately, is run well before the RTC is viable. So I figured I would create a task that is delayed a couple seconds after power-up which would just have those few instructions to initialize the RTC. Do you see any problem with that? Do you see a better solution for our situation?

Thanks,
Dave G.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Coldfire RTC Init Code
« Reply #1 on: December 15, 2009, 10:45:50 AM »
Hi Dave

I checked the MCF_CLOCK_RTCCR case but am not sure at the moment. I suspect that it would be better to follow the Freescale example and set the RTCSEL_OSC in the second write only. Whether there is any real difference (and thus whether the second write is necessary at all) is best confirmed by tests. I will give this a try and report back in a day or so.

On my demo board with super cap it can take several minutes until the RTC works (the first time powered up) so your HW is in fact quite fast. It is also know that the configuration will not work until the voltage is within the required range. If you are sure that a simple delay before initialisation is preformed is adequate then having a delayed task do this, or the initialisation controlled by a timer in any task should be acceptable.
To be more certain I would recommend also verifying that the initialisation was successful (checking that the second increments correctly or at least that the register's initialisation values can be read back successfully). If this is not the case then a further attempt can be made a couple of seconds later (and repeated until finally successful).

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Coldfire RTC Init Code
« Reply #2 on: December 20, 2009, 09:58:02 PM »
Hi Dave

I experimented with the two initialisation sequences on an M52259 and didn't actually notice any difference between the two. Possibly enabling the RTC before setting the RTCGOCL means that it may count a pulse (although probably it doesn't have time to do so) before the value is correctly configured, but I didn't actually see this happening.

I have modified the reference code to match the Freescale recommendation to be on the safe side since I couldn't otherwise explain why it should write the same value twice.

Regards

Mark