Page 1 of 1

Timer with microsecond resolution

Posted: Sun Nov 15, 2020 12:10 pm
by atmuc
Can I use a timer with micro second resolution instead of milli second?

Re: Timer with microsecond resolution

Posted: Mon Nov 16, 2020 6:11 am
by pythoncoder
If you are hoping for a callback to run with anything approaching microsecond resolution you need to use a Pyboard or similar. Interrupts on ESP32 are soft IRQ's and are subject to latency which can run to milliseconds, especially on SPIRAM boards,

On a Pyboard latency is on the order of 15μs.

Re: Timer with microsecond resolution

Posted: Mon Nov 16, 2020 6:47 am
by atmuc
Thanks, Peter. I think the best way is to have an Arduino as a pulse generator to drive my stepper motor. I can communicate with Arduino and ESP32 via SPI. In that way, I will have hardware interrupt on the Arduino with minimum C++ code and have all control logic on ESP with the freedom of Python.

Re: Timer with microsecond resolution

Posted: Mon Nov 16, 2020 8:13 pm
by OlivierLenoir
If your looking for µs, you can use the RMT.
I've been using it in MicroPython-Multiaxis project. Discussion in this forum Multiaxis stepper motors using RMT.

Re: Timer with microsecond resolution

Posted: Wed Nov 18, 2020 2:16 pm
by BabooMookerji
This thread makes me sad. I've been working on a design with three serial UARTs @ 57.6Kbps, 62.5 Kbps, and 202 Kbps speeds and ultra low latency / jitter requirement for the 62.5/202Kbps UARTS, using ESP32-S as the MCU running Micropython.

Is this even doable with the ESP-32 given these soft interrupt scheduling issues? I am reading other conflicting threads about what options there may be to get down to microsecond level granularity, is writing an RMT serial driver the only option here?
Does loboris fork solve any of this? Is loboris supported any longer? How do combustion engines even work?

Re: Timer with microsecond resolution

Posted: Wed Nov 18, 2020 2:25 pm
by pythoncoder
As I understand it the Loboris fork was abandoned long ago.

RMT output is well supported in the official firmware. I have used it to good effect. RMT input would be a great addition.

I could explain internal combustion engines but this is neither the time or place ;)

Re: Timer with microsecond resolution

Posted: Wed Nov 18, 2020 2:29 pm
by BabooMookerji
But RMT is write-only and beta status currently, correct?

Re: Timer with microsecond resolution

Posted: Wed Nov 18, 2020 2:32 pm
by BabooMookerji
So is ESP8266 an option here? From what I understand it is not plagued with soft IRQ issues as ESP32-S?

Re: Timer with microsecond resolution

Posted: Wed Nov 18, 2020 2:52 pm
by atmuc
For time critic operations native code can be used with microPython;

https://docs.micropython.org/en/latest/ ... atmod.html

I started to test RMT. I plan to combine RMT and timer interrupts. I have to know the position of the stepper with 1 mm precision while it is moving. When I buffer all pulses to RMT it will not be possible.

Re: Timer with microsecond resolution

Posted: Wed Sep 29, 2021 11:38 pm
by beyonlo
Hi.

In this doc of espressif talk about High Resolution Timer, in us.

https://docs.espressif.com/projects/esp ... timer.html

"
Periodic esp_timer also imposes a 50us restriction on the minimal timer period. Periodic software timers with period of less than 50us are not practical since they would consume most of the CPU time. Consider using dedicated hardware peripherals or DMA features if you find that a timer with small period is required.
"

periodic=50us is very good instead 1ms minimum possible currently.

Is possible to implement this High Resolution Timer on MicroPython?

Thank you.