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.

Problem triggering GPTM timer externally and setting count direction

Other Parts Discussed in Thread: CC3200

Hi, I need to measure the time between external interrupts on a pin however I am having problems setting up the timer. I require trigger on Both edges. As I understand i can do this in 2 ways, the first with a gpio interupt that starts a periodic or one shot timer and then check the count on the second interrupt. The second method is to use input-edge time mode and have the interrupt trigger the timer directly and then compute the count difference between interrupts. I have tried both methods but i can't seem to configure the timer properly. Using the periodic timer method, it seems to count in the opposite direction that i set with TIMER_CFG_PERIODIC_UP. Using the edge time mode, it seems to count down regardless. To configure edge-time I use TIMER_CFG_A_CAP_TIME_UP. Is there something else I need to configure for count direction? 

For periodic I configure the timer with:

     // Configuring the timers
     Timer_IF_Init(PRCM_TIMERA0, TIMERA0_BASE, TIMER_CFG_PERIODIC_UP, TIMER_BOTH, 0);
     MAP_GPIOIntTypeSet(GPIOA1_BASE,GPIO_INT_PIN_5,GPIO_BOTH_EDGES);

For edge-time I configure the timer with:

    // Configure the timer in edge count mode
    MAP_TimerConfigure(TIMERA2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP));
    // Set the detection edge
    MAP_TimerControlEvent(TIMERA2_BASE,TIMER_A,TIMER_EVENT_BOTH_EDGES);

Am I required to set a reload value of zero for count-up or is this set automatically?

  • Mike,

    Let me check and get back to you

    Thanks and Regards,
    Praveen
  • Mike,

    Please refer to the timer_cc example in CC3200 SDK. It uses TIMER_CFG_A_CAP_TIME mode of the GPT to measure the frequency of the external signal fed on Pin 4.

    I could not recreate you issue of time counting down when configured in TIMER_CFG_A_CAP_TIME_UP. You can modify the same example to see the timer counting UP.

    In main()

    //
    // Configure the timer in edge count mode
    //
    MAP_TimerConfigure(TIMERA2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP));

    And in the interrupt handler

    //
    // Get the samples and compute the frequency
    //
    g_ulSamples[0] = g_ulSamples[1];
    g_ulSamples[1] = MAP_TimerValueGet(TIMERA2_BASE,TIMER_A);
    g_ulFreq = (TIMER_FREQ/(g_ulSamples[1] - g_ulSamples[0]));


    Thanks and Regards,
    Praveen
  • Hi Praveen,

    Thank you for the reply. I've tried out the timer_cc example and it seems to be working. One question I have is when using the timer_cc example, how do I restart the event timer inside the interrupt handler after I get the count since last event? I wish to restart to avoid the timer running out before the next event edge occurs. Is this the correct way to restart the timer:

    MAP_TimerLoadSet(ulBase,ulTimer,ulValue);
    MAP_TimerEnable(ulBase,ulTimer);

    I find the function descriptions a bit unclear and having difficulty translating the register descriptions in the TRM to the functions provided in the peripheral library.

    My interpretation of this description in the TimerLoadSet function is that it restarts the timer?
    //! This function sets the timer load value; if the timer is running then the
    //! value is immediately loaded into the timer.
  • Hi Mike,

    Please use GPTMTAV Register to dynamically change the counter value ( see Table 9-27. GPTMTAV Register Field Descriptions for more details )

    Thanks and Regards,

    Praveen

  • Hi Mike,

    Is this issue resolved. If yes please press the "Verify Answer" button to close this thread.

    Thanks and Regards,
    Siddaram
  • I was able to get the up/down count direction working correctly however I am unsure what exactly fixed it. I seem to have mixed results sometimes when making changes and then trying to revert back to a working version of the code.

    I tried writing to the GPTMTAV register while using a periodic timer and it correctly changed the counter value dynamically. Writing to this register while using the edge-time capture mode however didn't seem to have any effect for me. After discussion with a coworker, it seems resetting the timer in the ISR may not be of best practice or suitable for my application. Instead, I chose to deal with the timer rollover and I was able to get that working. I require clarification however on the behavior of the prescale registers when using the event-time capture mode. 16 bits is not sufficient for my signal and I would like to use the 8 bit prescale extension.

    Page 2 of reference manual SWRU367B states that the time at which the selected input event occurred is stored with the 16 LSB in the (GPTM TAR) register and the 8 MSB in the Prescale Snapshot Register (GPTM TAPS). I couldn't find a function that returns the Prescale Snapshot value and the TimerValueGet function only seems to return the value of the TAR register. The Prescale Snapshot register also doesn't appear in Table 9-8 Timer registers on page 273. It states "All register offset addresses not listed in Table 9-8 should be considered as reserved locations and the register contents should not be modified." I assume its okay to read from this register using something like:
    HWREG(ulBase + TIMER_O_TIMER_O_TAPS) ?
  • Hi Mike,

    Yes it is ok to read from the register as you mentioned.
    HWREG(ulBase + TIMER_O_TIMER_O_TAPS)

    Thanks and Regards,
    Siddaram
  • Hi Mike,

    Are your queries answered. If yes please press the "Verify Answer" button to close this thread.

    Thanks and Regards,
    Siddaram
  • Hi Mike,

    I am closing the thread, if issue still exist please open a new thread and add a link to this one for reference

    Thanks and Regards,
    Siddaram