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.

RTOS/TM4C1292NCPDT: Timer period

Part Number: TM4C1292NCPDT

Tool/software: TI-RTOS

Hi,

I am using TIRTOS 2.16.0.14.

In my project, I am using timer3 which is created in the .cfg file as shown below. I am starting the timer from my function.

Now it is working with a period of 1s.  I want a timer with 1us period. To, achieve this, how the period has to be set? If the period is in counts, what is the maximum count I can set?

Regards

Sandra

  • Hello Sandra,

    The period can be set in microseconds when using the Timer - Instance Settings. Have you tried using '1' as a setting for it?

    If that doesn't produce a 1us period suitable for your needs, you may need to avoid using the TI-RTOS Hwi Dispatcher as stated here: e2e.ti.com/.../2105916
  • Hi,

    Thank you for the reply.
    I don't want to go to any timeout ISR. I just want to run a timer and increment it by 1us. To increment the timer by 1us, how should I set the period?

    Regards
    Sandra
  • Hello Sandra,

    I think I am unclear on your application then. Is the timer that runs every 1us just supposed to be a counter? How do you intend to leverage it if there will be no ISR used with it? What do you mean by 'increment it by 1us'? If you could clearly explain your goal for the timer and how it will be used, then I'll have a better chance of offering useful advice for you.
  • Pick your clock and prescaler combination so the timer advances in us.

    As simple as that.
  • Hi,

    I want to start the timer from a function in my program. I don't want to do anything when timeout occurs. I want a timer which is having a period of 1us and I need to read the timer count. I just want to get the time in microseconds after the timer starts.

    Thanks

    Sandra

  • Hi,

    Did you mean to take a clock module instead of the timer module?

    Regards
    Sandra
  • Hello Sandra,

    I believe setting the period to "1" instead of "1000000" within the configuration you have shown there would work then. But keep in mind the counter would be finite in size and with 32-bit timer, you'd still run out of count within 3 days. Not sure if you are planning to reset the counter before that occurs.

    You would need to list 'null' for the timer ISR function rather than the 'timer3ISRFxn' you have listed currently.

  • Thank you Ralph.

    Regards

    Sandra

  • Hello Ralph Jacobi,

    I believe setting the period to "1" will not give the timer register count will increment in 1 usec interval. i want to timer need to be started and there after timer register value should get increment by 1 usec interval. so that i can read the timer register by using Timer_getCount() for getting the values in 1 usec increment. Please suggest what is the typical configuration required to achieve this?

    Regards

    Bala

  • Have you considered using Timestamp_get64() and then converting the result into microseconds using Timestamp_getFreq() to determine the units of the value returned in Timestamp_get64()?

    Types_FreqHz freq;
    Types_Timestamp64 time;
    UInt64 frequency; /* in MHz */
    UInt64 timeInUs; /* time in microseconds */
    
    /* do the following once */
    Timestamp_getFreq(&freq); /* freq is in Hz */
    /* convert freq to MHz */
    frequency = ((UInt64)(freq.hi << 32) | (freq.lo) ) / 1000000;
    
     /* 
      * from then on, simply do the following to obtain the elapsed time since the system started up
     */ 
    Timestamp_get64(&time); /* get current timestamp */ 
    timeInUs = ((UInt64)(time.hi << 32) | (time.lo) ) / frequency; /* convert to microseconds */

    Alan

  • isn't that a little too complicated for what the OP wants to do? if all s/he wanted is to increment his timer 1us at a time, all s/he has to do is to set the prescaler so that the timer advances 1us/tick.

    on the flip side, the op did make a few conflicting claims so maybe we simply don't know what s/he wants to do.
  • Hi,

    I need timeInUs as 32 bit value. I divided the timeInUs by 2.
    I am getting timeInUs in the range 3961126959(EC1A 002F) initially itself. The timeInUs is supposed to increment from 0 right? When calling the function Timestamp_getFreq(), is it taking system frequency?

    Thanks
    Sandra
  • Just use the lower half of the 64 bit timeInUs. Dividing by two will yield time in 2 microsecond units.

    UInt32 timeInUs32;
    timeInUs32 = (UInt32)timeInUs;

    The timer used by the Timestamp APIs is started at system startup. Therefore the value retrieved from Timestamp_get64() will be since system startup. If you want to know the elapsed time from a particular point in your code, capture a snapshot of timeInUs at that point and then subtract that value from all subsequent timeInUs values:

    UInt32 t0;
    UInt32 elapsedTime;

    t0 = (UInt32)timeInUs; /* snapshot at T = 0 */

    ... collect an update to timeInUs32, then:

    elapsedTime = timeInUs32 - t0;

    /* elapsedTime is the number of microseconds from T=0 */

    For this device, the timestamp timers are clocked at the same frequency as the CPU. Therefore the frequency returned by Timestamp_getFreq() will be the CPU frequency.

    Alan
  • Hi Alan,

    Thanks for the reply.

    I am running a seconds counter also in the application. So, while reading microseconds value, I am getting 3232892 us for 11 seconds. For 13 seconds, it was giving 3063887 us. The microseconds value should correspond to seconds value right? How much time it will take to overflow?

    I tried by using

    ui32Time0 = Timestamp_get32();      // Initial value to find elapsed time

    /*Getting current timestamp */

    ui32TimeInUs = Timestamp_get32();

    ui32TimeInUs = (ui32TimeInUs - ui32Time0) / frequency;      // Frequency got by Timestamp_getFreq() as you suggested

    Then I am getting as,

    For 34 seconds, 35740198 us  and for 35 seconds, 38538855 us is gotten.

    Is this implementation correct? How much time will it take to overflow?

    Regards

    Sandra

  • On my Tiva launchpad, the Timestamp frequency is 120MHz. At that rate, the 32 bit timestamp rolls over every 35.79 seconds.

    I tried this code on my board and it behaved as expected:

       UInt32 ui32TimeInUs;
       UInt32 ui32Time0 ;
       UInt32 frequency;
       Types_FreqHz freq;
    
       ui32Time0 = Timestamp_get32();
       Timestamp_getFreq(&freq);
       frequency = freq.lo; /* frequency in Hz */
    
       ui32TimeInUs = Timestamp_get32();
       ui32TimeInUs = (ui32TimeInUs - ui32Time0) / frequency;
    

    Using the above code, the ui32TimeInUs advanced by 1 every 1 second because the frequency is in Hz.

    If you want ui32TimeInUs to truly be in microsecond units, you need to pre-divide the frequency by 1,000,000:

     frequency = frequency / 1000000; /* frequency in MHz */

    All subsequent calculations of ui32TimeInUs will then be in units of microseconds and will advance by 1,000,000 every 1 second.

    All

  • Hi Alan,

    Thank you for the reply.

    When I tried the same code,  the timestamp rolls over by 35 seconds. But the ui32TimeInUs advances by almost 13,00,000 for every 1 second. What may be the reason for this variation?

    Thanks

    Sandra

  • I'm not sure from your comment if you are referring to the return value of Timestamp_get32() prior to conversion into microseconds or after. Nor do I understand the value "13,00,000". I don't know if you meant 13,000,000 or 1,300,000, or possibly 130,000,000.

    With a 120MHz CPU clock, the value returned from Timestamp_get32() should advance by 120,000,000 every 1 second. After conversion to microseconds (by dividing by 120), the resulting value of ui32TimeInUs should advance by 1,000,000 every 1 second.

    What are you using as your reference time base to measure a 1 second interval? Using CCS and halting after approximately every 1 second to check the current value of ui32TimeInUs can yield widely varying results. Letting the program run for 20-30 seconds between halts will provide a much better indication of the rate that ui32TimeInUs is advancing.

    Alan
  • Alan,

    Thank you very much for the support. I got it.

    Thanks

    Sandra