Arduino style millis and basic example “Blink without delays“ with Silicon Laboratories Sleep Timer

2022-06-15 Silicon Labs
Thunderboard Sense 2 development board,BRD4166A,SILICON LABS

The main purpose of this application code example is to reproduce the Arduino-style millis function and "Blink without delays" sample code in the Silicon Labs Laboratories environment. The main logic is to check if the specified time interval has elapsed to run toggle logic. Subtraction of the actual value from the previous timestamp in the case of unsigned integers is handling the overflowing of the counters. The millis function in the Arduino environment will overflow for almost  49 days. Our solution is casting the systick sl_sleeptimer_get_tick_count  to milliseconds with function: sl_sleeptimer_tick_to_ms, so if the systick is overflowing, the current_millis values will start from 0. In this implementation with Thunderboard Sense 2, the overflow of the systick will occur every ~37 hours.

This usage of this function will be useful to measure time from milliseconds - to hours domain, like button push, sensor timing, etc.


How to set up the project
You need any kind of Silicon Labortiores development tool compatible with Simplicity Studio 5. For this example creation and testing, I have chosen a Thunderboard Sense 2 development board (BRD 4166A). To make some visible actions I have chosen to toggle a GPIO, which is fitted with a LED. In this case, if you check the user guide of the Thunderboard Sense 2 in chapter 3.5 Push Buttons and RG LED (page 17) details, that the red led is connected to PD8.  In the app. c the GPIO definition, that PD8 gpioPortD, 8.


In the case of another board, check the part's datasheet. Connect your development board to your computer and open Simplicity Studio 5. From the "launcher" perspective choose the "Example projects & demos" menu point,  and create an "Empty C Project"  for your kit.

1. Open your project's .slcp file
2. Add the following component:  
Software Components tab  Services / Sleep timer
3. Paste the attached code to your project's app. c file.
4. Build the project (hammer icon).
5. Flash: right-click on the project's .hex file under the "Binaries" folder, choose the "Flash to device..." point, and in the "Flash Programmer" window click to "program" button.

After flashing your board, the led will toggle every second. If you have a problem with flashing, it is possible, that you have a missing bootloader.

Used HW and SW
Thunderboard Sense 2 development board ( BRD4166A Rev 01), Simplicity Studio 5 with Gecko SDK Suite: Amazon, Bluetooth 3.3.0, Bluetooth Mesh 2.2.0, EmberZNet 7.0.0.0, Flex 3.3.0.0, HomeKit 1.1.0.0, MCU 6.2.0.0, Micrium OS Kernel, OpenThread 2.0.0.0 (GitHub-9dedd1869), Platform 4.0.0.0, USB 1.0.0.0, Wi-SUN 1.2.0.0, Z-Wave SDK 7.17.0.0.

  • +1 Like
  • Add to Favorites

Recommend

This document is provided by Sekorm Platform for VIP exclusive service. The copyright is owned by Sekorm. Without authorization, any medias, websites or individual are not allowed to reprint. When authorizing the reprint, the link of www.sekorm.com must be indicated.

Contact Us

Email: