cancel
Showing results for 
Search instead for 
Did you mean: 

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

Fèlix
Associate II

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,

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

7 REPLIES 7
TDK
Guru

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
Associate II

Thanks!

AFied.1
Associate III

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é

For example, setting CH1 on TIM2 to Force inactive:

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

JW

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é

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é

> 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