Page 1 of 1

small delays how to in a proper way

Posted: Fri Feb 28, 2014 7:04 am
by plyatov
Dear all,

please recommend me a proper way for creation of small delays in a range from 60ns up to 1.6ms inside of the driver function.

I need to make delays , but do not want to use a "busy-waiting" style.

Use of chThdSleepMicroseconds(1) gives 1ms delay at least instead of 1us, so this is not an option for me. This way just makes my driver too slow.

Example code:

Code: Select all

...
palSetPad(GPIOB, GPIOB_LED3);
// here is 10 ns - 1.6 ms delay required
palClearPad(GPIOB, GPIOB_LED3);
...


If there is no way to eliminate "busy-waiting" style, then please recommend me proper macros or function to calculate delay from MCU main clock frequency.

P.S.: This is not a periodical delays, so it seems callback from virtual timer are not appropriate here.

Best wishes.
--
Igor

Re: small delays how to in a proper way

Posted: Fri Feb 28, 2014 8:54 am
by Giovanni
Hi,

If you don't want busy wait then you could use the GPT driver in one-shot mode and get a callback after the requested time BUT not that you will have a limit in the IRQ service time, you cannot go realistically under 5-10uS and you will have heavy jitter at those levels.

If you want a polled solution then look for halPolledDelay(), it allows delays with clock-cycle resolutions. Note that an interrupt can affect the total delay anyway so it can only guarantee a minimum delay.

Giovanni

Re: small delays how to in a proper way

Posted: Thu Mar 06, 2014 7:26 am
by plyatov
Thank you Giovanni!