2017-03-21 06:08 AM
Hi all.
I'm working on a STM32L151, with EWARM toolchain.
I'm using TIM4, with HAL libraries. TIM4 has 4 channels. I set
- CH1, input compare;
- CH2, CH3, CH4 output compare (no output);
I want to use input compare event as 'trigger' for the other channels.
In my implementation of:
HAL_TIM_IC_CaptureCallback
I set up period for CH2 (or CH3, CH4 ) and then want to start it with: HAL_TIM_OC_Start_IT. I noticed that this is the wrong way:
HAL_TIM_IC_CaptureCallback, is called before HAL_TIM_OC_DelayElapsedCallback and setting OC inside HAL_TIM_IC_CaptureCallback caused that HAL_TIM_OC_DelayElapsedCallback manages an interrupt already managed by HAL_TIM_IC_CaptureCallback. (bad design issue? why STM gives 4 channels and manages only one?)
I move HAL_TIM_OC_Start_IT after HAL_TIM_IRQHandler(&htim4). In this way OC starts properly. My problem is that if I try to stop interrupt of only OC one channel inside HAL_TIM_OC_DelayElapsedCallback, the timer, after a first return from HAL_TIM_OC_DelayElapsedCallback stops working.
- i try to stop it with the HAL: HAL_TIM_OC_Stop_IT(&htim4, TIM_CHANNEL_2);
- i try to stop the CHANNEL with LL
however it does not work.
Where I'm wrong?
#output-compare #tim #timer #hal #oc2017-03-22 02:04 AM
I don't Cube so don't quite understand what you are trying to accomplish but it sounds like you want to do something beyond the constraints imposed by Cube. You might be better off not using it at all.
I am not sure this is what you want, but if you want to start a timer upon an input capture (the word 'capture' is used for input, 'compare' for output) event, you should set up CH1 for capture, CH2-4 for compare, TIMx_PSC/TIMx_ARR as needed, but *don't* enable the timer by setting TIMx_CR1.CEN; then set trigger source to CH1 by setting TIMx_SMCR.TS to 0b101: Filtered Timer Input 1 (TI1FP1), and set slave mode to Trigger by setting TIMx_SMCR.SMS to 0b110. After a pulse arrives to CH1, the timer starts automatically without any need to do it in a CH1-triggered interrupt.
JW