LED Timing Issue in Timer Peripheral Example when Adjusting time_ms Value

Hi,

I am currently developing a project using the nRF52810 as my controller, with SEGGER Embedded Studio (version 5.42a) and SDK version 17.0.2 as my development environment. During the development phase, I am testing the timer peripheral example project from the directory nRF5_SDK_17.0.2_d674dde\examples\peripheral\timer\pca10040\blank\ses. I flashed the code onto the nRF52832 PCA10040 development board, and the four LEDs on the board turn on and off based on the time_ms value.

The issue is that when I change the time_ms value from 1000 (1 second) to 300000 (5 minutes), the LED indications are incorrect. The LEDs turn on and off within 30 seconds instead of 5 minutes. However, when I change the time_ms value to up to 4 minutes, the LEDs behave as expected, with the correct 4-minute delay. What could be causing this issue?

Studio version 5.42a

SDK: nRF5 SDK 17.0.2

Parents
  • Hi,

    When I test your code I get an assert at line 708 in modules/nrfx/hal/nrf_timer.h, which is because the number of ticks calculated from 300000 us is higher than UINT32_MAX (it does not fit in a 32 bit variable). You could solve this by changing the prescaler value so that the timer frequency is lower. For instance, add this line right before the call to  nrf_drv_timer_init():

    timer_cfg.frequency = NRF_TIMER_FREQ_125kHz;

    As you did not get this I assume you have disabled asserts? In that case, it is expected that you see the LED toggling at the wrong frequency, as the number of ticks overflowex the 32 bit, so the upper bits (above 32 bit) disappeared, so the number that is being used is lower than what you intended.

  • Thanks a lot for the valuable response. I understand the mistake and have changed timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz; before the nrf_drv_timer_init, and I am now able to increase the timer value. The LED indicates as per the given timer values. Currently, I am configuring the frequency to the minimum, which is 31250 Hz. Is there any need to modify it to 125 kHz ?.

Reply Children
Related