void EF_void_InputCapture_Init(void) { //give clock to it's peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER3); SysCtlDelay(5); //give clock to GPIO peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlDelay(5); /* use PD2 as CCP */ GPIOPinConfigure(GPIO_PD2_WT3CCP0); SysCtlDelay(5); GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_2); TimerConfigure(WTIMER3_BASE, TIMER_CFG_A_CAP_TIME_UP|TIMER_CFG_SPLIT_PAIR); TimerControlEvent(WTIMER3_BASE, TIMER_A, TIMER_EVENT_BOTH_EDGES); /* pre-scaler */ TimerPrescaleSet (WTIMER3_BASE, TIMER_A , 64- 1 ); TimerIntEnable(WTIMER3_BASE, TIMER_CAPA_EVENT ); } void EF_BOOLEAN_InputCapture_GetPulse(uint32_t* Pulse_ptr) { /* to save the first edge time in it */ uint32_t Pulse_FirstEdge = 0; TimerEnable(WTIMER3_BASE, TIMER_A); /* make Input capture unstuck + Wait for the wanted Edge */ while( (TimerIntStatus(WTIMER3_BASE , 0) != TIMER_CAPA_EVENT ) ); /* get the time of first edge */ Pulse_FirstEdge = TimerValueGet(WTIMER3_BASE, TIMER_A); /* clear flag by write one in it */ TimerIntClear(WTIMER3_BASE, TIMER_CAPA_EVENT); while( (TimerIntStatus(WTIMER3_BASE,0) != TIMER_CAPA_EVENT ) ); /* get the pulse by subtract the Second Edge from First Edge*/ *Pulse_ptr = TimerValueGet(WTIMER3_BASE, TIMER_A); *Pulse_ptr = -Pulse_FirstEdge + *Pulse_ptr ; /* clear flag by write one in it */ TimerIntClear(WTIMER3_BASE, TIMER_CAPA_EVENT); }