Report
6 years, 1 month ago.

mbed RTC crystal frequency 32kHz or 32.768kHz

While checking cmsis_LPC1768_system_LPC17xx.c, i noticed the RTC crystal frequency is defined at 32kHz.

RTC_CLK define in cmsis_LPC1768_system_LPC17xx.c

/*----------------------------------------------------------------------------
  Define clocks
 *----------------------------------------------------------------------------*/
#define XTAL        (12000000UL)        /* Oscillator frequency               */
#define OSC_CLK     (      XTAL)        /* Main oscillator frequency          */
#define RTC_CLK     (   32000UL)        /* RTC oscillator frequency           */
#define IRC_OSC     ( 4000000UL)        /* Internal RC oscillator frequency   */

The mbed schematic indicates a FC-135 crystal (orderable frequency range from 32kHz to 77.5kHz - datasheet at http://www.epsondevice.com/docs/qd/en/DownloadServlet?id=ID000805). Since no real mbed partlist is available, i dug a little further and according to http://mbed.org/forum/mbed/topic/1110/?page=1#comment-18202, the mbed uses a 32.768kHz crystal.

Which one is correct?

Comment on this question

2 Answers

6 years, 1 month ago.

Actually yes, the definition is wrong in the system_LPC17xx.c in the mbed version. In other versions of the system_LPC17xx.c file, which one may find in several NXP AppNotes, the RTC_CLK is correctly defined as 32768. But actually this 'bug' will only affect the calculation of the SystemCoreClock, if the RTC Crystal is used as a low power Main Clock Crystal (and fed into PLL0).

For the 'normal' operation of the RTC itself this RTC_CLK definition has no impact, as the RTC-Block of the LPC1768 has a fixed RTC-oscillator and 2^15 divider connection scheme and operates with correct timings as long as there is physically a 32768 Hz Crystal connected to the RTC Crystal Pins, no matter what is defined in system_LPC17xx.c

But of course it would be nicer, if the definition was spot on too.

Regards
Neni

6 years, 1 month ago.

the crystal frequency. is 32.768, although it is almost always documented as just 32kHz. but it is divided down, 2^15 so 1 hertz is the end result.

hope that was informing.

Ceri

I know it is divided down, but when we declare it as 32000 and divide by 2^15, we don't get 1Hz but 1.024Hz. The error on long delays is not really neglectable.

Edit: forgot to mention "if we use RTC_CLK as source for division".

posted by Frank Vannieuwkerke 24 Feb 2013

To post an answer, please log in.