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.

TM4C123GH6PM: Delay time incorrect...

Part Number: TM4C123GH6PM

Tool/software:

Hello,

I set my sys clock freq as 80MHz and don't know why SysCtlDelay(10000000); is delaying 750ms instead of 375ms. 

I used logic analyzer to test the SPIWritePacket function, and as you can see below, the delay is 750ms, not 375ms.  

 

This is my code for testing SPIWritePacket() and and SysCtlDelay(10000000).

 

My code for setting the Sys Freq is SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

  • This is my code for testing SPIWritePacket() and and SysCtlDelay(10000000).

     

    Hi Scott,

      SysCtlDelay() takes three cycles to execute. Therefore, if you call SysCtlDelay(SysCtlClockGet()), it will give you 1s * 3 which is equal to 3s of delay. If you want to get a 1s delay you would call SysCtlDelay(SysCtlClockGet() / 3). If you want to get 375ms then you would call SysCtlDelay(SysCtlClockGet() / 3 * 375 / 1000). Try to experiment with all three calls to get a feel of how the delay works. 

    SysCtlDelay(SysCtlClockGet())

    SysCtlDelay(SysCtlClockGet() / 3)

    SysCtlDelay(SysCtlClockGet() / 3 * 375 / 1000)

  • Hi Charles,

    Yes, I'm aware of that but what I'm saying is the theory doesn't match the experimental value and I would like to know what's causing it.

    Theoretically, SysCtlDelay(10M) should be 1/80MHz * 10M * 3 = 0.375s, but on logic analyzer I'm getting 0.75 instead of 0.375

  • Hi Scott,

      Please use ROM_SysCtlDelay instead of SysCtlDelay. There may be variation of the delay due to the compiler optimization when SysCtlDelay is executed. Use ROM_SysCtlDelay instead as the number of the cycles the function takes is fixed in the ROM memory.