2019-03-18 04:08 PM
Hello:
There is a post on this same issue titled "TIM16 PWM signal generation...". The fix here was to set the AOE bit in the BDTR register. In that thread they were using LL.
I am having a similar issue where I am unable to get the PWM output signal on PA.6. The code base was generated using CubeMX, this is the initialization code:
#define PULSE1_VALUE (uint32_t)(7999) /* Capture Compare 1 Value */
void MX_TIM16_Init(void)
{
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
htim16.Instance = TIM16;
htim16.Init.Prescaler = (uint32_t)999;
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
htim16.Init.Period = 15999;
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim16.Init.RepetitionCounter = 0;
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim16) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = PULSE1_VALUE;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 0;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_ENABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_MspPostInit(&htim16);
}
The hardware is initialized here:
vovoid HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(tim_baseHandle->Instance==TIM16)
{
/* TIM16 clock enable */
__HAL_RCC_TIM16_CLK_ENABLE();
/* TIM16 interrupt Init */
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
__HAL_RCC_GPIOA_CLK_ENABLE();
/**TIM16 GPIO Configuration
PA6 ------> TIM16_CH1
*/
GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
}
}
Finally in main(), I call the start:
if (HAL_TIM_PWM_Start(&htim16, TIM_CHANNEL_1) != HAL_OK)
{
/* PWM Generation Error */
Error_Handler();
}
As seen in the initialization, I have set the variable sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_ENABLE;
which should be the AOE bit as mentioned in the other post. Yet, there is still no signal from PA6.
Any suggestions?
NB:
I also tried a direct register update before enabling the PWM. Did not help.
TIM16->BDTR |= TIM_BDTR_MOE;
TIM16->BDTR |= TIM_BDTR_AOE;
Solved! Go to Solution.
2019-03-18 07:02 PM
Solved. I had the interrupt enabled for the PWM on the channel. Disabled it and it works OK.
2019-03-18 04:24 PM
Read and check all the relevant GPIO and TIM registers' content.
JW
2019-03-18 05:49 PM
The response I posted was not good information, I will repost again.
2019-03-18 06:47 PM
I generated the code with nothing else and PWM works. Still looking...
2019-03-18 07:02 PM
Solved. I had the interrupt enabled for the PWM on the channel. Disabled it and it works OK.