Page 1 of 1
ESP32 Virtual Timers??
Posted: Sun May 17, 2020 4:00 am
by jdts
Does MP actually support virtual timers on ESP32? The
documentation sure claims so, but the example given to demonstrate it doesn't even run correctly, and:
Re: ESP32 Virtual Timers??
Posted: Sun May 17, 2020 5:58 am
by patrickw
What board and firmware are you running?
This is my setup IDF4 nightly build:
Code: Select all
>>> import os
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.12.0',
version='v1.12-452-g801f7dca7 on 2020-05-14', machine='TinyPICO with ESP32-PICO-D4')
This ran fine on my board.
Code: Select all
from machine import Timer
tim = Timer(-1)
tim.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(1))
I don't understand the point of Timer(-1)==Timer(-1) but it is also True on my board.
Re: ESP32 Virtual Timers??
Posted: Sun May 17, 2020 7:05 pm
by jdts
Code: Select all
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.12.0', version='v1.12-35-g10709846f on 2019-12-29', machine='ESP32 module with ESP32')
Yes you can run one timer callback, but the example has two calls with a virtual timer. You never see the "1", since the 2nd overwrites the first, as it would for a fixed hardware timer:
Code: Select all
=== tim = Timer(-1)
=== tim.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(1))
=== tim.init(period=2000, mode=Timer.PERIODIC, callback=lambda t:print(2))
>>> 2
2
2
2
2
2
2
2
2
2
...
It appears there are only 4 timers on the ESP32, and -1 is the same as 3:
Code: Select all
>>> Timer(-1) == Timer(0)
False
>>> Timer(-1) == Timer(3)
True
Re: ESP32 Virtual Timers??
Posted: Sun Jul 19, 2020 11:12 pm
by nevercast
At the time of writing this reply, the ESP32 does not have support for Virtual Timers. The docs are unfortunately incorrect in this regard. Perhaps an oversight when they were originally copied from either the WiPy1 or ESP8266. I am not sure which.
I've attempted to fix the docs here:
https://github.com/micropython/micropython/pull/6258
Hopefully in the future the ESP32 port will use the FreeRTOS Software Timers.
Re: ESP32 Virtual Timers??
Posted: Mon Jul 20, 2020 12:46 am
by shaoziyang
You may use Timer(-1), Timer(-2)... for different virtual timer.
Re: ESP32 Virtual Timers??
Posted: Mon Jul 20, 2020 4:17 am
by mattyt
shaoziyang wrote: ↑Mon Jul 20, 2020 12:46 am
You may use Timer(-1), Timer(-2)... for different virtual timer.
Currently that's not correct on the ESP32; virtual timers are
not implemented.
See Josh's PR
#6258 for more details. In short there are four
hardware timers and using -1 (and -2) actually maps to one of those timers due to a defect.
Re: ESP32 Virtual Timers??
Posted: Mon Jul 20, 2020 12:58 pm
by shaoziyang
mattyt wrote: ↑Mon Jul 20, 2020 4:17 am
shaoziyang wrote: ↑Mon Jul 20, 2020 12:46 am
You may use Timer(-1), Timer(-2)... for different virtual timer.
Currently that's not correct on the ESP32; virtual timers are
not implemented.
See Josh's PR
#6258 for more details. In short there are four
hardware timers and using -1 (and -2) actually maps to one of those timers due to a defect.
Thanks for the tip
Re: ESP32 Virtual Timers??
Posted: Mon Jul 20, 2020 12:59 pm
by shaoziyang
mattyt wrote: ↑Mon Jul 20, 2020 4:17 am
shaoziyang wrote: ↑Mon Jul 20, 2020 12:46 am
You may use Timer(-1), Timer(-2)... for different virtual timer.
Currently that's not correct on the ESP32; virtual timers are
not implemented.
See Josh's PR
#6258 for more details. In short there are four
hardware timers and using -1 (and -2) actually maps to one of those timers due to a defect.
Thanks for the tip