Skip to content

Commit d3ccd2a

Browse files
authored
FreeRTOS.ino: fix usage of vTaskDelay (espressif#7418)
The original code assumes 100Hz FreeRTOS tick rate and just supplies vTaskDelay with the assumed number of ticks required for the wanted delay. This patch simply fixes it to use portTICK_PERIOD_MS, thereby working correctly regardless of what tick rate FreeRTOS has been configured to run at.
1 parent c1dc4f2 commit d3ccd2a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

libraries/ESP32/examples/FreeRTOS/FreeRTOS.ino

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ void TaskBlink(void *pvParameters) // This is a task.
6767
for (;;) // A Task shall never return or exit.
6868
{
6969
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
70-
vTaskDelay(100); // one tick delay (15ms) in between reads for stability
70+
// arduino-esp32 has FreeRTOS configured to have a tick-rate of 1000Hz and portTICK_PERIOD_MS
71+
// refers to how many milliseconds the period between each ticks is, ie. 1ms.
72+
vTaskDelay(1000 / portTICK_PERIOD_MS ); // vTaskDelay wants ticks, not milliseconds
7173
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
72-
vTaskDelay(100); // one tick delay (15ms) in between reads for stability
74+
vTaskDelay(1000 / portTICK_PERIOD_MS); // 1 second delay
7375
}
7476
}
7577

@@ -92,6 +94,6 @@ void TaskAnalogReadA3(void *pvParameters) // This is a task.
9294
int sensorValueA3 = analogRead(A3);
9395
// print out the value you read:
9496
Serial.println(sensorValueA3);
95-
vTaskDelay(10); // one tick delay (15ms) in between reads for stability
97+
vTaskDelay(100 / portTICK_PERIOD_MS); // 100ms delay
9698
}
9799
}

0 commit comments

Comments
 (0)