I have boiled a problem I am having down to something really simple - a function toggling a pin high and low very quickly.
If I do not use freeRTOS I get a continuous oscillation on the output pin, see photo.
However if I use the code below I get output on oscilloscope (1ms/div):
Approximately every 1ms, the pin does not toggle for around 1ms
Is this task’s priority set to zero? [Edit: I see you posted that code – yes, it is set to priority zero.] If so, did you define configIDLE_SHOULD_YIELD to zero?
Is the loop() function you posted relevant to your question?
Well that was easy. I thought that priority levels were just relative to each other but I guess it also sets how much the scheduler conducts the task. Much appreciated
No, not in the sense of an OS like Windows where a low priority task will get less time than a higher priority task if both are compute-bound.
Task Priority is STRICTLY observed, if a higher priority task is ready, it will be switched to at the earliest possible allowed instance (depending on things like is pre-emption allowed), and it will be given the CPU until it no longer needs it, or another task of higher priority (or equal if time-slicing is enabled) becomes ready.
There is one task that is ALWAYS ready to run, the idle task, as FreeRTOS doesn’t know how to ‘stop’ a CPU and make it do nothing, so has this idle task to use up any otherwise unneeded CPU time.
To add to Richard’s explanation, any tasks you put at priority zero are time sliced with the idle task. To prevent the idle task from taking an entire timeslice when another task is ready to run at priority zero, set configIDLE_SHOULD_YIELD to 1 (or don’t set it at all, which results in the default setting of 1).