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.

TM4C129ENCPDT: Timer in capture mode

Part Number: TM4C129ENCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL

Hi,

I was Tring to configure timer4 in capture mode .I was expected an interrupt either in rising or falling edge.but unable to get an interrupt, can some one help me out to slove this issue 

SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

// Enable the peripherals for Timer 4 and GPIO Port M
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);

// Configure GPIO Port M pin 4 as Timer 4A capture input
GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_4);
GPIOPinConfigure(GPIO_PM4_T4CCP0);

// Configure Timer 4A as a capture timer
TimerConfigure(TIMER4_BASE, TIMER_CFG_A_CAP_TIME_UP);

// Set the load value for Timer 4A
TimerLoadSet(TIMER4_BASE, TIMER_A, 0xFFFF);

// Enable Timer 4A capture events on Falling edges
TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);

// Register the interrupt handler for Timer 4A capture event
TimerIntRegister(TIMER4_BASE, TIMER_CAPA_EVENT, Timer4ACaptureIntHandler);

// Enable Timer 4A capture event interrupt
TimerIntEnable(TIMER4_BASE, TIMER_CAPA_EVENT);

// Enable Timer 4A
TimerEnable(TIMER4_BASE, TIMER_A);

// call back function

void Timer4ACaptureIntHandler(void)
{
// Clear the Timer 4A capture event interrupt
TimerIntClear(TIMER4_BASE, TIMER_CAPA_EVENT);
count ++;

}

  • HI,

      First of all, it seems you are using an older version of TivaWare as I see SYSCTL_CFG_VCO_480 in your clock configuration. Please download the latest TivaWare version as it has a example that uses Timer0 to calculate the high phase of a input. The example can be found at C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl\timer_edge_capture.

    I think I also see two issues. You are trying to use timer_A of Timer4 module. But you call:

    TimerConfigure(TIMER4_BASE, TIMER_CFG_A_CAP_TIME_UP);

    instead of:

    TimerConfigure(TIMER4_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP);

    Second, I don't see you call IntEnable(INT_TIMER4A);

  • Hi Charles,

    Thank you for your response.I have tried by resolving the issues mentioned but still didn't getting any response. And i have also tried with latest library and its example , still same in same situation.In this setup i have configured a pwm0 and timer0 from example and pwm output is given to capture pin. Could you please help me to resolve this issue. My aim is to get counts from the capture events on falling edge.

  • Hi,

      Please take a look at this example. It works for me. Just a heads-up, Monday is a US public holiday and my response will be delayed. 

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "utils/ustdlib.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    uint32_t g_ui32SysClock;
    
    uint32_t g_ui32IntCount = 0;
    
    uint32_t g_intFlag = 0;
    
    void
    InitConsole(void)
    {
    	// Enable GPIO port A which is used for UART0 pins.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
    	// Enable UART0 so that we can configure the clock.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
    
    	GPIOPinConfigure(GPIO_PA0_U0RX);
    	GPIOPinConfigure(GPIO_PA1_U0TX);
    
    	// Use the internal 16MHz oscillator as the UART clock source.
    	UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
    
    	// Select the alternate (UART) function for these pins.
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
    	// Initialize the UART for console I/O.
    	UARTStdioConfig(0, 115200, 16000000);
    }
    
    // The interrupt handler for timer 4.
    
    void
    Timer4IntHandler(void)
    {
    	// Clear the timer interrupt.
    	TimerIntClear(TIMER4_BASE, TIMER_CAPA_MATCH);
    
    	g_ui32IntCount+=5;
    
    	g_intFlag = 1;
    
    	// The timer is automatically stopped when it reaches the match value so re-enable it here.
    	TimerEnable(TIMER4_BASE, TIMER_A);
    }
    
    
    int
    main(void)
    {
    
    
    	g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    			SYSCTL_OSC_MAIN |
    			SYSCTL_USE_PLL |
    			SYSCTL_CFG_VCO_480), 120000000);
    
    	// UART Func Call
    	InitConsole();
    
    	UARTprintf("Timer Input Edge Example\n");
    
    	// Enable Timer4 & GPIOM
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
    
    	// Configure PM0 as the CCP0(Timer A) pin for timer 4.
    	GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_4);
    	GPIOPinConfigure(GPIO_PM4_T4CCP0);
    
    	// Enable processor interrupts.
    	IntMasterEnable();
    
    	// Configure the timers in edge count mode.
    	TimerConfigure(TIMER4_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT_UP));
    	TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
    	TimerLoadSet(TIMER4_BASE, TIMER_A,6);
    
    	// Set match to 15 so that after 5 postive edges detected, generate a match interrupt
    	TimerMatchSet(TIMER4_BASE, TIMER_A,5);
    
    	// Setup the interrupt for the edge capture timer.  Note that we
    	// use the capture match interrupt and NOT the timeout interrupt!
    	IntEnable(INT_TIMER4A);
    	TimerIntEnable(TIMER4_BASE, TIMER_CAPA_MATCH);
    
    	// Timer Moudle(Timer A & Timer B) Clock Source Set
    	TimerClockSourceSet(TIMER4_BASE, TIMER_CLOCK_SYSTEM);  // TIMER_CLOCK_PIOSC or  TIMER_CLOCK_SYSTEM
    
    	// Enable the timer.
    	TimerEnable(TIMER4_BASE, TIMER_A);
    
    	// At this point, the timer will count up every time a negative  edge is detected on the relevant pin .
    	while (1)
    	{
    		if (g_intFlag == 1) {
    			UARTprintf("%d Positive edges detected\n", g_ui32IntCount);
    			g_intFlag =0;
    		}
    
    	}
    }

  • Hi Charles,

    Thank you for your response.Let me check with the code your share and will let you know. If i need to modify the code , i need  to convert it to a counter which can count when ever an event occurs say an fall edge may detect and i need to get count.what all changed should  i do?