打印
[STM32F1]

stm32f103VCT6 定时器TIM1输出PWM 一直是低电平

[复制链接]
1635|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Rayyyy|  楼主 | 2015-11-28 23:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这个是买开发板配套的软件,用定时器TIM1输出PWM。但是我用逻辑分析仪仿真的时候一直都是低电平,不会跳变这个为什么啊。
下面是代码。
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;

。。。
void GPIO_Configuration(void)
{                       

               
                /* GPIOA Configuration: Channel 1, 2, 3 and 4 Output */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOA, &GPIO_InitStructure);
                GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
               

                /* GPIOB Configuration: Channel 1N, 2N and 3N Output */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOB, &GPIO_InitStructure);

                /* GPIOB Configuration: BKIN pin */   
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOB, &GPIO_InitStructure);

}


u16 capture = 0;
u16 CCR1_Val = 1800;      
u16 CCR2_Val = 900;      
u16 CCR3_Val = 450;        

void TIM_Configuration()
{
        TIM_DeInit(TIM1);  
        /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 3600-1;
        TIM_TimeBaseStructure.TIM_Prescaler = 0;
        TIM_TimeBaseStructure.TIM_ClockDivision = 0;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
        TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
       
        /* Channel 1,2,3 and 4 Configuration in PWM mode */
        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 = CCR1_Val;

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;

  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;         

  TIM_OC1Init(TIM1,&TIM_OCInitStructure);

  TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
  TIM_OC2Init(TIM1,&TIM_OCInitStructure);

  TIM_OCInitStructure.TIM_Pulse = CCR3_Val;
  TIM_OC3Init(TIM1,&TIM_OCInitStructure);

  /* Automatic Output enable, Break, dead time and lock configuration */
  TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
  TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;


  TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
  TIM_BDTRInitStructure.TIM_DeadTime = 0x75;  
  TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;  

  TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
  TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
  TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
       
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);

。。。
}
沙发
宽衣解吊带| | 2020-2-2 17:59 | 只看该作者
楼主解决了没有,现在我的F103R8T6遇到同样的问题,不发PWM的时候是低电平。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