Measure time between encoder counts wtih STM2f439ZI
Hello, I'm super new to all this STM32 stuff so bear with me please.
I'm using a Nucle board with an STM32f439ZI and I want to measure the speed of my motor.
So far I managed to count the increments of my incremental encoder. I did that by configurating TIM2 in encoder Mode, and I'm getting the counts with __HAL_TIM_GET_COUNTER(&htim2).
To calculate the velocity I want to use the method described in a Ben Katz blog :
"Getting good damping performance is dependent on good velocity measurement, which is not trivial. The gist of the problem is that differentiating your position signal *****. By the time you can filter the differentiated signal enough to have a nice looking velocity, the phase lag caused by the filter ruins your signal. Fortunately, the MA700 sensor I'm using for position sensing has an encoder output as well as an absolute position output. I'm able to use the encoder output to my advantage for velocity measurement. By configuring one timer on the STM32F4 in encoder mode to keep track of encoder count, and then configuring another free-running timer as a slave which resets whenever the count changes, I'm able to automatically capture the time between encoder edges. This gives a value inversely proportional to the motor speed, which gives good results for velocity measurement when combined with some logic to handle the zero-speed case where the count isn't changing."
I don't really know how to set this other timer and to trigger it when my counter changes. Could someone help me to set this up please ?
Ty in advance.