Delay between setting each variable

Hi

I have a case where I need to set the delay . The delay varies between 5-15 seconds . I am using STM32 . below is my code . I want to modify these variables when these delays expire . But I do not wan to block the task. How do I achieve this in FreeRTOS.

Any help appreciated

 void test_sequence(void) {
    if (complete) {
delay(5sec);
        enable           = true;
        delay(10sec);
        remote_setpoint         = 500;
delay(15sec);
        remote_setpoint_confirm = CONFIRM;
    }

Thanks

I would use a timer callback to set those variables at the point in the future.

See: FreeRTOS - RTOS software timer functionality and features description

Or use RTOS - xTaskCheckForTimeOut() (see the example code) to poll for timeouts if your task runs without waiting for something (forever).

Thanks Richard for responding. The software timers are static right ? Are you suggesting me to create 3 timers in this case (for 5,10 and 15 sec).

All I want to do is when 5 seconds expires set 1 st variable and when 10 secs expires set 2 nd variable and when 15 sec expires set 3rd variable

When you create a timer, you connect a subroutine that will be called when the timer expires to that timer. That timer can be used and reused as needed. You can change the timeout period for the timer (and make it auto-restart for periodic activation if desired).

In your case you could either create 3 separate timers, each that calls a function that sets the appropriate variable, or you could create 1 timer that calls a function that keeps track of what “step” it is on, setting the appropriate variable for that step, and then restarting the timer for when the next step should occur. Then when the condition occurs that you want to trigger them your start the timer(s) and things will happen when they expire.

Hi @rohinidr

Adding to what @richard-damon mentioned, To do it in a single function you can use auto-reload timers which gets periodic callback execution and set the auto reload timer period according to your use case which seems to be 5seconds here.

Please check more details here.