2025-01-12 09:58 PM
Hi,
I am using an STM32H7 TIM8 unit to generate a PWM signal with a fixed number of pulses. The TIM unit is configured in one-shot mode and the repetition counter is configured to generate the desired number of pulses, after which the timer automatically halts. This all works great.
Occasionally we may wish to stop the counter early. The pulses are triggering an external motor controller which moves a shaft forward or backwards based on the number of pulses received and an encoder wheel. If an external sensor signals that the shaft is near a limit we'd like to halt its movement. I think I can do this by just setting CEN=0 if the sensor is triggered. It would also be nice to know how many pulses were actually generated (i.e. some way of reading the repetition counter's current value) since we are trying to keep track of the shaft's actual position, but I can't seem to find a way to do that.
I suppose we could use CEN in master mode to gate a second timer running in slave mode and after setting CEN=0 reading the other timer's CNT value to figure out how much time has elapsed and then calculating the number of pulses. That seems like a lot of work to just read the repetition counter's internal value, though.
Thanks,
TG