-
Notifications
You must be signed in to change notification settings - Fork 7.6k
delay() function doesn't work for less than 10ms #2981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ducalex Chuck. |
@ducalex if you are worried the void delay(uint32_t ms)
{
vTaskDelay(ms / portTICK_PERIOD_MS);
uint32_t remainderUS = (ms % portTICK_PERIOD_MS)*1000;
if(remainderUS) delayMicroseconds(remainderUS);
} |
Your code would also resolve the problem indeed. |
You can see the problem with this code: void setup()
{
for (int i = 0; i < 20; i++) {
int start = millis();
delay(i);
printf("i = %d, actual sleep = %dms\n", i, (int)(millis() - start));
}
} Output:
|
So I assume you are using arduino-esp32 as a component with your own sdkconfig settings? Let's say portTICK_PERIOD_MS = 10 and you call delay(9). Do you really want to block and spin for 9ms? |
@ducalex with current core 7dbda4
Chuck. |
Correct, the default esp-idf settings.
I do. That is how other arduino boards work and a lot of code and libraries expect delay to work as per the documentation. That is also how esp-idf's own usleep() works. As you pointed out delay works fine in Arduino IDE, if you consider Arduino as component to be unsupported then please close this issue! Thanks |
@stickbreaker Yes, I can see it works fine in Arduino IDE now. As pointed out by @negativekelvin, it is only a problem when using arduino-esp32 as a component because freertos frequency is 100hz (by default). |
I missed you were using arduino as a component. I don't know all the rules when using arduino as a component. I do know, I2C is not shared between Chuck. |
Yes usleep, emphasis on the u. It is not good design to use it for ms delays. Is there a reason you don't want to set tick hz to 1000? |
None, I didn't know that Arduino-esp32 IDE version wasn't using the default 100Hz. I will change my project to 1000 but perhaps it could be worth mentioning this necessary step in the setup guide here https://github.com/espressif/arduino-esp32/blob/master/docs/esp-idf_component.md. Thanks |
@ducalex Please fix that doc to and make a PR |
Done. #3014 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
Hardware:
Board: Lolin32
Core Installation version: d5fdd71
IDE name: IDF component
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 8.1
Description:
delay() doesn't work for periods smaller than one tick(10ms) (it is also rounded down if not divisible by 1 tick).
It is a small change but I can create a pull request if it is the proper way to do things also, just tell me.
Sketch: (leave the backquotes for code formatting)
The text was updated successfully, but these errors were encountered: