Elapsed time capture is working well on the TM4C123G Launchpad, except for that the counter is not resetting after a capture event. I understand that this counter register reset is not automatic. From the datasheet page 715:
"After an event has been captured, the timer does not stop counting. It continues to count until the
TnEN bit is cleared."
So I inserted a command to clear the counter by using the TimerLoadSet command in the ISR, but the counter continues on where it left off after the capture event. Here is my complete code:
#include <stdint.h> #include <stdbool.h> #include "inc/tm4c123gh6pm.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" #include "driverlib/pin_map.h" extern void WTimer0IntHandler(void); uint32_t period_value; int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //40 MHz SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_4); GPIOPinConfigure(GPIO_PC4_WT0CCP0); SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); TimerConfigure(WTIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP); TimerControlEvent(WTIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerIntEnable(WTIMER0_BASE, TIMER_CAPA_EVENT); TimerIntClear(WTIMER0_BASE, TIMER_CAPA_EVENT); IntEnable(INT_WTIMER0A); IntMasterEnable(); TimerEnable(WTIMER0_BASE, TIMER_A); while(1) { } } void WTimer0IntHandler(void) { TimerIntClear(WTIMER0_BASE, TIMER_CAPA_EVENT); period_value = TimerValueGet(WTIMER0_BASE, TIMER_A); TimerLoadSet(WTIMER0_BASE, TIMER_A, 0); }
In a watch window I could see period_value increase after each capture, but the input at pin PC4 is a constant pulse width so period_value should likewise be constant. Likewise WTIMER0_TIMER_TAV also constantly increased after each capture event in the Memory Browser.
The TimerLoadSet description in the API page 549 says:
"This function configures the timer load value; if the timer is running then the value is immediately loaded into the timer."
So I should not have to stop the timer to reset it, yet it will not reset. Please advise.