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.

TM4C123G 捕获高低电平

想求一个捕获某个引脚高低电平持续时间的例子,最好是带详细解析的。我写的程序用信号发生器产生5KHZ,占空比50.1%,峰峰值为3.2V,最大值为3.2V,最小值为-0.1V的方波信号得不到数据。(数据使用示波器测得其中PB6与示波器和信号发生器红脚相连,GND与两个黑脚相连)

#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
float time,time1;
int main(void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    //5分频,使用PLL,外部晶振16M,system时钟源选择 main osc。系统时钟50MHZ
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
        //使能TIMER0 32位(TIMER0A16位+TIMER0B16位)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    //使能GPIOF和GPIOC外设
  //  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
    GPIOPinConfigure(GPIO_PB6_T0CCP0);    //#define GPIO_PC4_WT0CCP0   0x00021007
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);

    TimerConfigure(TIMER0_BASE,TIMER_CFG_A_CAP_TIME_UP|TIMER_CFG_SPLIT_PAIR);//计时捕获模式,上升沿捕获
    TimerConfigure(TIMER0_BASE,TIMER_CFG_B_CAP_TIME_UP|TIMER_CFG_SPLIT_PAIR);

    TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
    TimerControlEvent(TIMER0_BASE,TIMER_B,TIMER_EVENT_NEG_EDGE);

    IntEnable(INT_TIMER0A);
    IntEnable(INT_TIMER0B);

    //使能TIMER0A
    TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
    TimerIntEnable(TIMER0_BASE, TIMER_CAPB_EVENT);

    IntMasterEnable();
    //master interrupt enable API for all interrupts
    TimerEnable(TIMER0_BASE, TIMER_BOTH);

    while(1)
    {
    }
}

void Timer0IntHandler(void)
{


    TimerIntClear(TIMER0_BASE,TIMER_CAPA_EVENT);
    time=TimerValueGet(TIMER0_BASE,TIMER_A) ;


}
void Timer1IntHandler(void)
{


    TimerIntClear(TIMER0_BASE,TIMER_CAPB_EVENT);
    time1=TimerValueGet(TIMER0_BASE,TIMER_B) ;


}


//下面为启动文件中更改部分内容
extern void Timer1IntHandler(void);
extern void Timer0IntHandler(void);



Timer0IntHandler,                      
// Timer 0subtimer A
Timer1IntHandler,                      
// Timer 0 subtimer B