Task Switching Does Not Work As I Believed, timing problem

Hi all,

I have a problem in switching my tasks.

As I thought, every task has 37ms to work before it gets interrupted by the task-scheduler, who then activates the task with the highest priority or, if prioritys are all equal, the task which waits the longest time.
I am running 57 tasks. One of them should not have any breaks longer then 23ms.
But how to do. If I work with an endless loop. The task gets interrupted and several other tasks are executed. So the break will be much longer then 29ms.
Then I increased the priority of that task and only that task worked, no other.
To get other tasks working, I had to build in a 63ms 'task_wait'. But then, in spite of the high priority of that task, the break was as long as it was with the endless loop and the same priority like the other tasks.
I thought, I would leave the task with 'task_wait', an other task is executed and after 31ms(task_wait) the first task will be executed again because of its high prioriy. But that does not seem to be so.

Any solutions for my problem?

Thanks for all replies

Susi

Parents
  • You have 57 tasks. Don't you think that is quite a lot of tasks for an embedded system?

    What kind of work requires a pause of max 23ms? Is it buffering of input data or making a decision based on data received from an interrupt?

    Can you move part of your critical task to be done by the interrupt handler that now supplies it with it's decision data?

    You really should not have a "worker" thread that both need high priority and have enough work to run constantly since that means that you can't give it a higher priority without loosing 100% CPU capacity to that thread. A high-priority thread should be written so that it only wakes up on a trigger event, and then quickly performs it's work and goes to sleep again. That allows the remaining time to be distributed to lower-priority tasks.

Reply
  • You have 57 tasks. Don't you think that is quite a lot of tasks for an embedded system?

    What kind of work requires a pause of max 23ms? Is it buffering of input data or making a decision based on data received from an interrupt?

    Can you move part of your critical task to be done by the interrupt handler that now supplies it with it's decision data?

    You really should not have a "worker" thread that both need high priority and have enough work to run constantly since that means that you can't give it a higher priority without loosing 100% CPU capacity to that thread. A high-priority thread should be written so that it only wakes up on a trigger event, and then quickly performs it's work and goes to sleep again. That allows the remaining time to be distributed to lower-priority tasks.

Children
More questions in this forum