|
新手求助,怎么用TTIMERA和TIMERB同时测量上升沿和下降沿啊
[复制链接]
1芯积分
想用TIMER0来测量高电平的持续时间,现在能读出TIMERA上升沿的定时器数值,却读不出来TIMERB下降沿定时器数值,,求大家帮帮我,,谢谢大家了
楼主程序
#include
#include
#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"
#define GPIO_PB6_T0CCP0 0x00011807
float time,time1;
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//5分频,使用PLL,外部晶振16M,system时钟源选择 main osc。系统时钟40MHZ
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) ;
}
|
|