2020-08-19 05:23 AM
Hi,
If you set a timer in Output Compare in Mode "Toggle" and assing a Chanel to a pin of your uC you can make it toggle when CCRx == CNT. That works just fine, as expected.
My question is: when you configure the Mode of that Channel to “Active on Match�?, how can you clear that pin to low again? It keeps allways Active. To clear the pin I tried:
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, 0) inside the callback void HAL_TIM_OC_DelayElapsedCallback , and also in the main(), but it does not work. Is there any way?
The same aplies for the mode “Inactive Level on Match�?.
Thanks a lot guys,
Solved! Go to Solution.
2020-08-19 05:45 AM
You need to modify the TIMx->CCMRx_OCxM bits to what you want. The pin cannot be controlled directly.
You probably want to use the "force active/inactive level" options.
You could also reinitialize the pin as GPIO and control it that way.
2020-08-19 05:45 AM
You need to modify the TIMx->CCMRx_OCxM bits to what you want. The pin cannot be controlled directly.
You probably want to use the "force active/inactive level" options.
You could also reinitialize the pin as GPIO and control it that way.
2020-08-19 08:26 AM
Thanks!
2021-02-15 01:51 PM
Hey Fèlix, did you find any way to do that? I'm looking for exactly the same thing. :) And I don't know how to do it from the answer above.
greetings and thanks,
André
2021-02-15 02:34 PM
For example, setting CH1 on TIM2 to Force inactive:
TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M) | (4 << TIM_CCMR1_OC1M_Pos);
JW
2021-02-15 11:15 PM
Hey, thanks for your answer JW! That *kinda* works.
But than it's LOW forever. I would like to set it to LOW, so next time it matches TIM2->CNT it becomes active again. "Force inactive" disables the "Active on match". I don't know how I can achieve this. Is there some trigger I have to reset? I did already read through the docs about timer, but I don't know what to look for exactly.
greetings and thanks,
André
2021-02-16 01:40 AM
I also tried to clear those flags, but it doesn't change anything:
__HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1);
__HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1OF);
greetings,
André
2021-02-16 02:18 PM
> But than it's LOW forever. I would like to set it to LOW, so next time it matches TIM2->CNT it becomes active again.
Well, then after you set it to Force inactive, set it again to Active on match.
What's the problem with that?
> I also tried to clear those flags
They have nothing to do with the channel output (TIMx_CH1 pin).
Read the TIM chapter in RM.
JW