cancel
Showing results for 
Search instead for 
Did you mean: 

PWM FORCED ACTIVE

Pablito Parseval
Associate II
Posted on February 15, 2018 at 09:32

Hi All,

in my application, i need sometimes to stop PWM and Force Output to High.

I write this code but seem not run good. 

void forcePwmActive(void)

{

   TIM_OC_InitTypeDef configOC;

   HAL_TIM_PWM_Stop(&htim21, TIM_CHANNEL_2);

   configOC.OCMode = TIM_OCMODE_FORCED_ACTIVE;

   configOC.Pulse = 0;

   configOC.OCPolarity = TIM_OCPOLARITY_HIGH;

   configOC.OCFastMode = TIM_OCFAST_DISABLE;

   if(HAL_TIM_OC_ConfigChannel(&htim21, &configOC, TIM_CHANNEL_2) != HAL_OK)

   {

      _Error_Handler(__FILE__, __LINE__);

   }

}

Can anyone help?

5 REPLIES 5
Posted on February 15, 2018 at 09:51

What are the symptoms?

What's the content of TIM21 registers?

JW

Posted on February 15, 2018 at 11:18

The TIM Setup is the following:

void systemConfig_TIM21Setup(void)

{

   TIM_ClockConfigTypeDef sClockSourceConfig;

   TIM_MasterConfigTypeDef sMasterConfig;

   TIM_OC_InitTypeDef sConfigOC;

   htim21.Instance = TIM21;

   htim21.Init.Prescaler = 0;

   htim21.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED3;

   htim21.Init.Period = 16000;

   htim21.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

   if (HAL_TIM_Base_Init(&htim21) != HAL_OK)

   {

   _Error_Handler(__FILE__, __LINE__);

   }

   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

   if (HAL_TIM_ConfigClockSource(&htim21, &sClockSourceConfig) != HAL_OK)

   {

      _Error_Handler(__FILE__, __LINE__);

   }

   if (HAL_TIM_PWM_Init(&htim21) != HAL_OK)

   {

      _Error_Handler(__FILE__, __LINE__);

   }   

   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

   if (HAL_TIMEx_MasterConfigSynchronization(&htim21, &sMasterConfig) != HAL_OK)

   {

      _Error_Handler(__FILE__, __LINE__);

   }

      sConfigOC.OCMode = TIM_OCMODE_PWM1;

      sConfigOC.Pulse = 0;

      sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

      sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

   if (HAL_TIM_PWM_ConfigChannel(&htim21, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

   {

      _Error_Handler(__FILE__, __LINE__);

   }

   HAL_TIM_MspPostInit(&htim21);

}

The effect is that if i measure with the oscilloscope the PWM output, is not forced to HIGH.

Pablito Parseval
Associate II
Posted on February 15, 2018 at 13:19

Like you can see in the image below, the CCMR1 register have the bit [14:12] set to 101 like required 

in the datasheet.

0690X00000609loQAA.png
Posted on February 15, 2018 at 13:08

What's the content of TIM21 registers (after the 'forcing' routine)?

Read them out in debugger and post.

JW

Posted on February 15, 2018 at 14:30

Yes indeed, but also CCER is all zero which means the CCxE bits are cleared.

Try to set them.

JW