Blink frequencies

Hi, I just happened to measure the 'Blinking' frequencies (on digital pin13) by changing the program delays from 10000 microseconds to 1000 microseconds then to 100 microseconds . In the first instance the frequency I got was 50 Hz (correct value) then in the second instance I got it as 500Hz (also correct value) in the third instance (100uS) it was showing only 4790Hz ( instead of 5000Hz) and when I set the delays to 10uS it was showing 36200Hz instead of 50000Hz. I confirmed the frequency read outs accuracy using a second frequency counter also. Can anybody explain the difference ?!!. Thanks in advance .


Post your code. In short, there is should be digitalWrite, which also consume a portion of time

Since function calls and loops take time the frequency generated by delays is only accurate for delays that are large compared to the instruction cycle time. To get accurate frequencies you have to adjust the delays to account for time use in other instructions.

That sounds about right. The digitalWrite() loop, not including the delays(), takes about 10 microseconds. So if the delay is 100us, you’d get a frequency of about 1e6/(100+100+10) = 4761 Hz.

Extensive discussion here:

Hi All,
Thanks for your reply. Now I get it. There is always around a resident 10uS delay with the loops and when the delay times are very large compared to it the frequencies are more nearer to predicted values,and vice verse.