Help in Delay with float values

I have to control a buck boost controller with frequency of 50kHz.
Delays having float values are required in between 1 to 20microseconds. How is such a delay possible?
Need help here!!!

For example how to ged delay of 2.3microseconds?

The model is arduino uno.

What does the delayMicrosecond() function documentation states about accuracy?

If you want very short delays with fractions of microseconds then you need to take into account function call time, saving context, possibly interrupts happening at same time etc… or inline enough [


]( assembly operations to get the delay you want.

The resolution you get is connected to the frequency of your micro controller (which is not always super stable) A nop takes one cycle, so 1/16th of a microsecond on your uno running at 16MHz (so if you put 16 of those in a row and disable all interrupts you get 1 microsecond delay)

That being said I’m not sure what you do with your buck boost… probably an XY problem…

For an accurate and very short delay (a few us), you can't use delayMicoseconds(). Instead, an inline assembler macro should do the job by inserting "nop" instructions. These instructions do nothing but wait a clock cycle (however your compiler could optimize your code and simply erase the nops depending on the optimization level).

The UNO is clocked at 16MHz, hence a clock cycle duration is 62.5 ns. Your 2.3 us delay = 2300 ns= 37 clock cycles.

Give a try with this snippet:

__asm__ __volatile__(
  ".macro NOPX  P               \n\t"
  ".rept &P                     \n\t"   // adjust the number of nop here
  " NOP                         \n\t"
  ".endr                        \n\t"   // End of Repeat
  ".endm                        \n\t"   // End of macro
void setup() {
__asm__ __volatile__("NOPX 37"); 

void loop() {


I smell a double layered XY-problem.

@Jim_Kyle123, please tell us what your project is about. What is the boost buck converter for ? Can you show us a schematic ?

Are you trying to create a frequency with a delay ?
You can use the tone() function to create 50kHz.
Or you can use one of the timers to create a frequency output.

Welcome to the Forum.

What sort of signal do you want out of the UNO, and how is it controlling the buck-boost unit?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Please show ALL wiring including power supplies and label pins on the devices.

Thanks.. Tom... :slight_smile:

In order to delay execution for a specific number of cycles, GCC implements

    void __builtin_avr_delay_cycles (unsigned long ticks)

ticks is the number of ticks to delay execution. Note that this built-in does not take into account the effect of interrupts that might increase delay time. ticks must be a compile-time integer constant; delays with a variable number of cycles are not supported.