Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Good job, but how to speed up execution times?

Open vittorioexp opened this issue 6 years ago • 1 comments

Hi, I want to thank you for the work you did. I noticed that the "SetPinFrequencySafe (TX_PIN, frequency)" function takes 88 microseconds to run, while the "pwmWrite (TX_PIN, 127)" function takes 44 microseconds. Is there a way to speed up these execution times?

Esposito Vittorio

vittorioexp avatar Jul 08 '17 08:07 vittorioexp

Hi Vittorio,

the execution time of the SetPinFrequencySafe command doesn't really matter because it is in the setup routine and is only executed once after bootup. Even the pwmWrite function is only executed if frequency change is requested, and the the loop function itself runs only twice in 2 seconds, the code run length is not noticeable compared to the delay. The whole method of using the hardware PWM of the Arduino is far better than writing the code in software with the digitalWrite function. I would look for optimization where it matters.

Tobias

atmelino avatar Jan 10 '18 23:01 atmelino