2018-02-15 12:32 AM
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?
2018-02-15 12:51 AM
What are the symptoms?
What's the content of TIM21 registers?
JW
2018-02-15 03:18 AM
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.
2018-02-15 04:19 AM
Like you can see in the image below, the CCMR1 register have the bit [14:12] set to 101 like required
in the datasheet.
2018-02-15 05:08 AM
What's the content of TIM21 registers (after the 'forcing' routine)?
Read them out in debugger and post.
JW
2018-02-15 06:30 AM
Yes indeed, but also CCER is all zero which means the CCxE bits are cleared.
Try to set them.
JW