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.

Question about USdelay



Hello,

I open 2806x library,

I see DELAY_US macro

#define DELAY_US(A)  DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)

this macro multiply "us delay" x1000 to calculate "ns delay" (1us=1000ns),

then the macro divides "ns delay" for Tclock in ns to calculate the number of ticks.

I don't understand why the macro subtract 9 and it subsequently divide for 5.

Can someone help me ?

  • Mauro Fantina said:

    Hello,

    I open 2806x library,

    I see DELAY_US macro

    #define DELAY_US(A)  DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)

    this macro multiply "us delay" x1000 to calculate "ns delay" (1us=1000ns),

    then the macro divides "ns delay" for Tclock in ns to calculate the number of ticks.

    I don't understand why the macro subtract 9 and it subsequently divide for 5.

    Can someone help me ?

    Mauro,

    The source for this function is in the <device>_common\source folder in the <device>_usDelay.asm file.  The comments describe the function:

     

    ;There is a 9/10 cycle overhead and each loop
    ;takes five cycles. The LoopCount is given by
    ;the following formula:
    ;  DELAY_CPU_CYCLES = 9 + 5*LoopCount
    ; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
    ; The macro DELAY_US(A) performs this calculation for you
    ;

    Lori