cancel
Showing results for 
Search instead for 
Did you mean: 

TIM8_CH2N for PWM

Dilbert K
Senior

I try to setup the PB0 for PWM mode to drive a LED.

When I use the TIM3_CH3, it is working with the following code.

But it does not work for TIM8_CH2N.

I suppose something to do with the "N" but could not find out what in HAL code should be changed.

TIM_OC_InitTypeDef *sConfig;
 
sConfig->OCMode    = TIM_OCMODE_PWM1;		// PWM mode 1
 
sConfig->OCPolarity  = TIM_OCPOLARITY_HIGH;
 
sConfig->OCFastMode  = TIM_OCFAST_DISABLE;
 
sConfig->OCNIdleState = TIM_OCNIDLESTATE_RESET;
 
sConfig->OCNPolarity = TIM_OCNPOLARITY_HIGH;
 
sConfig->OCIdleState = TIM_OCIDLESTATE_RESET;
 
sConfig->Pulse 		 = 0;
 
HAL_TIM_PWM_ConfigChannel(&TimHandle, sConfig, timChannel);

2 REPLIES 2

> ​I suppose something to do with the "N"

Maybe. It needs TIMx_CCER.CCxNE to be set. I don't use Cube but it's open source do you can look it up which function sets it. Maybe in the "extended" ​functions/file.

TIM8 ​is also an Advanced timer and needs TIMx_BDTR.MOE to be set.

JW​

Dilbert K
Senior

Thanks for the hints. Found the HAL code to control it.

when using TIM8_CH2N, need to call the "TIMEx"

HAL_TIMEx_PWMN_Start()
 
HAL_TIM_PWM_Start()