Skip to main content
Fèlix
Associate
Aug 19, 2020 12:23 PM UTC
Solved

How to clear Output Compare Timer pin set to mode "Active Level on Match"

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,

This topic has been closed for replies.
TDK
TDKBest answer
Aug 19, 2020 12:45 PM UTC

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.

0693W000003PlwTQAS.png

"If you feel a post has answered your question, please click ""Accept as Solution""."

7 replies

TDK
TDKBest answer
Aug 19, 2020 12:45 PM UTC

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.

0693W000003PlwTQAS.png

"If you feel a post has answered your question, please click ""Accept as Solution""."
Fèlix
FèlixAuthor
Associate
Aug 19, 2020 3:26 PM UTC

Thanks!

AFied.1
Associate II
Feb 15, 2021 9:51 PM UTC

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é

waclawek.jan
Super User
Feb 15, 2021 10:34 PM UTC

For example, setting CH1 on TIM2 to Force inactive:

TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M) | (4 << TIM_CCMR1_OC1M_Pos);

JW

AFied.1
Associate II
Feb 16, 2021 7:15 AM UTC

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é

waclawek.jan
Super User
Feb 16, 2021 10:18 PM UTC

> 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