This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issue with TIMER in soft device S132

Dear Sir,

I  am new to Nordic. This is my first query. It is related to running Timer with softdevice. I am using TIMER1 ( as const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);)

I could run the application in the <SDK>\examples\peripheral\timer successfully. Here I have used  the  following

uint32_t time_ms = 1*60*1000;

This corresponds to 1 minute(60seconds).

It works fine without softdevice.

By actual code is along with softdevice. So I tried to use the same code there with the soft device.

Here I was expecting the  'timer_led_event_handler()' to be called every 1 minute(60 secoonds)

Here the  interrupt handler is getting called, but it is called at  faster rate ( not in every 1 minute). .

Is it some issue related to clock configuration?

Anyone , Please let me know what/where I went wrong?

Thank you.

Parents
  • : TIMER1 is not used by the softdevice or SDK. Application timer library use RTC1 as its timer source.

    : How did you configure the timer? How often is the timeout handler called? Which SDK version are you using? I would not recommend using a timer for 1 minute intervals, app_timer or RTC would be a better alternative, as it runs on lower frequency clock source, giving you lower accuracy but also much lower current consumption.

  • Dear Jørgen Holmefjord

    Thank you very much for your reply.

    I am using SDK version 15.0.0_a53641a.  Currently the time out handler is calling around  20 -30 times per second(it (the print statement) goes too fast  so exact value I could not get ).The timer I want to use for 5 minute. Just for checking I used  the value 1 minute. Actually I want to wake up the system every 5 minute and start advertising for say 1 minute. Then  go to sleep. Again after 5 minute start advertising...go on like this. So I am planning to call advertiing_start() function inside the handler, so that it will get called every 5 minute.

    I am copying the code( excluded the part not related to timer).

    Please correct me if I am wrong somewhere.

    #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(1);

    .......(some functions are there)

    void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
    static uint32_t i;
    uint32_t led_to_invert = 2;//((i++) % LEDS_NUMBER);

    switch (event_type)
    {
    case NRF_TIMER_EVENT_COMPARE1:
    NRF_LOG_INFO("Inside handler");
    break;

    default:
    //Do nothing.
    break;
    }
    }

    ............................

    ...............................

    int main(void)
    {


    bool erase_bonds;


    uint32_t time_ms = 1000*10; //Time(in miliseconds) between consecutive compare events.//GK added
    uint32_t err_code = NRF_SUCCESS;//GK added
    uint32_t time_ticks; //GK added

    // Initialize.
    log_init();
    timers_init();
    leds_init(&erase_bonds);//GK modified
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
    peer_manager_init();

    // Start execution.
    NRF_LOG_INFO("Sieva example started.");


    application_timers_start();


    advertising_start(erase_bonds);

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;//GK added for timer
    err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);//GK added  for timer
    APP_ERROR_CHECK(err_code);//GK added for timer

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms); //GK added for timer

    nrf_drv_timer_extended_compare(
    &TIMER_LED, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);//GK added for timer

    nrf_drv_timer_enable(&TIMER_LED);//GK added for timer

    // Enter main loop.
    for (;;)
    {
    idle_state_handle();
    }
    }

Reply
  • Dear Jørgen Holmefjord

    Thank you very much for your reply.

    I am using SDK version 15.0.0_a53641a.  Currently the time out handler is calling around  20 -30 times per second(it (the print statement) goes too fast  so exact value I could not get ).The timer I want to use for 5 minute. Just for checking I used  the value 1 minute. Actually I want to wake up the system every 5 minute and start advertising for say 1 minute. Then  go to sleep. Again after 5 minute start advertising...go on like this. So I am planning to call advertiing_start() function inside the handler, so that it will get called every 5 minute.

    I am copying the code( excluded the part not related to timer).

    Please correct me if I am wrong somewhere.

    #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(1);

    .......(some functions are there)

    void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
    static uint32_t i;
    uint32_t led_to_invert = 2;//((i++) % LEDS_NUMBER);

    switch (event_type)
    {
    case NRF_TIMER_EVENT_COMPARE1:
    NRF_LOG_INFO("Inside handler");
    break;

    default:
    //Do nothing.
    break;
    }
    }

    ............................

    ...............................

    int main(void)
    {


    bool erase_bonds;


    uint32_t time_ms = 1000*10; //Time(in miliseconds) between consecutive compare events.//GK added
    uint32_t err_code = NRF_SUCCESS;//GK added
    uint32_t time_ticks; //GK added

    // Initialize.
    log_init();
    timers_init();
    leds_init(&erase_bonds);//GK modified
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
    peer_manager_init();

    // Start execution.
    NRF_LOG_INFO("Sieva example started.");


    application_timers_start();


    advertising_start(erase_bonds);

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;//GK added for timer
    err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);//GK added  for timer
    APP_ERROR_CHECK(err_code);//GK added for timer

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms); //GK added for timer

    nrf_drv_timer_extended_compare(
    &TIMER_LED, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);//GK added for timer

    nrf_drv_timer_enable(&TIMER_LED);//GK added for timer

    // Enter main loop.
    for (;;)
    {
    idle_state_handle();
    }
    }

Children
No Data
Related