cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446 How to use CubeMX to config TIM2 in PWM Input Mode for speed measure (prep for Simulink)

Thomasch
Associate

For speed measure of a dc-motor we want to capture the pwm-period as described here: Solved: I have a timer set up to measure the input pwm period ... ,
I will use TIM2 and set up to 'PWM Input on CH1', with channel_1 read pwm-period, channel_2 read pulse width (Pin: PA6), the motor encoder gives 100 ticks per rotation and runs with max 3000 rpm,

Additional, when the input signal is stopped (dc-motor don't run), the capture registers has to reset to 0 (to indicate frequency=speed=0),

Questions: How to do all the nessesary configurations right in CubeMX? The lab experiments runs later directly from Matlab 2022B / Simulink.
And how can I use TIM2 CH3 to do the reset stuff as described in tread and how to config the right trigger?

pic1 TIM2 Mode and Configuration.jpg

Ty in advance.

1 REPLY 1
Thomasch
Associate

For testing I do following steps:

1. Step: config TIM1 as 'PWM Generation', 400Hz, Pin PA8

pic 1 Timer 1 Mode and Configuration (PWM 400Hz).jpg

2. Step: config TIM2 as Combined Channels 'PWM Input on CH1', PSC=1, Pin PB8

pic 2 Timer 2 Mode and Configuration (PWM Input on CH1).jpg

Then running the Simulink Model in real time gives wrong value from TIM2_CH1: 1024,
pic 5 Simulink TIM2 b.jpg
Any kind of help would be appreciated! Thanks