Page 1 of 1

(solved) how to program sub-tick delays?

Posted: Sat Oct 09, 2021 5:04 pm
by mzimmers
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.

Re: how to program sub-tick delays?

Posted: Sat Oct 09, 2021 5:09 pm
by chegewara

Re: how to program sub-tick delays?

Posted: Sat Oct 09, 2021 7:30 pm
by mzimmers
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.