I have some code that I have run successfully on an Uno, and I am now trying to migrate it to the Nano Every. The issue that I am running into at the moment is that when using the Nano Every board, I can only position my servo at increments of 4us. When using the Uno board, I am able to set the position at 1us increments. Here are the code snippets that call writeMicroseconds().
void loop() {
while (!Serial.available()) {
delay(100);
}
cmdString = Serial.readString();
int n = cmdString.length();
char char_array[n + 1];
strcpy(char_array, cmdString.c_str());
int steps = atoi(char_array);
moveServoRelative(tmpServo, steps);
Serial.print("MOVE : Moved current axis by ");
Serial.print(steps);
Serial.print(" microseconds to ");
Serial.print(tmpServo.readMicroseconds());
Serial.println(" microseconds.");
}
void moveServoRelative(Servo servo, int steps) {
int currentPos = servo.readMicroseconds();
Serial.print("Current Position setting: ");
Serial.println(currentPos);
int newPos = currentPos + steps;
Serial.print("New Position setting: ");
Serial.println(newPos);
servo.writeMicroseconds(newPos);
}
With the Nano Every, a sequence of commands attempting to move the servo position by 1us up to 6us yeilds this result:
Current Position setting: 1445
New Position setting: 1446
MOVE : Moved current axis by 1 microseconds to 1445 microseconds.
Current Position setting: 1445
New Position setting: 1447
MOVE : Moved current axis by 2 microseconds to 1445 microseconds.
Current Position setting: 1445
New Position setting: 1448
MOVE : Moved current axis by 3 microseconds to 1445 microseconds.
Current Position setting: 1445
New Position setting: 1449
MOVE : Moved current axis by 4 microseconds to 1449 microseconds.
Current Position setting: 1449
New Position setting: 1454
MOVE : Moved current axis by 5 microseconds to 1453 microseconds.
Current Position setting: 1453
New Position setting: 1459
MOVE : Moved current axis by 6 microseconds to 1457 microseconds.
Looking through the Servo library, I haven't been able to figure out where this rounding is happening, and I'm hoping someone with more expertise can direct me to the root cause of this issue.