Skip to content

Problem when using Nano Every at 20MHz #29

Open
@david-nc

Description

@david-nc

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

Metadata

Metadata

Assignees

Labels

topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions