Nanosecond delay
Posted: Fri Apr 12, 2024 12:58 pm
Hi there. I'm new to working with ESP controllers.
I'm converting a project from Raspberry Pi Pico to ESP32-S3. And from what I can tell this microcontroller should be more than capable.
There were a couple of time-critical functions and I'm trying to figure out how to implement them on ESP.
The most important one is a sub-microsecond delay. On RPi Pico I did it like this:
How would I achieve the same result on ESP? I tried searching for systick but I can't find it.
For less time-sensitive delays I used "busy_wait_us", but the best I found for ESP is "esp_rom_delay_us" which is marked as "Internal and Unstable". Of course, if I can manage to make a delay in 10s on ns, then this won't be a problem either.
Sidenote: I won't have any wireless connectivity. And in this case, if I understood correctly, I don't need RTOS.
I'm converting a project from Raspberry Pi Pico to ESP32-S3. And from what I can tell this microcontroller should be more than capable.
There were a couple of time-critical functions and I'm trying to figure out how to implement them on ESP.
The most important one is a sub-microsecond delay. On RPi Pico I did it like this:
Code: Select all
// the clock is set to 125 MHz => 1 tick == 8 ns
// init SysTick timer
systick_hw->csr = 0x05; // enable systick at 1 cycle resolution (8ns)
systick_hw->rvr = 0xffff; // 16 bit
// delay 13 ticks or 102 nanoseconds
uint16_t ticks = 13; // 13*8 = 102 nanos
uint16_t start = systick_hw->cvr;
while((uint16_t)(start-systick_hw->cvr) < ticks);
For less time-sensitive delays I used "busy_wait_us", but the best I found for ESP is "esp_rom_delay_us" which is marked as "Internal and Unstable". Of course, if I can manage to make a delay in 10s on ns, then this won't be a problem either.
Sidenote: I won't have any wireless connectivity. And in this case, if I understood correctly, I don't need RTOS.