Can I use a Pin as Timer source?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
water
Posts: 75
Joined: Sun Sep 24, 2017 9:16 am

Can I use a Pin as Timer source?

Post by water » Wed Feb 17, 2021 8:02 pm

Can I let Timer.counter() add 1 when Pin level changed.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Can I use a Pin as Timer source?

Post by dhylands » Wed Feb 17, 2021 9:42 pm

You can if you use one of the timer channels that has ETR mode (ETR = External Trigger).

I have an example here: https://github.com/dhylands/upy-example ... counter.py

On the pyboard, you can look inside the build-PYBV11 directory for a file called pins_af.py. If you search in that file for _ETR then those are the pins that you can adapt freq_counter.py to use.

It looks like there are only 2 available: X1 (with TIM2_ETR or TIM8_ETR) or X6 (with TIM2_ETR). Other boards may expose different pins and give you more or less timer channels with ETR functionality exposed.

Post Reply