打印
[其他ST产品]

STR736 TIMER0的OCMPA0输出脉冲问题

[复制链接]
2265|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
maxtech|  楼主 | 2007-8-12 20:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STR736 TIMER0的OCMPA0输出脉冲,设置如下:
      GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_AF_PP;
      GPIO_InitStructure1.GPIO_Pins = GPIO_PIN_8 | GPIO_PIN_9;
      GPIO_Init (GPIO1, &GPIO_InitStructure1);

    TIM0_InitStructure.TIM_Clock_Source = TIM_CLK_INTERNAL;
    TIM0_InitStructure.TIM_Prescaler = 0x02;
    TIM0_InitStructure.TIM_Mode = TIM_OCM_CHANNELA;
    TIM0_InitStructure.TIM_OCA_Modes = TIM_Wave;
    TIM0_InitStructure.TIM_Clock_Edge = TIM_Rising;
    TIM0_InitStructure.TIM_Pulse_Level_A = TIM_High;
    TIM0_InitStructure.TIM_Pulse_Length_A = 0x8A00;
      TIM_Init (TIM0, &TIM0_InitStructure);
      TIM_CounterCmd(TIM0, TIM_START);

使用以下程序进行电平切换:
  while(TRUE){
       if(TIM_FlagStatus ( TIM0, TIM_FLAG_OCA))
        TIM_CounterCmd(TIM0, TIM_STOP); 
        n1=~n1;
        n1=n1&0x01;
        if(n1==0) 
            TIM0_InitStructure.TIM_Pulse_Level_A = TIM_Low;
        else 
            TIM0_InitStructure.TIM_Pulse_Level_A = TIM_High;
        TIM_FlagClear (TIM0, TIM_FLAG_OCA);  
          TIM_Init (TIM0, &TIM0_InitStructure);
          TIM_CounterCmd(TIM0, TIM_START);
    }
结果是脉冲是有输出,但长度不一样,请指教.
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

17

帖子

0

粉丝