(solved) how to program sub-tick delays?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(solved) how to program sub-tick delays?

Postby mzimmers » Sat Oct 09, 2021 5:04 pm

Hi all -

The app I'm porting to the ESP32 needs relatively short (<1ms) delays. Clearly the vTaskDelay() function won't work for this. I was looking at the docs regarding General Purpose Timers.

1. is this the right component to use?
2. from the docs (and the example), it's not clear to me how I specify the time duration; the example uses an even increment of seconds.

Thanks for any help.
Last edited by mzimmers on Sat Oct 09, 2021 7:31 pm, edited 1 time in total.


User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: how to program sub-tick delays?

Postby mzimmers » Sat Oct 09, 2021 7:30 pm

Oh, that's perfect:

Code: Select all

#include "rom/ets_sys.h"
void delay_milliseconds(uint64_t ms) {
    uint64_t us = ms * 1000;
    if (ms < 1000) {
            ets_delay_us(us);
    } else {
        vTaskDelay((ms) / portTICK_PERIOD_MS);
    }
}
Thanks, chegewara.

Who is online

Users browsing this forum: Bytespider, PetalBot and 4 guests