Timer with microsecond resolution

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
atmuc
Posts: 18
Joined: Fri Nov 13, 2020 11:44 am
Location: Istanbul

Timer with microsecond resolution

Post by atmuc » Sun Nov 15, 2020 12:10 pm

Can I use a timer with micro second resolution instead of milli second?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Timer with microsecond resolution

Post by pythoncoder » Mon Nov 16, 2020 6:11 am

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.
Peter Hinch
Index to my micropython libraries.

User avatar
atmuc
Posts: 18
Joined: Fri Nov 13, 2020 11:44 am
Location: Istanbul

Re: Timer with microsecond resolution

Post by atmuc » Mon Nov 16, 2020 6:47 am

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.

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: Timer with microsecond resolution

Post by OlivierLenoir » Mon Nov 16, 2020 8:13 pm

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.

BabooMookerji
Posts: 6
Joined: Wed Nov 18, 2020 1:46 pm

Re: Timer with microsecond resolution

Post by BabooMookerji » Wed Nov 18, 2020 2:16 pm

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?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Timer with microsecond resolution

Post by pythoncoder » Wed Nov 18, 2020 2:25 pm

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 ;)
Peter Hinch
Index to my micropython libraries.

BabooMookerji
Posts: 6
Joined: Wed Nov 18, 2020 1:46 pm

Re: Timer with microsecond resolution

Post by BabooMookerji » Wed Nov 18, 2020 2:29 pm

But RMT is write-only and beta status currently, correct?

BabooMookerji
Posts: 6
Joined: Wed Nov 18, 2020 1:46 pm

Re: Timer with microsecond resolution

Post by BabooMookerji » Wed Nov 18, 2020 2:32 pm

So is ESP8266 an option here? From what I understand it is not plagued with soft IRQ issues as ESP32-S?

User avatar
atmuc
Posts: 18
Joined: Fri Nov 13, 2020 11:44 am
Location: Istanbul

Re: Timer with microsecond resolution

Post by atmuc » Wed Nov 18, 2020 2:52 pm

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.

beyonlo
Posts: 58
Joined: Thu Nov 26, 2015 8:03 pm

Re: Timer with microsecond resolution

Post by beyonlo » Wed Sep 29, 2021 11:38 pm

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.

Post Reply