I now noticed that ulTaskNotifyTake does not return the value I thought it did. Is there no way to check if that function returned because of a notification or because of time-out?
I have now replaced it with xTaskNotifyWait, but get the same behavior:
Thank you. I did see this page, and the description of the return value: “pdTRUE if a notification was received, or a notification was already pending when xTaskNotifyWait() was called. pdFALSE if the call to xTaskNotifyWait() timed out before a notification was received.”
Do you see an error in how I call this function in my last code block?
I use this return value to know if the task was notified or time-out. But even when receiving periodical notifications (every 2 ms), I get an extra wake-up every 10 ms (the timeout value). So, one led_on(LED_YELLOW); every 2 ms, and an extra every 10 ms.
New data: if I change the time-out to 100 ms, I get the behavior that I expect.
After this discovery, I did a binary search, and came to the conclusion that time-outs < 20 ms give me the unexpected time-out event. Values >= 20 ms do not time-out unexpectedly.
When you have tick rate of 100 Hz, a tick fires every 10 ms. This means that the time granularity is 10 ms - in other words, you are asking your task to block for one tick. That block time can be anything between 0.01 ms to 9.99 ms depending on when the API is called between 2 tick interrupts. Increasing tick rate to 1000 Hz, increases the time granularity to 1 ms which is what fixes your application.