random delay

I want to add a random delay in range 2000 to 3000 ms before my device perfrom any activity.

pls tell how can do this at earliest

usins some  timer or something else

  • Hakon i added:

    1). defined insatnce:  

    APP_TIMER_DEF(m_my_timer_instance);

    2). created a single shot timer in timers_init():

    err_code = app_timer_create(&m_my_timer_instance,
    APP_TIMER_MODE_SINGLE_SHOT,
    sensor_timer_handler);
    APP_ERROR_CHECK(err_code);

    3). now i am not getting how to use this shared by you:

    uint16_t rand_value;
    uint8_t bytes_available = 0;

    (void)sd_rand_application_bytes_available_get(&bytes_available);
    if (bytes_available >= sizeof(rand_value))
    {
    err_code = sd_rand_application_vector_get(&rand_value, sizeof(rand_value));
    APP_ERROR_CHECK(err_code);
    } else {
    /* implement your error handling if no rand bytes available */
    }

    err_code = app_timer_start(m_my_timer_instance, APP_TIMER_TICKS((rand_value % 1000) + 2000), NULL);

    as i dont know how to use it in handler, also i have to add this timer before timer used in line 357 of my code.

    pls hlp

  • Could you please explain what is the issue that you are seeing?

     

    Kind regards,

    Håkon

  • 1). in line 158: i have added

    APP_TIMER_DEF(m_my_timer_instance);

    2). in line 573: i have added

    err_code = app_timer_create(&m_my_timer_instance,
    APP_TIMER_MODE_SINGLE_SHOT,
    battery_level_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);

    3). i aim to add a random delay before the repeated timer of line 374 starts.

    as suggested by you: in line 357 i have added

    uint16_t rand_value;
    uint8_t bytes_available = 0;

    (void)sd_rand_application_bytes_available_get(&bytes_available);
    if (bytes_available >= sizeof(rand_value))
    {
    err_code = sd_rand_application_vector_get(&rand_value, sizeof(rand_value));
    APP_ERROR_CHECK(err_code);
    } else {
    /* implement your error handling if no rand bytes available */
    }

    err_code = app_timer_start(m_my_timer_instance, APP_TIMER_TICKS((rand_value % 1000) + 2000), NULL);
     

    4). i am getting error as shown in pic

    5). i am not able to add the random delay

Related