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.

TM4C1294NCPDT: Input Edge-Time mode does not work as expected

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

Hi, Mr Expert

    I configure the General Purpose Timer 1 to work in Input Edge-Time mode to capture rising edge on T1CPP0 assigned to pin PD2, but when the low level pulse is applied to the PD2 pin, the relevant interrupt is not triggered.

    Below are the code for Timer1 initializing and GPIO pin PD2 configuration.

    ......
    #define AFSEL_T1CCP0    4
    #define PMC2_T1CCP0     0x30
    #define DEN_T1CCP0      4
    #define ODR_T1CCP0      4

    ......

   //Initialize Timer1_A to Input Edge-Time Mode
    HWREG(GPIO_PORTD_BASE + GPIO_O_AFSEL) |= AFSEL_T1CCP0;
    HWREG(GPIO_PORTD_BASE + GPIO_O_PCTL) |= PMC2_T1CCP0;        //set PD0 to T0CCP0 function, use PWM function as DQ output
    HWREG(GPIO_PORTD_BASE + GPIO_O_DEN) |= DEN_T1CCP0;

    HWREG(SYSCTL_RCGCTIMER) |= SYSCTL_RCGCTIMER_R1;

    HWREG(TIMER1_BASE + TIMER_O_CTL) &= ~TIMER_CTL_TAEN;
    HWREG(TIMER1_BASE + TIMER_O_CFG) = TIMER_CFG_16_BIT;
    HWREG(TIMER1_BASE + TIMER_O_TAMR) = TIMER_TAMR_TACMR | TIMER_TAMR_TAMR_CAP | TIMER_TAMR_TACDIR;     //Timer counts up from 0
    HWREG(TIMER1_BASE + TIMER_O_CTL) |= TIMER_CTL_TAEVENT_BOTH;
    HWREG(TIMER1_BASE + TIMER_O_TAPR) = 0xFF;
    HWREG(TIMER1_BASE + TIMER_O_TAILR) = 0xFFFF;

    bBitPatternRecognized = false;
    ui32BitLength = 0;
    HWREG(TIMER1_BASE + TIMER_O_IMR) = TIMER_IMR_CAEIM;
    TimerIntRegister(TIMER1_BASE, TIMER_A, Timer1IntHandler);

    ......

    After I set the TAEN bit, and pull down the voltage on PD2 and then release voltage on PD2 to high.

    HWREG(TIMER1_BASE + TIMER_O_CTL) |= TIMER_CTL_TAEN;   

    The interrupt has not triggered as expected. Could you help to check if I missed something on the pin configuration?
    bBitPatternRecognized = false;
    ui32BitLength = 0;
    HWREG(TIMER1_BASE + TIMER_O_IMR) = TIMER_IMR_CAEIM;
    TimerIntRegister(TIMER1_BASE, TIMER_A, Timer1IntHandler);

