Page 1 of 5
Wrong delay when use "delay ms" ESP32
Posted: Mon Jan 04, 2021 3:29 pm
by flowjmaria
Hello everyone, in a simple project with delay ms, when I only try to use delay between 1ms and 9ms the delay is wrong. However if I use delay us and delay s, no problem.
Only is for information of issue.
Thanks.
Re: Wrong delay when use "delay ms" ESP32
Posted: Mon Jan 04, 2021 3:47 pm
by LeighM
This is due to the fact that the delay_mS resolution is limited by the RTOS tick period.
(RTOS has some advantages, some disadvantages
delay_uS does not allow other tasks to run, it just consumes CPU cycles
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 10:11 am
by flowjmaria
Please, look this picture, there you can see what happen with delay_ms wrong between 1ms and 9 ms.
Thanks.
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 11:23 am
by BenR
Hello,
Many thanks for reporting this. Are millisecond delays of 10ms and over ok?
I'll see if there is an easy way for us to fix this in the code.
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 11:26 am
by flowjmaria
Hello Ben, yes over 10ms the delay is OK.
Thanks.
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 11:37 am
by BenR
Aha thanks I've now made a change via the update system that hopefully will help.
Let us know how you get on.
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 12:37 pm
by flowjmaria
Hello Ben, Now it works OK.
Thanks a lot.
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 6:06 pm
by jgu1
Hi ben (hope it´s ok I ask now flowmaria?)
Seem that timing is ok now. But now I am even not possible to program the chip. And it´s the same program as first used.
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 7:47 pm
by jgu1
Me again!
I tryed to make a new project..............................

And yes, now Ili9341 work with ESP32
I work, but when I compare the speed of update with other Arduino project, it´s a little low, but ok. I though the ESP32 processor is very fast.
But finally, succes.
Br jorgen
Re: Wrong delay when use "delay ms" ESP32
Posted: Tue Jan 05, 2021 8:05 pm
by BenR
Hi Jorgen,
Great news
I work, but when I compare the speed of update with other Arduino project, it´s a little low, but ok. I though the ESP32 processor is very fast.
The ESP processor is very fast but it seems the IO is not. I have done a bit of hacking away at the ESP IDF toolchain already to strip away some layers and this sped up the IO a fair bit but it's still a bit slow when compared to other MCUs.
Here is a similar topic on Espressif forums. We will keep looking for optimisations but it could be that raw IO bit toggling is just not very efficient on ESP devices.
https://www.esp32.com/viewtopic.php?t=1595
I have a plan to implement the RMT peripherals on the device which should allow for hardware driven fast comms. This will help to allow things like WS2812B and 1-Wire components to function but may also be useful for GLCDs. Hardware SPI might also be a good option.