STM32mini板TIM1输出互补PWM不成功,请大家帮助一下

2019-08-17 00:54发布

STM32mini板TIM1输出互补PWM不成功,请大家帮助一下。谢谢
TIM1配置如下:
void GPIO_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ,ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void TIM1_Config(void)
{
  TIM_TimeBaseInitTypeDef TIM_BaseInitStructure;
  TIM_OCInitTypeDef TIM_OCInitStructure;
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
 
  //TIM1基本计数器设置
  //f=72000/3600=20kHz
  TIM_BaseInitStructure.TIM_Period = 3600-1;
  TIM_BaseInitStructure.TIM_Prescaler = 0;
  TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_BaseInitStructure.TIM_ClockDivision = 0;
  TIM_BaseInitStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM1, &TIM_BaseInitStructure);
  TIM_ARRPreloadConfig(TIM1, ENABLE);
 
  //TIM1_OC1模块设置(设置1通道占空比)
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 1800;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;   TIM_OC1Init(TIM1,&TIM_OCInitStructure);
  TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
 
  TIM_Cmd(TIM1,ENABLE);
  TIM_CtrlPWMOutputs(TIM1,ENABLE);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。