So, I have implemented a custom delay function using the standard one found at utils/delay.h.
inline void delay_us(uint16_t time) {
while (time > 0) {
_delay_us(1);
time--;
}
}
It's called inside a loop in the main function:
#define F_CPU 16000000UL
...
int main() {
pin_mode(P2, OUTPUT);
while (1) {
pin_enable(P2);
delay_us(1);
pin_disable(P2);
delay_us(1);
}
}
Using an oscilloscope, I can tell that the pin stays 1.120us high and 1.120us low, with 1 as parameter. Incrementing the parameter to 6, the the oscilloscope shows me 6.120us. But with 7, it stays 9 us. With 10, about 14 us.
I know the loop comes with an overhead, but why there is no overhead (or why the overhead does not changes) between 1 and 6 us?
OBS: I'm using an Arduino UNO (16 MHz)