Timer counter on STM32F407
Posted: Fri Dec 18, 2020 8:15 pm
I'm trying to count events from a GPIO on STM32F407 from Discovery Board using Timer 2.
The code works fine, except for the counter value that sometimes increases and in some resets the value decreases when the GPIO A1 change the input value.
Are there some additional configs for the timer settings to increase the counts on GPIO change?
Code: Select all
import time
import machine
from pyb import LED, Timer, UART, ADC, Pin
pin_a = pyb.Pin("A1", pyb.Pin.AF_PP, pull=pyb.Pin.PULL_NONE, af=pyb.Pin.AF1_TIM2)
pin_b = pyb.Pin("A15", pyb.Pin.AF_PP, pull=pyb.Pin.PULL_NONE, af=pyb.Pin.AF1_TIM2)
enc_timer = pyb.Timer(2, prescaler=1, period=100000)
enc_channel = enc_timer.channel(2, pyb.Timer.ENC_B)
enc_timer.counter(0)
while True:
time.sleep_ms(100)
print(enc_timer.counter())
Are there some additional configs for the timer settings to increase the counts on GPIO change?