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: TIVA TM4C1294 configuring single 24 bit capture counter.

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

 

I am using ccs 6.1.2 TIRTOS 2.16.0.08, compiler 5.2.7 and a TM4C1294NCPDT micro on a TIVA eval board part number EK-TM4C1294XL

I would like to configure a timer for counting pulses on an input pin of the micro. I would like to use the full width timer since I would like to use more than 16 bits for more than 65535 events. I read in input Edge count mode, I can only use 24 bits (section 13.3.3.3 of the CPU doc)

Assuming I am using Timer2, the pin on the eval board I would use to count pulses is PA4.

When I run my code below, I think the timer is free running and not counting actual pulses because if I don’t pulse the input pin PA4, the value I read from the timer is still changing. Below are two functions, one doer the read and the other does the init and configuration.

The questions I have are:

1)     Why does this not count the pulses on the PA4 pin and appear to free run.

2)     The IRQ callback is never called, I don’t know why.

3)     It’s unclear to me how to handle the full width timer, should I be using TIMER_BOTH or TIMER_A etc?

Thanks,

Doug

unsigned long Timer2ReadCount(void)

{

   unsigned long timerCount;

   timerCount = TimerValueGet(TIMER2_BASE, TIMER_A);

   return timerCount;

}

void timerCounterInit(void) // uses pin PA4 on the Tiva CPU (See CPU doc P 1808/1890)

{

   Hwi_Handle myHwi;

   Hwi_Params hwiParams;

   Error_Block eb;

 

   MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // enable the timer.

   MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // enable the GPIO used for the pin.

 

 

   MAP_GPIOPinConfigure(GPIO_PA4_T2CCP0); // set the alternate function

   GPIOPinTypeTimer(GPIO_PORTA_BASE, GPIO_PIN_4); // configure the pin as a timer      //GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);

 

   MAP_TimerConfigure(TIMER2_BASE, (TIMER_CFG_A_CAP_COUNT)); // count down Page 503/650 Rom Document

 

   MAP_TimerControlEvent(TIMER2_BASE, TIMER_BOTH, TIMER_EVENT_POS_EDGE); // config the edge.

   MAP_TimerLoadSet(TIMER2_BASE, TIMER_BOTH, 0xffff); //

 

// install the IRQ

   Error_init(&eb);

   Hwi_Params_init(&hwiParams);

   myHwi = Hwi_create(INT_TIMER2A_TM4C123, Timer2IntHandler, &hwiParams, &eb);

 

   if(NULL == myHwi)

   {

       printf ("Error installing IRQ %d for Timer\n", INT_TIMER2A_TM4C123);

   }

   Else

   {

       printf ("OK installing IRQ %d for Timer\n", INT_TIMER2A_TM4C123);

   }

 

   MAP_TimerIntEnable(TIMER2_BASE, TIMER_CAPA_EVENT | TIMER_CAPA_MATCH); // select the IRQ's to enable.

   ROM_IntEnable(INT_TIMER2A_TM4C129 ); // enable the IRQ 39. ROM user doc page 513/650 Rom Document

//ROM_IntEnable(INT_TIMER2A);

   MAP_TimerEnable(TIMER2_BASE, TIMER_BOTH); // enable the timer. ROM user doc page 509/650 Rom Document

}

  • If your goal is to count events and generate an interrupt after 0xXXXXXX events (where 0xXXXXXX represents a 24-bit number), you use half of the timer and the prescaler. The code below configures timer 2A to generate an interrupt every 0x30010 rising edges.

    void timerCounterInit(void) // uses pin PA4 on the Tiva CPU (See CPU doc P 1808/1890)
    
    {
       MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // enable the GPIO used for the pin.
       MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // enable the timer.
       while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER2))
       { // Wait for the Timer0 module to be ready.
       }
       MAP_GPIOPinConfigure(GPIO_PA4_T2CCP0); // set the alternate function
       MAP_GPIOPinTypeTimer(GPIO_PORTA_BASE, GPIO_PIN_4); // configure the pin as a timer
       MAP_TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT_UP);
       MAP_TimerMatchSet(TIMER2_BASE, TIMER_A, 0x0010); //
       MAP_TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, 0x03);
       MAP_TimerControlEvent(TIMER2_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); // config the edge.
       MAP_TimerIntEnable(TIMER2_BASE, TIMER_CAPA_MATCH); // select the IRQ's to enable.
       MAP_IntEnable(INT_TIMER2A); // enable the IRQ 39.
       MAP_TimerEnable(TIMER2_BASE, TIMER_A); // enable the timer. 
    }