Author Topic: Kinetis RTC support  (Read 5898 times)

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3060
    • View Profile
    • uTasker
Kinetis RTC support
« on: August 01, 2011, 02:16:26 AM »
Hi All

During the new Kinetis K40 work, where the SLCD demonstration needed a clock display, it was time to add RTC support.

The RTC in the Kinetis is low power (typically 550nA), takes its supply from a battery input between 1.71V and 3.6V and uses a dedicated 32kHz oscillator. It is however also quite basic, essentially offering a counter running at 32kHz and an overflow counter running at 1s. This seconds counter is what is used as time base.

Although it is possible to use the RTC to generate a 1Hz output signal, the K40 and K60 don't have a 1Hz interrupt. For this reason, the new RTC driver uses the alarm match registers to generate an interrupt every second, which is practically the same as generating a 1Hz interrupt but with the loss of the capability to generate a single alarm interrupt at some future general point in time.

A 1s counter is the base of time but is not that practical when it comes to time and date itself. Therefore it was decided to essentially use the RTC interface from the M522XX project (this RTC supports various interrupts and has registers holding seconds, minutes, hours, etc.) but slightly expand on it to bring the interface's time/date features up to the level of a good RTC. This means that the driver actually manages the time and date based on the RTC seconds, allowing the user to simply request time and date inclucing year, month, day of month, day of week, hour, minutes and second. This essentially meant that the driver operates with its own time and date and perform all necessary conversions between these and the RTC's seconds counter, including Gergorian calender support.

This generally seems a good idea in order to standardise the RTC interfaces, whether the RTC hardware behind it is intelligent enought to do this itself or as simple as the Kinetis one.

The demo project thus has the following define to enable RTC support [#define SUPPORT_RTC]. When enabled, the command line menu is extended with the administrator menu commands "set_time xx:yy:zz" and "set_date xx:yy:zzzz" which can be used to prime tiem and/or date.
When the application task starts it collects the present time/date from the RTC and will also start the RTC if it wasn't previously operating (note that the 32kHz oscillator requires a 1s stabilising delay when this takes place, which is also managed).

With a K40 and SLCD display, the time is then displayed (Tower Boards as 12 hours clock with AM/PM and Kwikstick as 24 hour digital clock) .

Regards

Mark