硬件使用STM32G030C8T6的PA6的AF5功能,即TIM16_CH1驱动一个无源蜂鸣器,输出一个2.7K-2.9K的方波,占空比为50%,始终没有成功,查阅datasheet发现PA6也可以映射AF1功能,即TIM3_CH1,将PWM初始化代码中的TIM16替换为TIM3,正常输出方波。MDK里查看了TIM3和TIM16配置后寄存器,完全一样,再改回TIM16,依然不行。确认了PA6的IO配置,尤其是AF寄存器,均是对的。同样的问题,在G070上验证了一样,也是TIM3能输出PWM而TIM16不行。哪位帮我分析分析,谢过!贴一下TIM3的代码
void TIM3_PWMConfig(void)
{
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
TIM_InitStruct.Prescaler = SystemCoreClock/1000000-1;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 0xAC*2-1; //频率2.9KHz
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM3, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM3);
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH1);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 0xAC;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH1);
LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM3);
LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH1);
LL_TIM_EnableCounter(TIM3);
}
|