Delay() With Small Values (eg Delay(1)) Does Not Delay If System HZ ...

Skip to content Dismiss alert {{ message }} / arduino-esp32 Public
  • 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
Additional navigation options delay() with small values (e.g. delay(5)) does not delay if system HZ (CONFIG_FREERTOS_HZ) <1000 #6946New issueNew issueClosedCloseddelay() with small values (e.g. delay(5)) does not delay if system HZ (CONFIG_FREERTOS_HZ) <1000#6946@egnor

Description

@egnoregnoropened on Jul 5, 2022

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 assigned

Labels

No labelsNo labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You can’t perform that action at this time.

Tag » Arduino Delay Hz