Task scheduling using calendar

sfross wrote on Wednesday, September 14, 2016:

Hi,

I was wondering what other community members would do or are doing for a application where a task in a RTOS that needs to fire at a given time or regular interval (e.g every hour starting at midnight).

I intend using Free RTOS on an EFM32GG to implemenet this feature.

I could find only one method after a goggle search. The task requests the calendar time, calculates the amount of time until it next needs fire and and the sleeps for this amount of time. It seems a bit in accurate, but since I have not tried it I suppose I cannot comment.

Applogies if I have posted this in the wrong place.

Thanks,

Ross

davedoors wrote on Thursday, September 15, 2016:

The accuracy of vTaskDelayUntil() depends on the accuracy of the crystal running the EFM. External crystals are extremely accurate. Low power internal crystals can be very inaccurate. The normal thing is to have a separate real time clock. The EFM probably has one built in. You can then check then trigger tasks from interrupts generated off the real time clock (easy) or use the real time clock to calibrate and adjust the rtos tick (harder).

sfross wrote on Friday, September 16, 2016:

Hi Dave,

Thanks for your reply, I realise now that I was a bit vague in my comment about accuracy. In the examples I have seen the RTOS uses the hardware counter and there is a software time used for the calendar. The reason for this seems to be that, if they share the counter, the RTOS does not like a wild change in hardware counter when the calendar is synchronised.

My concern, possibly invalid, the two counter system may give inaccuracy in timing.

In a super loop example the calculation of the minutes in the day is done at the begging of the loop and any state machine within the look and do something based on the modulus of the result of this calculation with a given interval.

In the RTOS world, I guess I was hoping for a mechanism where the RTOS is instructed to fire a task(s) or generate a semaphore to the task(s). The task(s) would wake up or run and go back to sleep until the next event.

Ross

richard_damon wrote on Friday, September 16, 2016:

I woud impement such a system using the RTOS clock to handle short term incremental timing (something needs to happen in 10 seconds), and some service running off that clock maintains the Time-of-Day clock, as well as the occational adjustments to correct the Time-of-Day. This service is then fires off the various requests for things at particular time marks.

jackfarmersedge wrote on Friday, September 16, 2016:

If your controller has an RTC with a calendar function then set it to interrupt on your preset time of day. The interrupt routine sets a flag to wake up the task. That’s how I do it on an STM32.