Open
Description
Servo positioning is incorrect when using Servo library with a Nano Every running at 20MHz. The calculation in Servo.cpp
to adapt to the clock frequency is dropping the fractional part and producing an incorrect result.
In the file Servo/src/megaavr/Servo.cpp
, line 6 is as follows:
#define usToTicks(_us) ((clockCyclesPerMicrosecond() / 16 * _us) / 4) // converts microseconds to tick
clockCyclesPerMicrosecond() / 16
is rounding off to 1 before multiplying by _us, producing an incorrect result.
Changing the line to the following seems to correct the problem:
#define usToTicks(_us) (((int32_t)clockCyclesPerMicrosecond() * _us / 16) / 4 ) // converts microseconds to tick