delay of the order of micro second

i am writing a code(in C language) in which i need a delay of the order of few micro seconds. and this delay is not constant, i.e., i am using a variable and i should get a delay of value equal to that variable and it would be of the order of micro seconds.. the minimum value of that variable is 0.5 and max is 150,i.e., the delay would have to be changing from 0.5 microsec to 150 microsec. the inbuilt functions in the AVR compilers are not giving such short delays. i have no knowledge about keil. can any one suggest me a microcontroller for the delay of this order and also, is there any inbuilt function in keil to give such delays?If yes, then what is it? if not then how to get such delays?

Parents
  • A delay of 0.5us is too short for you to initialize a timer and wait for it to timeout. With a fast processor, you can have a timer constantly running and then sample the current value and wait until now - start is long enough.

    Obviously, you will need a processor that can perform a number of instructions in 0.5us. An ARM or fast 8051 one-clocker should be able to do it but you have to keep your eyes on the possibilities of the timers. The timer must support ticking at more than 2MHz without overflowing in 150us. A fast-running 16-bit or 32-bit timer would do nicely.

    If the processor can do this in less than 0.5us then it should be fast enough:
    - sample current timer value on function entry.
    - subtract the estimated call/return time for the delay function call.
    - do at least one loop sampling the timer again and subtract with start value and compare with input parameter.

    This might be possible to inline to avoid any call/return times.

    As you can deduce from the above, you would probably require 20-50 MIPS minimum speed from the processor to manage the initial setup and still manage the 0.5us minimum delay.

Reply
  • A delay of 0.5us is too short for you to initialize a timer and wait for it to timeout. With a fast processor, you can have a timer constantly running and then sample the current value and wait until now - start is long enough.

    Obviously, you will need a processor that can perform a number of instructions in 0.5us. An ARM or fast 8051 one-clocker should be able to do it but you have to keep your eyes on the possibilities of the timers. The timer must support ticking at more than 2MHz without overflowing in 150us. A fast-running 16-bit or 32-bit timer would do nicely.

    If the processor can do this in less than 0.5us then it should be fast enough:
    - sample current timer value on function entry.
    - subtract the estimated call/return time for the delay function call.
    - do at least one loop sampling the timer again and subtract with start value and compare with input parameter.

    This might be possible to inline to avoid any call/return times.

    As you can deduce from the above, you would probably require 20-50 MIPS minimum speed from the processor to manage the initial setup and still manage the 0.5us minimum delay.

Children
More questions in this forum