ElectricRCAircraftGuy / eRCaGuy_TimerCounter

An Arduino micros()-like function (encapsulated in a library) with 0.5us precision (since the built-in Arduino micros() function has only 4us precision)
http://www.electricrcaircraftguy.com/2014/02/Timer2Counter-more-precise-Arduino-micros-function.html
31 stars 13 forks source link

Recommend using Multiply vs Divide in get_micros() #3

Open filmo opened 6 years ago

filmo commented 6 years ago

On Arduinos multiply is about 39x faster than divide. Thus multiplying by 0.50 rather than dividing by 2.0 might make a difference on the get_micros() routine.

ElectricRCAircraftGuy commented 6 years ago

yeah I think you're right. Here's some more speed test info: https://playground.arduino.cc/Main/ShowInfo. Really though I recommend you just use get_count() if you want good speed. Avoid the floating point operations altogether. I made get_micros() return a float essentially for those less experienced who are likely using floating point variables and math instead of integer math anyway.

I'll fix it anyway when I get the chance.