Page 1 of 1

Can I use a Pin as Timer source?

Posted: Wed Feb 17, 2021 8:02 pm
by water
Can I let Timer.counter() add 1 when Pin level changed.

Re: Can I use a Pin as Timer source?

Posted: Wed Feb 17, 2021 9:42 pm
by dhylands
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.