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.

Wide Timers on TM4C

Hello,

I have been working with the timers today and have come across a discrepancy which I can't explain. I have been trying to make a simple freerunning 32 bit timer so I can do some microsecond measurements. 

I made some operational code for the 16/32 bit timers and this worked fine and tried to use this code to control a 32/64bit timer TimerA so that I was able to use the prescaler. 

Here is the code:

		//set up a timer for the fine resolution clock
		// Configure TimerA as a 32 bit timer    
    // TimerB values inferred from Timer A
    SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1);
	  // ensure timer is disabled before configuring
	  TimerDisable(WTIMER1_BASE, TIMER_BOTH);
	  // timer overflows and restarts
    TimerConfigure( WTIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC_UP );
    // Set timer clock source to be system clock
    TimerClockSourceSet( WTIMER1_BASE, TIMER_CLOCK_SYSTEM );
    // set up the prescaler - each counter bit is worth 1/20e6 of a second (ie divide by 20 to get uS)
		TimerPrescaleSet( WTIMER1_BASE, TIMER_A, 1);
		// Set the overrun value (largely ignored, must be above max expected value)
	  TimerLoadSet( WTIMER1_BASE, TIMER_A, 2000001 ); 
    // set the cause of interrupt
		TimerIntEnable( WTIMER1_BASE, TIMER_TIMA_TIMEOUT); 
		// timer is free running
    TimerEnable( WTIMER1_BASE, TIMER_A );

Where I essentially replaced the timer base with WTIMER1_BASE.

Does anyone have any initial thoughts why this might not have worked... it just cycles through at a constant rate and ignores the TimerLoadSet threshold (regardless of what value I use). 

Best of thanks

  • Hello Andrew,

    The prescalar is an extension of the timer counter. So in upcount mode it would be going to the full value of 0xFFFF.FFFFFFFF before a roll over to the Load Values. Is that what you are seeing or is there some other behavior observed?

    Regards

    Amit

  • Andrew Newton1 said:
    trying to make a simple freerunning 32 bit timer so I can do some microsecond measurements. 

    You report that this, "worked fine" w/16/32 bit timers. 

    It's unclear why you then moved to, "Wide Timers."  The prescalers can not increase your measurement precision - should that be your thought.  Timers are fed from System Clock - I don't believe you can reduce that granularity.  Thus Wide timers are usually employed to measure signals which persist beyond the limits of 16/32 ones.  (and - that appears not your case)

    As Amit states - in many (most) modes the prescaler serves (bit unusually) as an "over-flow" counter - not as the lower counter result/register repository...

  • Morning,

    Thanks for taking an interest. The reason I wanted to use the 32/64 bit timer is to *reduce* the resolution! I only need to count 80 clock cycles to reach a microsecond. Thus, by using the prescaler I can limit my number to 24 bits when counting microseconds in a second. That is only important so that I can speed up transmission of my serial message by removing a number of unused bytes in the message. 

    However, if I understand correctly, you're saying that the prescaler does not act as a clock divider, it just reduces the size of the bucket so that it overflows (and therefore interrupts) earlier. That would make it unsuitable for a free running counter. In which case I understand. Thanks