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

Configuring a single shot timer to work as a delay

I have been trying to configure a single shot timer as a low power alternative to nrf_delay_ms(). 

I have my timeout handler configured to do nothing and the timer is created with a 100 ms interval. But whenever I call the timer , I get a "Fatal_error" on putty. 

Similar to this https://devzone.nordicsemi.com/f/nordic-q-a/6131/timer-handler-not-called but I don't have a app_timer_stop() like the above linked question. Can I use the __WFI() function even if I am using the softdevice?

I am using the nrf52832 with the s132 softdevice and I'm developing using the SDK version 12.2. I'm running out of ideas to make it work. 

P.S I work using armgcc and I really appreciate Nordic's creation of the makefile. I have finally configured Microsoft's VS Code for my use but the lack of a debugger is a big hinderance. I'd appreciate if Nordic updated the GCC with eclipse blog post or suggested some other IDE with a debugger for open source folks like me. 

Thanks for your help!

Vijay

Parents
  • You don't say which timer you are using, but for 100msec best to use RTC. Make sure you are not using RTC0. Both RTC0 and Timer0 are protected resources with SoftDevice.

    Yes, you can use __WFI with SD, but keep in mind the SD is constantly doing stuff so hard to predict when you'll come out of WFI/WFE. Most of the docs recommend you use power_manage.  Same functionally but lets the SD handle the process.

    However, if you want it to be simple just user app_timer.  Very easy to configure single shot timers and loads of examples in the devzone.  I think I even did one example a while back. Only took 4 lines of code.

    Here is a good example of app_timer: https://devzone.nordicsemi.com/f/nordic-q-a/34551/nrf51822-app-timer/132548#132548

  • It is an RTC based application timer. This is where I stand,

    err_code = app_timer_create(&m_writereg_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                timeout_handler);
    APP_ERROR_CHECK(err_code);
    and the timeout_handler is this,
    static void timeout_handler(void *p_context)
    {
        UNUSED_PARAMETER(p_context);
        
        \\Do nothing
    }
    When I start the timer like this,
    err_code = app_timer_start(m_writereg_timer_id, APP_TIMER_TICKS(500, 0), NULL);
    APP_ERROR_CHECK(err_code);
    I have a toggle led command before and after the app_timer_start function. I don't see the desired output.
    To be noted, this is to induce a delay when sampling data from a TWI sensor. I have another big app_timer which wraps around all of these..
    Like this,
    static void big_timer_timeout_handler()
    {
        nrf_drv_twi_tx() \\I2C write register ..
        app_timer_start() \\one shot timer to create the required delay
        nrf_drv_twi_rx() \\I2C read register..
        app_timer_start() \\one shot timer to create the delay
    }
    
    Thanks again!
  • Hi.

    If you want to add delay between your TX and RX, you should put the nrf_drw_twi_rx(); function in the callback for the timer (static void timeout_handler(void *p_context) function)

    The app_timer_start() is asynchronous function, which means that app_timer_start(); always returns immediately after being called independent of the given timeout.

    - Andreas

  • Andreas, thanks for your answer! It works!!

    Ambystoma labs, thanks for your input as well. Appreciate it..

Reply Children
No Data
Related