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 get a delay of 1sec using driverlib function SysCtlDelay()

Other Parts Discussed in Thread: TM4C129DNCPDT

Hi,

I am facing problem to get the correct formula for generating the delay i want using SysCtlDelay function. We are using TIRTOS 2.1.0.

I am using TM4C129DNCPDT controller.

I tried using below formula to generate a delay of 1sec, but it didn't give me the required time delay and goes into long delay :

Clk = SysCtlClockGet();

SysCtlDelay(DelayTimeInSeconds/((1/Clk)*3));

Can anybody please confirm the formula and what we are missing.

Thanks in advance.

  • Hello Shrikant,

    SysCtlClockGet is not a valid function for TM4C129x devices. The system clock frequency in case of TM4C129x is the return value of SysCtlcClockFreqSet function. Also based on the location of the API and flash prefetch state (which is proportional to the system clock) the delay may vary around 1 sec. An accurate way of getting 1 second would be to use a timer in periodic mode.

    Regards
    Amit
  • Hi Amit,
    Thanks for your reply. Actually i want to get how frequently a function in my code is getting called. So i am using function Timestamp_get32(); which returns the current sys tick count value. So i every time i enter into that function i am calulating the difference between previous tick count and current tick count which gives me a constant diff value of 100000. But 100000 is not a value representing any time so i want to know the what time this 100000 sys tick count represents.(For exampe : 1ms, 100ns, 10ms whatever it can be)
    I was using sysctl delay to get this time from the value 100000, which may not be a suitable way.
    Hope you understood my problem. Can you now suggest any solution to this?Thanks.
  • Hello Shrikant,

    The count represents the number of Clock Cycles of SysTick Module. If the Systick is running at 16MHz then the maths is very simple

    Time = 1/16Mhz * Number of clock cycles

    Regards
    Amit