Timer id's - which is correct?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
dundeemt
Posts: 2
Joined: Wed Sep 27, 2017 12:06 pm

Timer id's - which is correct?

Post by dundeemt » Wed Sep 27, 2017 12:22 pm

Please correct me, where I am wrong. I'll list my understanding of the chip first.
* It appears that the ESP32 has 2 groups of 2 timers, for a total of 4 available timers.
* The timers are hardware timers.
* There are no virtual timers.

Reading the documentation for the ESP8266 led me to think that I should always use -1 for the id in `t = Timer(-1)` However, looking at the esp32 mpy source code, it appears that the id is manipulated to produce a group and index value. i.e.
https://github.com/micropython/micropyt ... 858e81821c

>>> for i in range(4):
... # print id, Group, index
... print (i, (i >> 1) & 1, i & 1)
...
...
...
0 0 0
1 0 1
2 1 0
3 1 1

Since the timers are hardware based, shouldn't non-negative numbers be used, as negative numbers appear to indicate a virtual timer?
So is 0, 1, 2, 3 more correct for the Timer id than -1, -2, -3, -4?

Best,

Jeff

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: Timer id's - which is correct?

Post by fdufnews » Wed Sep 27, 2017 5:54 pm

That's not what I understand when I read the documentation
class machine.Timer(id, ...)
Construct a new timer object of the given id. Id of -1 constructs a virtual timer (if supported by a board).

dundeemt
Posts: 2
Joined: Wed Sep 27, 2017 12:06 pm

Re: Timer id's - which is correct?

Post by dundeemt » Thu Sep 28, 2017 12:38 am

https://github.com/micropython/micropyt ... ne_timer.c line 80 - machine_timer_make_new
along with machine_timer_isr (line 99) which specifically references device->hw_timer -- Makes me question support for virtual timers currently. Also, attempting to make more than 4 timers leads to problems. (The nature of which appears to be memory corruption, although I've yet to confirm that.)

I've also created timers using ids of 0,1,2,3 and -1, -2, -3, -4 and found no difference in operations. Trying to create multiple timers using only -1, as the id results in unexpected results.

I'm hoping someone on the board can give some feedback on what I am seeing.

Post Reply