EV2500_TM4C_003

  • Hi Steve,

      Is there any reason why you are not using the TivaWare for developing your software? Writing the DRM (direct register manipulation) style is very prone to mistakes. 

      Below is an example you can reference.   If you insist to use DRM then please look at the source code of each function and see how they configure the timer. 

        // Enable and configure Timer0 peripheral.
        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    
        // Initialize timer A and B to count up in edge time mode
        TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_CAP_TIME_UP));
    
        // Timer a records pos edge time and Timer b records neg edge time
        TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
        TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_NEG_EDGE);
    
        //set the value that the timers count to (0x9C3F = 39999)
        //CO2 sensor outputs 1khz pwm so with mcu at 40Mhz, timers should stay in sync with CO2 output
        TimerLoadSet(TIMER0_BASE, TIMER_BOTH, 0x9C3F);
    
        //Configure the pin that the timer reads from (PD0)
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        GPIOPinConfigure(GPIO_PD0_T0CCP0);
        GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0);
    
    
        // Registers a interrupt function to be called when timer b hits a neg edge event
        IntRegister(INT_TIMER0A, duty_cycle);
        // Makes sure the interrupt is cleared
        TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT);
        // Enable the indicated timer interrupt source.
        TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
        // The specified interrupt is enabled in the interrupt controller.
        IntEnable(INT_TIMER0A);

  • Hi, Charles

        Thanks for your reply, I use the DRM because it looks more strait forward to me, also, I remember using TivaWare functions in the interrupt handler causes warnings

        I would peruse your code and check what I am missing in my code

    Thanks

    Steven

  • Hi, Charles

        I still have several questions to your reference code:

        1: In the function of TimerConfigure, I found below code which always sets the bit of TnPWMIE bit for TAMR or TBMR, since the purpose is to set Input Edge-Time mode, why should TnPWMIE bit set in the TnMR register?

        if(NEW_TIMER_CONFIGURATION)
        {
            HWREG(ui32Base + TIMER_O_TAMR) = (((ui32Config & 0x000f0000) >> 4) |
                                              (ui32Config & 0xff) |
                                              TIMER_TAMR_TAPWMIE);
            HWREG(ui32Base + TIMER_O_TBMR) = (((ui32Config & 0x00f00000) >> 8) |
                                              ((ui32Config >> 8) & 0xff) |
                                              TIMER_TBMR_TBPWMIE);
        }
        else
        {
            HWREG(ui32Base + TIMER_O_TAMR) = ((ui32Config & 0xff) |
                                              TIMER_TAMR_TAPWMIE);
            HWREG(ui32Base + TIMER_O_TBMR) = (((ui32Config >> 8) & 0xff) |
                                              TIMER_TBMR_TBPWMIE);
        }

        2: In the function     GPIOPinTypeTimer(), I found below code:

        //
        // Set the pad(s) for standard push-pull operation.
        //
        GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);

        Does this indicate the pin can only be set to standard push pull mode if it is configured as TxCCPx pin?

  • Hi, Charles

        I need to configure Timer1_A to Input Edge Time Mode and detect the time on the positive edge on pin PD2, with the reference code you provided above, I composed the code as below for Timer1_A, but I still can not have the Timer1_A interrupt triggered, please can you further help to check if there would be something wrong with the code below:

        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
        TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP));
        TimerControlEvent(TIMER1_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        GPIOPinConfigure(GPIO_PD2_T1CCP0);
        GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_2);

        // Registers a interrupt function to be called when timer b hits a neg edge event
        IntRegister(INT_TIMER1A, Timer1IntHandler);
        // Makes sure the interrupt is cleared
        TimerIntClear(TIMER1_BASE, TIMER_CAPA_EVENT);
        // Enable the indicated timer interrupt source.
        TimerIntEnable(TIMER1_BASE, TIMER_CAPA_EVENT);
        // The specified interrupt is enabled in the interrupt controller.
        IntEnable(INT_TIMER1A);

  • Hi Steven,

      I didn't see you enable the NVIC interrupt at the processor level. Please call IntMasterEnable() to enable the processor interrupt. Let me know if this will solve your problem. 

  • Hi, Charles

        I add IntMasterEnable function after the Timer1 initializing finished, but the interrupt still could not be triggered.

        I also checked lsb in PRIMASK register, the bit is always cleared before and after IntMasterEnable function is called, this indicates the NVIC interrupt is already enabled in previous code. Could there be any other reason for the Timer Interrupt failed to be triggered

  • Hi Steve,

      There is a edge-time CCS project example in TivaWare library. You can find the example in C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl\timer_edge_capture. Can you please try this example as is and see if you can get it to work. Once working, you can modify for Timer1. I think what you are missing is the below two lines. Anyway, try the example first and see if you can get it to work. 

        MAP_TimerLoadSet(TIMER1_BASE, TIMER_BOTH, 0xFFFF);
        MAP_TimerPrescaleSet(TIMER1_BASE, TIMER_BOTH, 0xFF);
  • Hi, Charles

        Thanks for your support for this case, now the cause of this issue has been identified!