2017-07-31 05:41 AM
Beginner working with STM32L452:
I have TIM2 set up as encoder-based timer. Works perfect.
Now I want an interrupt whenever the TIM2 reaches a certain value (position).
I tried to enable timer interrupt through HAL_TIM_Encoder_Start_IT, and hoped to be able to get an interrupt when the encoder passed value 0. But I only managed to get an interrupt on every single encoder tick.
Reading a bit more on timers, i wonder if setting up another timer as slave to TIM2 would be the way forward ?
If yes, then how should the master/slave output/input be configured to have the slave follow TIM2 ? I have read the timer overview in 'en.DM00042534.pdf' but I don't understand all of it.
if no, what are my options then?
If a solution can be achieved through CubeMX configurator, i I would very much appreciate that, but it is not a must.
Thanks.
#interrupt #timer #hal_tim_encoder_start_it #interrupts #encoderSolved! Go to Solution.
2017-07-31 06:15 AM
I want an interrupt whenever the TIM2 reaches a certain value (position).
That is, you want to use one of the capture-compare units in *compare* configuration, i.e. you want to throw an interrupt when timer's counter CNT matches the value set in CCRn.
The encoder mode uses CH1 and CH2 as input. While it won't necessarily propagate beyond the input filters, it precludes using those channels as *compare* which is an output rather than input feature.
Thus, set up CH3 or CH4 for the output compare (you don't need to actually enable it as output, nor set up a GPIO pin for it) and bind the interrupt to the chosen channel in DIER.
JW
2017-07-31 06:15 AM
I want an interrupt whenever the TIM2 reaches a certain value (position).
That is, you want to use one of the capture-compare units in *compare* configuration, i.e. you want to throw an interrupt when timer's counter CNT matches the value set in CCRn.
The encoder mode uses CH1 and CH2 as input. While it won't necessarily propagate beyond the input filters, it precludes using those channels as *compare* which is an output rather than input feature.
Thus, set up CH3 or CH4 for the output compare (you don't need to actually enable it as output, nor set up a GPIO pin for it) and bind the interrupt to the chosen channel in DIER.
JW
2017-08-03 12:49 AM
@waclawek_jan :
Thanks for pointing me the direction of output compare.
I will have to see next week if I can make this work, at least at can see that googling for 'stm32 timeroutput compare
' gives some new interesting leads.2017-08-03 03:18 AM
Read the Timer chapter in RM first.
JW