打印

[请教]STM32F103 TIM1 输出PWM波不互补问题

[复制链接]
7723|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
afuliu|  楼主 | 2012-8-2 16:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
使用STM32F103 TIM1 输出PWM波不互补,channel 1和channel 1N的波形一样,不知道什么原因。
程序
void PWM_Config(void)
{
  
       GPIO_InitTypeDef GPIO_InitStructure;
/////////////////IO Config//////////////////////////////////////////
//4.<PA8--PA10> PWM(TIM1_CH1 C+,TIM1_CH2 B+,TIM1_CH3 A+)  ->BLMOTOR
       GPIO_InitStructure.GPIO_Pin = PWM_CP_PIN|PWM_BP_PIN|PWM_AP_PIN;
       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
       GPIO_Init(GPIOA, &GPIO_InitStructure);  
      
//10.<PB13--PB15> PWM(TIM1_CH1N C-,TIM1_CH2N B-,TIM1_CH3N A-)  ->BLMOTOR
       GPIO_InitStructure.GPIO_Pin = PWM_CN_PIN|PWM_BN_PIN|PWM_AN_PIN;
       GPIO_Init(GPIOB, &GPIO_InitStructure);
      
//7.<PB0,PB1,PB12> BC,AC,AB (EXINT) ->BLMOTOR  检测电机当前状态
      
/////////////////Timer1 Config//////////////////////////////////////////
      
  /* Time Base configuration */
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef   TIM_OCInitStructure;
  TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
  
  TIM_DeInit(TIM1);               //重设缺省值
  
  TIM_TimeBaseStructure.TIM_Prescaler = 0;    //预分频(时钟分频)72M/(0+1)=72M
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;   //向上计数模式
  TIM_TimeBaseStructure.TIM_Period = 9000-1;                    //装载值 72M/9000 = 8k(频率)
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;       //不分割               
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
  
  /* Channel 1 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 = 3000-1;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCPolarity_Low;//TIM_OCNPolarity_Low;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Set;//TIM_OCNIdleState_Set;
//配置CCR1
  TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  
  /* TIM1 counter enable */
  TIM_Cmd(TIM1, ENABLE);
  /* Main Output Enable */
  TIM_CtrlPWMOutputs(TIM1, ENABLE);   
  
      
}
沙发
learnxp| | 2012-12-20 22:39 | 只看该作者
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
        TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;         
        TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
        TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;         
试一试这4句

使用特权

评论回复
板凳
afuliu|  楼主 | 2013-7-19 16:18 | 只看该作者
TIM_OCInitStructure.TIM_OCPolarity =   TIM_OCPolarity_High;
       TIM_OCInitStructure.TIM_OCNPolarity =  TIM_OCNPolarity_High;
       TIM_OCInitStructure.TIM_OCIdleState =  TIM_OCIdleState_Reset;
       TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;

就可以了。

使用特权

评论回复
地板
afuliu|  楼主 | 2013-7-19 16:19 | 只看该作者
learnxp 发表于 2012-12-20 22:39
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
        TIM_OCInitStructure.TIM_OCNPolarity = T ...

多谢!

使用特权

评论回复
5
crazy2012| | 2013-8-27 23:18 | 只看该作者
afuliu 发表于 2013-7-19 16:19
多谢!

楼主,能否说说输出极性,空闲极性到底指什么啊,示波器看波形和我想象的不一样啊

使用特权

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

本版积分规则

2

主题

22

帖子

3

粉丝