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.

TM4C123GH6PM: Timer in Input Edge Time Mode

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL

Following is the code where i have configured the timer0 of tm4c123gh6pm in Input Edge Time Mode. I am triggering events using the on-board switch of ek-tm4c123gxl. Events are detected but when i press the button. But i am not able to read the current value of  timer  using TimerValueGet() API.  Is there any other API that returns the current value of timer.

#include<stdint.h>
#include<stdbool.h>
#include"driverlib/sysctl.h"
#include"driverlib/gpio.h"
#include"driverlib/interrupt.h"
#include"driverlib/timer.h"
#include"driverlib/pin_map.h"
#include"inc/tm4c123gh6pm.h"
#include"inc/hw_memmap.h"
uint32_t a=0,b;
int main(void) {
SysCtlClockSet(SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_SYSDIV_5);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinConfigure(GPIO_PB6_T0CCP0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_CAP_TIME_UP);
TimerLoadSet(TIMER0_BASE, TIMER_A, 65000);
TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE,TIMER_CAPA_EVENT);
TimerEnable(TIMER0_BASE,TIMER_A);

while(1){
b=TimerValueGet(TIMER0_BASE,TIMER_A);
SysCtlDelay(100);
}
}

void timer0_isr(void)
{
a++;
TimerIntClear(TIMER0_BASE,TIMER_CAPA_EVENT);
}

  • "But i am not able to read the current value of  timer  using TimerValueGet() API."

    that means?

  • Hi Danny F,

    As mentioned in the datasheet of TM4C123GH6PM

    In  input edge time mode, the timer is initialized to the value loaded in the GPTMTnILR and GPTMTnPR registers when counting down and 0x0 when counting up. In this mode, the GPTMTnR and GPTMTnPS registers hold the time at which the selected input event occurred while the GPTMTnV and GPTMTnPV registers hold the free-running timer value and the free-running prescaler value. After an event has been captured, the timer does not stop counting. It continues to count until the TnEN bit is cleared. When the timer reaches the timeout value, it is reloaded with 0x0 in up-count mode and the value from the GPTMTnILR and GPTMTnPR registers in down-count mode.

    As TimerValueGet() API is supposed to return the current value of the timer, i am capturing that return value in  b;

    while(1){
    b=TimerValueGet(TIMER0_BASE,TIMER_A);
    SysCtlDelay(100);
    }

    Despite Setting a breakpoint at TimerValueGet() to observe the updated values, i am reading 0 in b always.

  • Make sure the time base is running, capturing is enabled and the input pin is correctly configured, in that order. Compare the registers vs. The datasheet and see if any values are unexpected.

    Forget about the api for now. Start with the registers always.

  • Thank you Danny.