MicroPython_ESP32_psRAM_LoBo icon indicating copy to clipboard operation
MicroPython_ESP32_psRAM_LoBo copied to clipboard

sleep_us is not accurate

Open WilliamHarvey97 opened this issue 6 years ago • 1 comments

I did the following test code:

import time

init_time = time.time()
time.sleep_us(1000000)
print('exec time: ', str(time.time() - init_time))

It gaves me the following output:

exec time: 0.102143

I think it comes from mphalport.c:

void mp_hal_delay_us(uint32_t us) {
	if (us == 0) return;
	if (us > 10000) {
		// Delay greater then 10 ms, use ms delay function
		uint32_t dus = us % 10000;	// remaining micro seconds
		mp_hal_delay_ms(us/10000);
	    if (dus) ets_delay_us(dus);
		return;
	}
    ets_delay_us(us);
}

In this following line:

mp_hal_delay_ms(us/10000)

Here, the delay is smaller than it should by a factor of 10, since a millisecond is 1000 microseconds.

WilliamHarvey97 avatar Jun 12 '19 04:06 WilliamHarvey97

Good catch. But you might have to just fix it in your own codebase, there haven't been any commits here since September of last year.

carterw avatar Jun 12 '19 16:06 carterw