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?

Is there a timeout when using the timer? Or does it require any prescaler or timer bit width adjustments?

Your response is valuable.

Studio version 5.42a

SDK: nRF5 SDK 17.0.2

iam attaching the code for better understanding . 


#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_drv_timer.h"
#include "bsp.h"
#include "app_error.h"




const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);

/**
 * @brief Handler for timer events.
 */
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    static uint32_t i;
    int j=0;
    uint32_t led_to_invert = ((i++) % LEDS_NUMBER);

    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
            bsp_board_led_invert(led_to_invert);
            //nrf_gpio_pin_toggle(12);
            
            
            break;

        default:
            //Do nothing.
            break;
    }
}


/**
 * @brief Function for main application entry.
 */
int main(void)
{
    uint32_t time_ms = 300000; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    //Configure all leds on board.
    bsp_board_init(BSP_INIT_LEDS);
    //nrf_gpio_cfg_output(12);
    //nrf_gpio_cfg_output(11);

    //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);

    nrf_drv_timer_extended_compare(
         &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&TIMER_LED);

    while (1)
    {
        __WFI();
    }
}

/** @} */

Parents Reply Children
Related