This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM PWM 输入捕获的问题

请教论坛里的前辈

这是我写的一个pwm捕获中断程序,四轴遥控解码用的

我配置的系统时钟80M,定时器配置的是40Hz,单次计时最长25ms,用来计时高电平时间的长短

向上技数,在中断中会更改下次触发中断的条件,理论上应该没问题,但读出来的数据是错误并且不稳定,哪位能帮我看一下吗,谢谢了

uint32_t     Rc_Pwm_In[4];
int main(void)
{    
    SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//    GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
//    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_6,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
    
    //Configures the alternate function of a GPIO pin
    GPIOPinConfigure(GPIO_PB6_T0CCP0);   
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
 
    //
  TimerLoadSet(TIMER0_BASE, TIMER_A,2000000-1);//40Hz(25ms)
    TimerConfigure(TIMER0_BASE,TIMER_CFG_A_CAP_TIME_UP|TIMER_CFG_SPLIT_PAIR);
    TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
 
    IntEnable(INT_TIMER0A);    
    TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
    //master interrupt enable API for all interrupts
    IntMasterEnable();    
    TimerEnable(TIMER0_BASE, TIMER_A);
    
    while(1)
    {
    }
}

  uint32_t temp_cnt1,temp_cnt1_2;
    uint32_t Count1;
  unsigned char Flag=0;
void Timer0IntHandler(void)
{
    
    TimerIntClear(TIMER0_BASE,TIMER_CAPA_EVENT);
    Count1 = TimerValueGet(TIMER0_BASE, TIMER_A);
    if(GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_6))
    {              
          //比较捕获极性 取反
          TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_NEG_EDGE);
            temp_cnt1 = Count1;
    }
    else
    {        
        //比较捕获极性 取反
        TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
        temp_cnt1_2  = Count1;    
        if(temp_cnt1_2>=temp_cnt1)
                Rc_Pwm_In[0] = (temp_cnt1_2-temp_cnt1);
        else
                Rc_Pwm_In[0] = (2000000-1-temp_cnt1+temp_cnt1_2);       
        
    }
 
}