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.

CCS/EK-TM4C129EXL: EK-TM4C129EXL : delay time

Expert 1660 points
Part Number: EK-TM4C129EXL
Other Parts Discussed in Thread: EK-TM4C1294XL

Tool/software: Code Composer Studio



could anyone explain how to achieve 100,500,1000 ms delay time . for this 120MHz clock.




   g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                             SYSCTL_OSC_MAIN |
                                             SYSCTL_USE_PLL |
                                             SYSCTL_CFG_VCO_480), 120000000);




  • Do you want a delay, or do you really want to do an operation every 100ms, every 500ms and every second? If it is the first, look at using the TivaWare function SysCtlDelay(); SysCtlDelay(40000000); will delay 1 second. SysCtlDelay(20000000); will delay 500mS . SysCtlDelay(4000000); will delay 100ms. 

    It is more common that you need to execute periodic tasks. You can use timers to generate periodic interrupts. You can use a single timer to generate an interrupt every 100mS. In that interrupt routine you can set a flag to do your 100mS task. Also increment and check a 500mS counter. Every 5th interrupt reset that count and set the flag to do your 500mS task. Likewise you can set a flag for your 1 second task every other time you do the 500mS task. Or you can use three timers, one set for 100mS, one for 500mS and the third for 1 second. See the TivaWare example in:

    C:\ti\TivaWare_C_Series-2.1.4.178\examples\boards\ek-tm4c1294xl\timers

  • Thanks Bob Crosby for your kindness.

    sorry about my silly question but how did you calculate the delay time .the clock is 120MHz .how SysCtlDelay(40000000); will delay 1 second . how did you calculate this value 40000000

  • AHMAD_OBAI said:
    how SysCtlDelay(40000000); will delay 1 second . how did you calculate this value 40000000

    From the documentation for SysCtlDelay in TivaWareTM Peripheral Driver Library USER’S GUIDE SW-TM4C-DRL-UG-2.1.4.178.pdf:

    I.e. for a nominal 1 second delay with a 120 MHz clock the delay count parameter for SysCtlDelay is 120000000 / 3 = 40000000.

  • Both earlier arriving posters have advised well.

    That given - it may prove useful to note the following:

    • the 'SysCtlDelay()' function (as poster Chester detailed) is 'Not' a high accuracy function - & is subject to error.    (error depends upon other program operations which are of higher priority (especially interrupts) which may 'Prolong' the length of your chosen delay).    
    • as vendor's Bob noted - the use of one of the (many) MCU Timers enables far more accurate delay (or timed interval) creation.

    Note too that while your program is executing 'SysCtlDelay()' - it is (almost) completely 'blind to & unable to perform' other program operations!    (higher priority interrupts escape this weakness)     This serves as the 2nd main reason while use of a 'Timer' proves (most always) a superior choice.    (i.e. Use of the Timer does not preclude other code from executing - while the Timer counts!)    When the Timer extinguishes (ends) - a timer interrupt is generated - and it is only then that you take your specific timer-based action...     This Timer usage thus proves far less 'disruptive' that (any) 'in-line, delay' - which periodically renders the MCU (near) 'deaf & dumb.'    Should your code regularly employ 'multiple calls to 'SysCtlDelay()' or to any 'in-line delay code' - your program may 'miss fleeting (very narrow) events' - while the MCU is 'trapped w/in the delay unwinding.'      Timers avoid such (unnecessary & unwanted) limitations...