This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How could I make a adjustable delay function in "micro-second" level

Hello Every :

I use AT89C52 and 11.059MHz oscillator.
1 instuction takes about 1 micro-second.(10^-6 sec.)

I write a delay function in *.asm.

It works well , but I want it adjustable.
I want to delay according to the parameter I pass.My goal is to modify delay time for some protocol time slot testing.

I found it some how difficult to achieve.
Because the basic instruction , for example : _nop_ , take 1 micro-second.
I can't add more decision. It will takes more time.

How could I implement such kind of delay?
Please give me a hand , thanks a lot~~

Parents
  • Thank You all , I learned a lot from you all.

    But Jon , Maybe you just solved half of my question.
    All of You did give me some great solution of how to delay in micro-second level.
    But , I still can't decide "delay count" in run time.
    Your method is calling certain non-parametered sub-routine in the program.
    For example , if I want to delay 10 uS , I could call NOPS_010 (),and 20 uS ,call NOPS_020().
    This is great when implementing any protocol.
    But , if I want to adjust Signal time slot (protocol) in run time.
    I want to input "delay count" to decide how long to delay.
    I tried the method in this article :
    http://www.keil.com/forum/docs/thread2938.asp (the one Graham Cole wrote).
    And I declare a variable for storing "delay count".
    Then , I could just change "delay count" by passing different parameter.
    Or I can call the major function that includes "delay function".

    This method seems doesn't work.
    Because when I call by constant (ex:NOPS(10)), it almost meet my require.But when I call by variable (ex:NOPS(delay_count) where delay_count = 10)
    it has serious overhead . It delays about (delay_count + 20~30) uS.

    Are there any more solutions ?
    Anyway , thank you all. I did learn a lot.

Reply
  • Thank You all , I learned a lot from you all.

    But Jon , Maybe you just solved half of my question.
    All of You did give me some great solution of how to delay in micro-second level.
    But , I still can't decide "delay count" in run time.
    Your method is calling certain non-parametered sub-routine in the program.
    For example , if I want to delay 10 uS , I could call NOPS_010 (),and 20 uS ,call NOPS_020().
    This is great when implementing any protocol.
    But , if I want to adjust Signal time slot (protocol) in run time.
    I want to input "delay count" to decide how long to delay.
    I tried the method in this article :
    http://www.keil.com/forum/docs/thread2938.asp (the one Graham Cole wrote).
    And I declare a variable for storing "delay count".
    Then , I could just change "delay count" by passing different parameter.
    Or I can call the major function that includes "delay function".

    This method seems doesn't work.
    Because when I call by constant (ex:NOPS(10)), it almost meet my require.But when I call by variable (ex:NOPS(delay_count) where delay_count = 10)
    it has serious overhead . It delays about (delay_count + 20~30) uS.

    Are there any more solutions ?
    Anyway , thank you all. I did learn a lot.

Children