FRDM-MKL25Z4 RTC

Note to self:

RTC

The MKL25Z4 has no oscillator for the RTC unless we want to run the whole shebang off 32.768 kHz miltiplied by the MCG settings.
This would mean no USB. So, we need to work around this. The chip does have an RC? oscillator which can be run at 4 MHz or 32.768 kHz. These are known as the fast and slow Internal Reference Clock (IRC). This may (I don't know yet) not be as bad as it sounds. The IRC is factory trimmed , has a compensation register and a hardware facility to auto-trim it using the (8 MHz) crystal.

In order to use the hardware RTC we need to: * Enable the slow IRC and direct it to the clock out pin (PTC3). * Use a jumper from the CLKOUT pin (PTC3) to the RTC_CLKIN pin (PTC1).

Then use the rtc_api to initialise the clock ( rtc_init() ), write the current date & time in seconds ( rtc_write(seconds ) and read it back ( rtc_read ),
Then cross our fingers, toes, eyes and knackers and see how we go.

Further investigation shows that the above strike-out text is incorrect for the mbed loader while still being true for the PEMicro loader. The mbed loader outputs a 32768 Hz signal to the PTC1/RTC_CLKIN pin. The K20 pin in question is routed to the K25 RTC_CLKIN pin via R24, a 0 ohm resister. For battery use this causes problems for me: R24 is too close to many other components for my tired old hands to remove.

Options

  • Detect when the board is powered by the button cell and enable the PTC3 output. Downside is that the two pins will conflict between the K20 being powered and detecting that fact and disabling the PTC3 pin.
  • Use a resister |(10k) between PTC3 and PTC1. This will allow the K20 to drive the RTC_CLKIN pint suitably and the K20 pin will not drive it when powered down. Downside is that the auto-trim facility will not be available when the K20 is powered (All power sources bar the button cell). I might be able to live with this. I will also need to change the compensation for each 32kHz source.
  • Run the whole board off the 5V to V input and bigger battery. Not an ideal solution.
  • Use the PEMicro loader. Implications are I would need to compile on mbed, save the file and use GCC's binutils to write a S19 file for the loader. A lot of mucking about and needs to be tested.
  • Use Martin Kotjal's instructions to make an Eclipse and GCC/G++ workspace.

Next Steps

  • Provide a function to get a tm-like structure representing a time difference in years, months, days, minutes and seconds. On second thought, just show when RTC was last set.
  • Provide a function to calculate the RTC compensation registers from a time difference in seconds and the error in seconds & write them to the registers.
  • Provide a function to use the MGC auto trim feature.
  • Since I do not have a frequency counter I will have to use over night or longer testing. So, I will need to find out how to enable low power states for the testing to determine the appropriate compensation settings.
  • Investigate clock settings & use lowest possible for data collection, calculations and writing to the SD card.


1 comment on FRDM-MKL25Z4 RTC:

23 Jul 2014

Pete I know this is an old question but the RTC will work correctly if you use 32KHz crystal and re-config the clock set up. I use this chip with a 32KHz crystal all the time now which gives good low power results in deep sleep and wake up modes with the added benefit of a crystal accurate RTC.

Check this link for modified clock set up and pinconfig Mbed-src library:

http://mbed.org/users/star297/code/KL25Z-32kHz-crystal-mbed-src-library/

The USB function will not work, but for most applications with is not a problem after debug, that of course depends on your application. This is intended for custom build boards rather than the FRDM board, however you can test your code on the FRDM board if you replace the crystal.

Please log in to post comments.