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.

关于DSP2833x_usDelay.asm延时程序的问题


.def _DSP28x_usDelay
.sect "ramfuncs"

.global __DSP28x_usDelay
_DSP28x_usDelay:
SUB ACC,#1
BF _DSP28x_usDelay,GEQ ;; Loop if ACC >= 0
LRETR

;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

在这个延迟程序中ACC的值是从C程序中传递的unsigned long cnt值。请问一下DELAY_CPU_CYCLES = 9 + 5*LoopCount这个公式是什么作用?CPU的周期=9+5*循环次数? unsigned long cnt这个值不是循环的次数? 不是很明白。麻烦解释一下谢谢!
;

  • DELAY_CPU_CYCLES = 9 + 5*LoopCount这个公式是用来计算循环次数的基本公式:

    --> LoopCount = (DELAY_CPU_CYCLES - 9) / 5

    其中9是调用函数进入的时间,5是每个循环花费的时间,单位都是系统周期。

    看看具体调用的时候:

    DELAY_US(ADC_usDELAY)  // ADC_usDELAY = 1000L

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

    函数调用时传递的就是计算好的循环次数LoopCount 。

  • 你好!麻烦了谢谢! 

    请问 9是调用函数进入的时间指的是在C语言中调用DELAY_US(A)函数,然后转到宏定义进入汇编程序的时间? 

    5是每个循环花费的时间这个指的是汇编程序循环一次要5是吗?

    ((long double) A * 1000.0L) / (long double)CPU_RATE) = DELAY_CPU_CYCLES是?