打印

用外部中断打开互补输出,为什么互补的输出会有毛刺?

[复制链接]
2794|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
/* TIM1 Peripheral Configuration */

  void TIM_Configuration(void)
  {/* Time Base configuration */
  TIM1_TimeBaseStructure.TIM_Prescaler =71;
  TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM1_TimeBaseStructure.TIM_Period = 1999;
  TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;
  TIM1_TimeBaseStructure.TIM_RepetitionCounter = 0x0;

  TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);

  /* Channel 1, 2,3 and 4 Configuration in PWM mode */
  TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
  TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;                  
  TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
  TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;         
  TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;         

  TIM_OC1Init(TIM1,&TIM1_OCInitStructure);



  /* Automatic Output enable, Break, dead time and lock configuration*/
  TIM1_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
  TIM1_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
  TIM1_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
  TIM1_BDTRInitStructure.TIM_DeadTime = 0x75;
  TIM1_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
  TIM1_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
  TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;

  TIM_BDTRConfig(TIM1,&TIM1_BDTRInitStructure);

  /* TIM1 counter enable */
  TIM_Cmd(TIM1,ENABLE);

  /* Main Output Enable */
  TIM_CtrlPWMOutputs(TIM1,DISABLE);

  while(1)
  {

CCR1_Val=VAL[0];

TIM1->CCR1 = CCR1_Val;

   
Delay(2);


CCR1_Val=VAL[1];
    TIM1->CCR1 = CCR1_Val;

  Delay(2);

    CCR1_Val=VAL[2];
    TIM1->CCR1 = CCR1_Val;
  
  Delay(2);

         


CCR1_Val=VAL[3];
    TIM1->CCR1 = CCR1_Val;
  
Delay(2);


CCR1_Val=VAL[4];
    TIM1->CCR1 = CCR1_Val;
  
Delay(2);
   }



void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  {
  TIM_Cmd(TIM1,ENABLE);
  TIM_CtrlPWMOutputs(TIM1,ENABLE);
  GPIO_SetBits(GPIOC,GPIO_Pin_6);
   }
     EXTI_ClearITPendingBit(EXTI_Line0);
}中断


  void EXTI_Configuration(void)
  {
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0);

  EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  EXTI_GenerateSWInterrupt(EXTI_Line0);

  }

}

QQ截图20111108112930.png (1.23 KB )

QQ截图20111108112930.png
沙发
香水城| | 2011-11-8 11:20 | 只看该作者
你这个帖子与前一个帖子是什么关系?

https://bbs.21ic.com/viewthread.php?tid=282026

使用特权

评论回复
板凳
xiongxingzhi|  楼主 | 2011-11-8 14:06 | 只看该作者
2# 香水城 前一个帖子,是产生波形,这个帖子是控制开关啊

使用特权

评论回复
地板
香水城| | 2011-11-8 14:35 | 只看该作者
用示波器定位一下,看看在产生毛刺的时候你的程序在做什么?

使用特权

评论回复
5
libinxtdj| | 2011-11-10 20:52 | 只看该作者
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;         
  TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;   
      

你这里定义的输出哦度是低有效,什么有定义的空闲状态又是一个高,一个低呢?这不冲突吗?

TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;

你这里为什么要使能自动输出呢?

使用特权

评论回复
6
香水城| | 2011-11-11 10:23 | 只看该作者
TIM_Configuration(void) 里面的 while (1) 是做什么用的?

使用特权

评论回复
7
ti饭饭| | 2013-2-23 09:49 | 只看该作者
仿真很屌

使用特权

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

本版积分规则

0

主题

12

帖子

1

粉丝