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.

F28M36P63C2: TimerLoadSet Value for 16-bit counters

Part Number: F28M36P63C2


I am using some of the Timers on our product for fan tachometers. I configure the timers using the split, 16-bit capture counters:


    TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR|TIMER_CFG_A_CAP_COUNT|TIMER_CFG_B_CAP_COUNT);
    TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR|TIMER_CFG_A_CAP_COUNT);

And then for each timer and channel, I do the following:

    TimerControlEvent(timerBase, timer, TIMER_EVENT_POS_EDGE);      // Capture on rising edge
    TimerLoadSet(timerBase, timer, 0xFFFF);                                                     // Load timer with largest 16-bit value

However, if I load with 0xFFFF, the timers never start counting, even when I know the fans are spinning and the GPIO is receiving events. Each Timer TimerValueGet() is always 0xFFFF. If I reduce the load value to 0xFFFE, everything works. The timers start to count down, and then wrap back to 0xFFFE when they hit zero. The documents don't mention the valid range for the TimerLoadSet.

I'm using :

// $TI Release: F28M36x Support Library v207 $

  • Derek,

    Thanks for reaching out to the C2000 E2E.

    I believe the problem is that by default the timer's "match" value is 0xFFFF by default.  So, when we leave the start value at 0xFFFF, once we enable the timer it has already "matched" to the target value so it doesn't count.  When you set the start to 0xFFFE this is no longer true, so it counts as you expect. 

    If we add the following line of code before we enable the timer(s) is should behave as expected:

    TimerMatchSet(TIMERn_BASE, TIMERn, 0x0001);  //set the match for non reset value.

    I used a value of "1" above, but this could be whatever is needed in the system for the event trigger.  Certainly we can change both this and the default timer value to count whatever number of pulses desired before the ISR, etc.

    Best regards,

    Matthew

  • Matthew,

    Thanks for the details. I am just using the timer as a counter and polling its value, I am not setting it up to use MATCH or an ISR. Is there a way to disable the match functionality completely? I thought the the TimerConfigure() setting the timer to *_CAP_COUNT mode would disable the match functionality. But it apparently it doesn't.

    Derek

  • Derek,
    From your earlier description, when 0xFFFE was used as the init value(and the match value untouched) does the timer continue to count always? Just from the documentation if appears as it might, since the match is never reached it will not stop and disable TnEN bit, rather roll to the init value of 0xFFFE and keep going.

    If this is acceptable, and you just need the extra MSB for counting purposes, both TimerA/B also have an 8 bit prescaler (GPTMTnILR)that is active in the Capture mode. You could make the MSB of the prescaler a "1" and then the timer will count 65535 before it rolls back.

    The other option, would be to use as is, with a match value of 0x0000 and some SW, either ISR or polling to reset the counter. I think the first option is the best bet for what you want, since the counter will never stop/miss edges.

    Let me know if this works for you.

    Best regards,
    Matthew