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.

How to set timer for 0.5ms

Other Parts Discussed in Thread: TM4C1294NCPDT

Hi,

            I amusing TM4c1294ncpdt controller.i have to generate  A DELAY OF EXACTLY 0.5 MS USING TIMER. I have made all the configuration for timer 0 (reference ex code in tivaware)below is my setting

Clock setting

ui32SysClkFreq=SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

ui32Period = ui32SysClkFreq/X;


TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);

IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();

TimerEnable(TIMER0_BASE, TIMER_A);

and then enabled the handler , what value should my Ui32Period (x) be to get a delay of 0.5ms or less.

  • Surely you have (some) thoughts/ideas - haven't you?

    The MCU's Timers are among the easiest to troubleshoot. A simple Led - properly connected (via current limit R) to the MCU's Timer pin - can serve as an excellent test-aid.

    Experimentation proves extremely powerful - builds your knowledge base & independence.

    MCU data-sheet (Timer section) provides (great) detail AND there are numerous code examples. (none creating the EXACT duration you seek - but EXCELLENT in unlocking any/all "timer mysteries."

    It would be "amusing" (your writing) to read your report after you've made slight additional effort to resolve this yourself...
  • Hello Kiran

    Note that the timer works at 120MHz. So to get a 0.5ms interval the X would be Frequency * Interval

    Regards
    Amit
  • Hi Amit,

                      Thanks for the reply.As per my application my requirement is to set timer for 5ms. So i have loaded the value 200 in ui32Period to get 5ms delay.

    ui32Period = (ui32SysClkFreq/(120000*5));     //ui32SysClkFreq/=120Mhz.

  • Hello Kiran

    Can you explain how a count of 200 will get 5 ms? Each count is at 120Mhz or takes 8.333ns. So a count of 200 would 200*8.333ns which is no way is 5ms!!!

    Regards
    Amit
  • Hi Amit,

    Clearly poster (assumed - did not read) Timer Section - and simply divided (1 second by 200)...thus 5mS!   MCU clock thus was (removed) from all consideration...

    And - had poster routed Timer output to an Led (someone here past suggested) he could have (at least) experimented with timer durations of 1/5 - several seconds - and then "scaled" those to his desire...

  • Hi Amit,

                     600024 *8.333ns gives 5ms so my  ui32Period should be almost 600024 .so in previous post you mean  ui32Period=ui32SysClkFreq * 5ms right?Had used timers in MSPs and other controllers , When programming through API ,lab 5 in workshop details won't give complete idea. Please let me know , if am wrong

    Thankyou

  • Hello Kiran

    Using the time scale will lead to approximation error. In this case it adds a 0.2us to total time. Rather use the system clock. It should give a value of 600000

    Regards
    Amit
  • Hi Amit,

    Perhaps it should be noted that (only) a 32 bit (or larger) timer can accommodate 600K.
  • Hello cb1

    Absolutely. Thanks a lot for pointing that out.

    Regards
    Amit