small delays how to in a proper way

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

plyatov
Posts: 25
Joined: Tue Feb 25, 2014 10:24 am
Been thanked: 2 times

small delays how to in a proper way

Postby plyatov » Fri Feb 28, 2014 7:04 am

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

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: small delays how to in a proper way

Postby Giovanni » Fri Feb 28, 2014 8:54 am

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

plyatov
Posts: 25
Joined: Tue Feb 25, 2014 10:24 am
Been thanked: 2 times

Re: small delays how to in a proper way

Postby plyatov » Thu Mar 06, 2014 7:26 am

Thank you Giovanni!


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 44 guests