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.

SysCtlDelay and Sys Clock

Hi everyone !

I wrote the following code , I wanna delay of one second using SysCtlDelay;

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

SysCtlDelay(360000000);  // according to driver library instructions, each loop will take 3 machine cycles, of system clock, but I am unable to take one second delay

Does anyone Know Why ?

Thanks in advance

  • Hi,

    Hz = cycles per second, so if the micro runs at 120MHz, it will make 120x10^6 cycles in one second. Now if an iteration/ loop takes 3 cycles and you need 1second, then simple arithmetic operation should be division, not multiplication.

  • Hi Petrei,

    Your guidance IS correct - yet requires a stipulation/boundary.    When users seek time durations GREATER than 1 second - poster's "multiplication" method becomes valid...   When LESS than 1 second - division succeeds...

    Often the "best solution" is the most general one.   (so long as accuracy is not compromised)

  • Hello Haroon

    And additional point to add. If the function crosses a prefetch boundary there is an additional penalty of prefetch buffer, that may cause additional delay. Rather using a periodic timer with interrupt would be prevent this uncertainty.

    Regards
    Amit
  • Hi Amit,

    Well said - and often that, "Prefetch boundary" spoils "SysCntlDelay()'s" result.

    Now - would it not be even (more) useful if you could describe just, "How" we users may detect such, "Prefetch boundary" and what steps (if any) we may take to avoid it?    (I'm unsure if this is (only) a, "40MHz or Greater System Clock" issue.   Thus best to ask...) 

    Might you explain how we may avoid this, "Prefetch boundary" issue - or at least reduce it?    Thank you, Amit.

  • Hello cb1,

    In CCS (the one I use the most), a function may be placed at a location by using the following in the cmd (ICF file equivalent of IAR)

    .text.SysCtlDelay > 0x00900

    This will place the function SysCtlDelay always at location 0x900. When the function is placed at the start of the 256 bit flash line, it will always be in the prefetch buffer.

    Regards
    Amit
  • Thank you, Amit - appreciated.

    Two (new) issues arise:

    •  256 bit flash line - might you describe/detail - I can't recall that being (past) detailed here
    • 0x00900 must "relate" to that "256 bit flash line" - again might you detail?

    My Search (via the search box - atop the forum) yielded NO mention of "256 bit flash line!"   (see below)

  • Hello cb1,

    For the TM4C129, Figure 8-2 "Flash memory Configuration". The organization of the address space shows there are 32 bytes in a line (256 bits). If the function takes for e.g. 10 bytes and is placed at the end of the line then a prefetch will be invoked, when rolling over from one line to the next.

    Regards
    Amit
  • Thank you, Amit.

    Poster did not specify C129 (that I can see). Can you confirm that this "prefetch" impacts the C123 series - as well?

    And - should our (or others') function exceed 256 bits (32 bytes) is the prefetch then (always) invoked? If that's the case - it would appear that many/most complex functions fall "victim" to this, "Prefetch Buffer." Might you comment? Thank you, Amit.
  • Hello cb1

    Poster specified the use of the API SysCtlClockFreqSet which is specific to TM4C129x.

    In case of TM4C123x the prefetch is a single 32 bit buffer. It is advised (and should be valid for TM4C129x) to use the ROM version of the API which will always have a single cycle delay.

    Regards
    Amit