Skip to main content
Fèlix
Associate
August 19, 2020
Solved

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

  • August 19, 2020
  • 5 replies
  • 4667 views

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.
Best answer by TDK

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

5 replies

TDK
TDKBest answer
August 19, 2020

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
August 19, 2020

Thanks!

AFied.1
Associate II
February 15, 2021

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
February 15, 2021

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
February 16, 2021

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
February 16, 2021

> 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