File tree 1 file changed +19
-1
lines changed
hardware/arduino/cores/arduino
1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -124,8 +124,26 @@ void delayMicroseconds(unsigned int us)
124
124
// calling avrlib's delay_us() function with low values (e.g. 1 or
125
125
// 2 microseconds) gives delays longer than desired.
126
126
//delay_us(us);
127
+ #if F_CPU >= 20000000L
128
+ // for the 20 MHz clock on rare Arduino boards
127
129
128
- #if F_CPU >= 16000000L
130
+ // for a one-microsecond delay, simply wait 2 cycle and return. The overhead
131
+ // of the function call yields a delay of exactly a one microsecond.
132
+ __asm__ __volatile__ (
133
+ "nop" "\n\t"
134
+ "nop" ); //just waiting 2 cycle
135
+ if (-- us == 0 )
136
+ return ;
137
+
138
+ // the following loop takes a 1/5 of a microsecond (4 cycles)
139
+ // per iteration, so execute it five times for each microsecond of
140
+ // delay requested.
141
+ us = (us <<2 ) + us ; // x5 us
142
+
143
+ // account for the time taken in the preceeding commands.
144
+ us -= 2 ;
145
+
146
+ #elif F_CPU >= 16000000L
129
147
// for the 16 MHz clock on most Arduino boards
130
148
131
149
// for a one-microsecond delay, simply return. the overhead
You can’t perform that action at this time.
0 commit comments