Question about Timers

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
nesergen
Posts: 23
Joined: Mon Oct 26, 2020 9:17 pm

Question about Timers

Post by nesergen » Thu Jun 03, 2021 9:39 pm

Good day!
I want to use timers in my program to periodically execute a part of the code, without referring to any pins.
According to the documentation, to activate the timer, you need to write the following line, which usually includes the identifier (built-in number) of the timer.

Code: Select all

machine.Timer(id, ...)
But I do not specify the identifier and the timer is created and works without problems.

Code: Select all

machine.Timer(mode=machine.Timer.PERIODIC, period = 2000 , callback = lambda x: set_ln2())
And two timers are created this way and work.
So the question I'm interested in is what timers (name, type, or something else) I activate with this code and how many of them can I create?

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Question about Timers

Post by davef » Fri Jun 04, 2021 6:10 am

What hardware are you running on?

ESP8266 virtual timers
ESP32 hardware timers

nesergen
Posts: 23
Joined: Mon Oct 26, 2020 9:17 pm

Re: Question about Timers

Post by nesergen » Fri Jun 04, 2021 10:29 am

davef wrote:
Fri Jun 04, 2021 6:10 am
What hardware are you running on?

ESP8266 virtual timers
ESP32 hardware timers
I'm sorry, I forgot to specify my equipment. I am using stm32f411 board.

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

Re: Question about Timers

Post by pythoncoder » Fri Jun 04, 2021 3:49 pm

If no ID is specified (or id == -1) the timer is virtual. A positive integer specifies a hardware timer.
Peter Hinch
Index to my micropython libraries.

Post Reply