Delay() With Small Values (eg Delay(1)) Does Not Delay If System HZ ...
Maybe your like
- Notifications You must be signed in to change notification settings
- Fork 7.8k
- Star 16.2k
- Code
- Issues 136
- Pull requests 22
- Discussions
- Actions
- Projects 2
- Wiki
- Security 3
- Insights
Description
Board
OLIMEX ESP32-POE (but will happen anywhere I think)
Device Description
Stock OLIMEX ESP32-POE, but I believe this will happen on any board
Hardware Configuration
Nothing attached
Version
latest development Release Candidate (RC-X)
IDE Name
PlatformIO
Operating System
Ubuntu 22.04
Flash frequency
40MHz
PSRAM enabled
yes
Upload speed
115200
Description
The Arduino delay() function is implemented as follows:
arduino-esp32/cores/esp32/esp32-hal-misc.c
Line 178 in fcd4799
| vTaskDelay(ms / portTICK_PERIOD_MS); |
If portTICK_PERIOD_MS > 1 (i.e. CONFIG_FREERTOS_HZ < 1000), then small values will round down to 0, and no delay will happen. I'm not super familiar with the delay facilities in FreeRTOS / ESP-IDF but there has to be some way to do a shorter delay (busy-wait, if nothing else)?
See also: platformio/platform-espressif32#846
Sketch
// Run me with CONFIG_FREERTOS_HZ=100 to see the problem void setup() { Serial.begin(115200); } void loop() { Serial.printf("BEFORE msec=%lu\n", millis()); for (int i = 0; i < 20; ++i) delay(5); Serial.printf("AFTER msec=%lu\n\n", millis()); }Debug Message
(none)Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
No one assignedLabels
No labelsNo labelsType
No typeProjects
No projectsMilestone
No milestoneRelationships
None yetDevelopment
No branches or pull requestsIssue actions
You can’t perform that action at this time.Tag » Arduino Delay Hz
-
Generate Frequency Using Simple HIGH-Delay-LOW-Delay-Repeat
-
Convert Frequency To Delay Formulae - Arduino Forum
-
Delay() - Arduino Reference
-
Converting Frequency To Delay Time - Arduino Forum
-
0.25 -0.5 Us Delay Repeated With 60 Hz Frequency - #18 By Aiasnikov
-
0.25 -0.5 Us Delay Repeated With 60 Hz Frequency - Arduino Forum
-
Programing Hz - Programming Questions - Arduino Forum
-
Converting Frequency To Time (SOLVED) - Arduino Forum
-
How To Set LED Frequency? - General Electronics - Arduino Forum
-
How To Generate Two Signals With Time Delay? - Arduino Forum
-
Setting PWM Frequency - 5Hz - Arduino Forum
-
Blink With Separate Control Of Frequency And Duty Cycle, Without Using ...
-
Relation Between Frequency And Delay() - AVR Freaks
-
Sampling With Arduino. Delay Of Arduino And If Statement Question