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

[Strategy] Multiple Tasks (SoftDevice + Scheduler + App Timer)

Hello guys. I'm beginner in Nordic Devices.

I'm working in project that sends Acceleration Data from KX220 sensor over LoRa network or if there is a BLE device connected, my nRF52 (SDK 14.2) should stream the data over BLE.

The acceleration data is currently collected by TIMER1 + SAADC + PPI, but I want collect the acelleration sampling 5KHz with LFXTAL due the low power consuption.

For LoRa network, I'm using this port:

https://github.com/gluedig/nrf52-lora

I built a Custom Board with my peripherals, LoRa Radio, Accelerometer KX220 and the nRF52832 is my main CPU. So, the nrf52-lora uses RTC2 to control the LoRaMAC timer. Soft Device uses the RTC0 and app_timer uses RTC1.

In the current scenario i want to keep my device sleeping for a long period, like 30 minutes for example. But I dont known exactly how can I count these 30 minutes sleeping, because RTC0, RTC1 and RTC2 have been used for other purpourse.

My first idea is using the app_timer lib to create a new task event but I'm note sure how could I do this.

I followed this tutorial:

https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/application-timer-tutorial

I started to work with the ble_app_uart, this example uses the app_timer but this code doesnt follow the above steps for app_timer, I didn't understand very well how to use the app_timer with soft device. In the ble_app_uart we just see the following code:

// Initialize.
    err_code = app_timer_init();

In the ble_app_uart example there is not a app_timer callback like the tutorial, see the example bellow.

/**@brief Create timers.
 */
static void create_timers()
{
    ret_code_t err_code;

    // Create timers
    err_code = app_timer_create(&m_repeated_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                repeated_timer_handler);
    APP_ERROR_CHECK(err_code);
}

So I want to use app_timer to create tasks to wake up my device after sleep minutes and control a sampling process. Can i do this with app_timer ? Do I need to use the scheduler ? Which is the best strategy for this case ?

Parents
  • Hi,

    Can i do this with app_timer ?

    Yes, app_timer supports timeout_ticks up to the maximum length of a uint32_t variable. 30 minutes should correspond to 1 800 000 ms, or 58 982 400 ticks with the default prescaler. You can change the prescaler for app_timer in sdk_config.h to support event longer intervals:

    // <o> APP_TIMER_CONFIG_RTC_FREQUENCY  - Configure RTC prescaler.
     
    // <0=> 32768 Hz 
    // <1=> 16384 Hz 
    // <3=> 8192 Hz 
    // <7=> 4096 Hz 
    // <15=> 2048 Hz 
    // <31=> 1024 Hz 
    
    #ifndef APP_TIMER_CONFIG_RTC_FREQUENCY
    #define APP_TIMER_CONFIG_RTC_FREQUENCY 0
    #endif

    Do I need to use the scheduler ?

    That should not be required. Scheduler is typically used to execute tasks from interrupt handlers in main context, to make sure everything is handled in the correct order.

    Best regards,
    Jørgen

  • If you build the application in debug configuration mode (or with DEBUG flag set in preprocessor symbols), the exact function call/line number/error code should be output on the log. This will help with determining what is failing in your application.

    App_timer is a software timer implementation. It is not possible to use PPI with app_timer to trigger HW events. If you want to use RTC with PPI, you need to use another RTC instance and set this up manually (see for instance this example).

Reply Children
No Data
Related