This page describes timing concepts and suggests timing libraries for this project.


(Image from Wikipedia.)


This project needs to read data from the accelerometer and microphone "simultaneously". It is important to have a precise understanding of when each data point was collected to get an accurate picture of acceleration and acoustic waves from our machinery. Therefore every data point will be timestamped, either in ticks or in actual seconds (ms or us), of how much time has passed since the last collection point.

There is also a need for delays in this code, however I have noticed that some delay-creating methods are incompatible with this sensor code, for example when used with interrupts.


Our highest-speed component will be the KX134-1211 accelerometer, which could have an ODR of up to 25600Hz. This would mean a period of ~39us. Therefore it would be really nice to have at least 2x this resolution (maybe even 3x or 4x) as our timing method to get accurate timestamps between measurements.

  • 2x —> 51200Hz
  • 3x —> 76800Hz
  • 4x —> 102400Hz

These mean that we need a high-frequency clock - LFXO won't cut it (see Clock Sources below).

We will also need to collect data for 1s, so it will be important to make sure that the rollover is higher than a second (if we choose not to reset the counter between readings in order to save precious nanoseconds).

Creating Delays

There are several kinds of delays you could use in Simplicity Studio 5 [1]:

  1. USTIMER_DelayIntSafe: Seems to be safe for threads and interrupts. Mags: I recommend this one, it seems to work great in my code.
  2. USTIMER_Delay: Not thread safe, does not play nice with other interrupts (Mags: I have seen this in my code, so I switched over to #1.)
  3. halCommonDelayMicroseconds: Internally uses USTIMER_DelayIntSafe() (not verified)
  4. usecDelay: Have only seen implemented in EFR32.
  5. UDELAY_Delay, coded in assembly language. Comments state that could only be delaying for 75% of intended value, and also not for values more than 1ms (1000 us).
  6. UTIL_TIMER_delay: in RAIL app utils. This seems to use a combination of TIMER0 and TIMER1.


Besides the methods listed below, I have seen suggestions for other methods of timestamping mentioned in the forums:

  • There is a mysterious halCommonGet-Int16uMillisecondTick() and halCommonGetInt32uMillisecondTick() duo of functions, however I don't think they're available for this board (can't find anything about them anywhere else) [2].

Real Time Clock (RTC)

This driver is deprecated in Series 2 devices. The manufacturer recommends using 'Sleeptimer' instead. [3]


Real Time Clock/Calendar (RTCC)

  • Hard to tell, but it looks like it will only work on LF sources [6, pg. 415] - this would mean maximum resolution of 30.5us.
  • Works up to EM3, the second-lowest energy mode.
  • In older models (EFR32xG1 and EFR32xG12) the BLE module needed exclusive use of the RTCC, however there were some ways you could get around this to use the RTCC functions. [4]
  • To get accurate timing in fluctuating temperatures, you may need to apply a transform to the clock frequency that takes the following form (not currently implemented): [5]
\begin{align} f = f_0[1 + \beta(T-T_0)^2] \end{align}

Back-up Real Time Clock (BURTC)

  • Can use LFXO, LFRCO, or ULFRC as the clock source. [6, pg 434]. Maximum resolution of 30.5us.
  • Works up to EM4, which is the lowest-possible energy mode (uses ULFRCO).
  • Silicon Labs Documentation for BURTC


  • Interestingly enough, so far it's the only peripheral I've seen that has an explicit "Tick" function in the library that can do milliseconds. I'm worried that ms is not going to be precise enough, although I have yet to try.
  • One of the following clock sources must be enabled before initializing the sleeptimer [8]:
    • LFXO: external crystal oscillator. Typically running at 32.768 kHz.
    • LFRCO: internal oscillator running at 32.768 kHz
    • ULFRCO: Ultra low-frequency oscillator running at 1.000 kHz
  • This means this also has a maximum resolution of 30.5us.

Timer (TIMER)

After all that: probably going to be the most useful going forward.

  • The default clock source is the 'Prescaled EM01GRPA clock', which is initialized to the HFXO. This clock is optimized for 38.4 MHz crystals [6 pg. 171], which would suggest that the period of ticks is 26ns.
  • There is some nice math provided by [14] if we ever want to change it from the fastest timer, but for now we'll leave it since we only want one second of data.

Low-Energy Timer (LETIMER)

Clock Sources

From [7]:

There are a maximum of seven oscillators that can be used as clock sources for different purposes. The SYSCLK is usually clocked by the HFXO, FSRCO or HFRCO, whereas low energy peripherals are usually clocked by the LFXO, LFRCO, or ULFRCO. The HFRCOEM231 is typically used for the low energy peripherals such as LETIMER.

Oscillator Frequency Range
HFXO 38-40 MHz
HFRCOEM23 1-38 MHz
LFXO 32768 Hz
LFRCO 32768 Hz
ULFRCO 1000 Hz

Clocks that have this effect are not available on the EFR32xG22.

Important Note about Bricking

When picking the oscillator for something like SYSCLK, the chosen oscillator HAS to be enabled first before it is selected or else all modules running that clock source will stop. Then the CPU will stop, and then the device has potentially entered an unrecoverable state.

See Also

1. Silicon Labs Community Forum Post; 2021; Various delay functions; https://www.silabs.com/community/mcu/32-bit/forum.topic.html/10_sec_delay_-BcH9
2. Silicon Labs Community Forum Post; How do you implement the timestamp function?; https://www.silabs.com/community/wireless/zigbee-and-thread/forum.topic.html/how_do_you_implement-T801
3. Simplicity Studio Software 5 Components Configurator
4. Silicon Labs Community Forum Postl; 2016; KBA_BT_0908: Using RTCC as Timer or Calendar while running BLE stack; https://www.silabs.com/community/wireless/bluetooth/knowledge-base.entry.html/2016/10/15/using_rtcc_as_timer-cFRe
5. Silicon Labs Community Forum Post; 2018; How to compensate the RTCC calendar due to crystal frequency deviation over temperature; https://www.silabs.com/community/mcu/32-bit/knowledge-base.entry.html/2018/06/27/how_to_compensateth-tZCd
6. Silicon Labs; EFR32xG22 Wireless Gecko Reference Manual; https://www.silabs.com/documents/public/reference-manuals/efr32xg22-rm.pdf
7. Silicon Labs Whitepaper; AN0004.2: EFR32 Series 2 Wireless MCU Clock Management Unit (CMU); https://www.silabs.com/documents/public/application-notes/an0004.2-efr32-series2-cmu.pdf
8. Simplicity Studio 5 Internal Documentation; Services —> Sleeptimer
9. David Lynch; Silicon Labs Community Blog Post; Chapter 7: Create a Sprinkler Timer Part 1 – Interface the On-board LCD; https://www.silabs.com/community/blog.entry.html/2015/09/08/chapter_7_createa-FNtt
10. David Lynch; Silicon Labs Community Blog Post; Chapter 7: Sprinkler Timer Part 2 - Create the Timer Set/Adjust Mechanism; https://www.silabs.com/community/blog.entry.html/2015/09/18/chapter_7_sprinkler-MAJD
11. David Lynch; Silicon Labs Community Blog Post; Chapter 7: Sprinkler Timer Part 3: Real Time Clock (RTC); https://www.silabs.com/community/blog.entry.html/2015/10/01/chapter_7_sprinkler-iqHj
12. David Lunch; Silicon Labs Community Blog Post; Chapter 5 Clocking Part 1 — MCU Clocks and Introduction to Interrupts; https://www.silabs.com/community/blog.entry.html/2015/06/16/chapter_5_clockingp-g7dK
13. David Lunch; Silicon Labs Community Blog Post; Chapter 5 MCU Clocking Part 2 —The SysTick Interrupt; https://www.silabs.com/community/blog.entry.html/2015/06/29/chapter_5_mcu_clocki-pEjC
14. David Lunch; Silicon Labs Community Blog Post; Chapter 5: MCU Clocking Part 3 — Peripheral Clocking; https://www.silabs.com/community/blog.entry.html/2015/07/08/chapter_5_mcu_clock-NqdQ
15. David Lunch; Silicon Labs Community Blog Post; Chapter 5 Part 4 — Pulse Width Modulation (PWM) for LED Dimming; https://www.silabs.com/community/blog.entry.html/2015/07/17/chapter_5_part_4---WneD
16. David Lunch; Silicon Labs Community Blog Post; Chapter 5 MCU Clocking Part 5 — Fading Multiple LEDs at Once; https://www.silabs.com/community/blog.entry.html/2015/07/23/chapter_5_mcu_clocki-0atH
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License