cancel
Showing results for 
Search instead for 
Did you mean: 

Does STM32L412 TIM2 output comparator support combined-PWM mode?

DGrif.3
Associate II

I'm unsuccessfully trying to put STM32L412 TIM2 output comparator into combined-PWM mode via the STM32CubeIDE (ioc GUI). Can I confirm that this functionality exists in this device and for this particular timer? And if it does, is there a trick for making it appear as a selectable option in the IDE? I can see Combined PWM options for this timer but they all seem to relate to timer input rather than timer output.

5 REPLIES 5

There is nothing in RM0394 which would indicate that the 'L412 would not have Combined PWM modes available in TIM2, see TIMx_CCMRx description of TIM2/TIM3 chapter. Also I don't think there is anything which would link Combined PWM with Input Capture.

Instead of fighting the clicky IDE, you can try to program this directly in registers. Timers are not that complicated.

JW

DGrif.3
Associate II

Thank you for taking the time to reply. I appreciate it.

Yes I think I will go the code/registers route instead of via the GUI. This unhelpfully/confusingly just gave me the following options for Combined Channels whatever I tried:

Disable

Encoder Mode

PWM Input on CH1

PWM Input on CH2

XOR On/Hall Sensor Mode

For starter, you can try to configure the two neighbouring channels independently for plain PWM in the clicky, and then manually overwrite TIMx_CCMRx_OCxM of one of them for the Combined PWM mode. For extra fun, you can do this without writing any code, simply in the debugger, while observing the effect on the output pins.

Note, that the OCxM field is for historical reasons non-continuous

0693W00000aJL3mQAG.png 

JW

DGrif.3
Associate II

On the related area of the GPIO pins. I'm trying to generate normal PWM on TIM2_CH1 and combined-PWM on TIM2_CH3. However, the pins just float despite my attempt to configure them for alternate function. Does the following look sensible, if not then what's my silly mistake? Thank you in advance.

GPIO_InitTypeDef GPIO_InitStruct = {0};

 /*Configure GPIO pin : PA0 (TIM2_CH1) */

 GPIO_InitStruct.Pin  = GPIO_PIN_0;

 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; // see STM32L412xx datasheet

 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /*Configure GPIO pin : PB10 (TIM2_CH3) */

 GPIO_InitStruct.Pin  = GPIO_PIN_10;

 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; // see STM32L412xx datasheet

 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

Verify connection by setting them as plain GPIO output and toggling and observing output.

Read out and check/post GPIO and TIM registers content.

Clock for GPIO and TIM was enabled in RCC?

JW