vTaskDelay inaccurate (IDFGH-6964)
c - ESP IDF: Task never leaves vTaskDelay() - Stack Overflow
Task watchdog got triggered - it is fixed with a vTaskDelay of 10ms but is this a bug? (IDFGH-5818)
Better Explanation for vTaskDelay (FreeRTOS) ?
vTaskDelay is basically the same as Arduino delay() But if I remember correctly you have to divide it by the ticks per millisecond See the ESP documentation you can search for vTaskDelay and you'll see a number of results
More on reddit.comHello,
I am currently working on a project that uses FreeRTOS to create a bunch of tasks to do things. The code was written be a former student and I have to implement some stuff and make it run a bit smoother but I can't really understand the FreeRTOS part especially when it comes to Delays and TaskDelays or someone also told me about yields.
As an example I have 2 Tasks:
xTaskCreatePinnedToCore(
Task1code, /* Function to implement the task */
"Pubblish", /* Name of the task */
8192, /* Stack size in words */
NULL, /* Task input parameter */
1, /* Priority of the task */
&Task1, /* Task handle. */
1);
delay(100);
xTaskCreatePinnedToCore(
Task2Code, /* Function to implement the task */
"Sensors", /* Name of the task */
4096, /* Stack size in words */
NULL, /* Task input parameter */
2, /* Priority of the task */
&Task2, /* Task handle. */
1);and the following functions :
void Task1code( void * parameter) {
for (;;) {
if (client.connected()) {
String temp = getData();
vTaskDelay(800);
if (!client.publish("topic", temp ())) {
log_e("Couldnt publish to 'Topic' ");
vTaskDelay(200);
}
}
delay(3000);
}
}
void Task2code( void * parameter) {
for (;;){
getTempValue(); // reads some DS81B0 temperaturesensors over 1-wire
delay(750);
}
}I am kind of unsure what vTaskDelay does in the first code as I cant really understand this page here https://www.freertos.org/a00127.html - Also, can I use normal delays in a extra task or is it bad ?
I would love if someone could explains me the vTaskDelay a bit more noob-friendly and maybe has some ideas on how to make that code run better ?
Edit:
Also I question would be is how to use vTaskDelayUntil()
Thanks !
vTaskDelay is basically the same as Arduino delay() But if I remember correctly you have to divide it by the ticks per millisecond See the ESP documentation you can search for vTaskDelay and you'll see a number of results
vTaskDelay just causes the task to pause at that point for the specified duration. You generally use it in loops like you're doing here, or between statements that need a defined delay between them, such as when driving pins high or low for a communication protocol.
The real question is, what is this delay() function you're calling? Where is that defined? It seems like it probably does the same thing, but there's no such function in the FreeRTOS API AFAIK.
The problem is no to pass control back to FreeRTOS but the handling of the watchdog in the eps-idf framework.
The watchdog is "fed" in the IDLE task and while the APP_MAIN task has a higher priority than IDLE it is never interrupted.
If you don't want to use vTaskDelay maybe you could make the priority of the IDLE and the MAIN task equal. Than both should be executed (but you must be careful if there any even more task that do not get enough attention).
I don't recommend doing this for anything but testing, but you can simply disable the task watchdog on the IDLE tasks.
menuconfig->Component config->Esp32-specific config -> deactivate Task watchdog
For production code you should follow best-practice and use the FreeRTOS functions such as vTaskDelay so you don't hog the CPU.