Issue using a servo with GRBL for a plotter

I'm using a version of GRBL that was adapted for use of a servo to control the Z axis. A link of it can be found here: GitHub - robottini/grbl-servo: grbl 0.9i with Servo motor support

I just got a new Futaba S3003 in, and I installed it on my plotter. When I set the servo to it's "zero" position with universal Gcode sender by sending the "M5" message to my Arduino, it rotates about 60 degrees (counter clockwise). When I try to rotate it to the 20 degrees mark, it turns 20 more degrees in the direction it has already turned (counter clockwise). How do I make the zero position the point at which the servo hasn't rotated at all from its minimum position?

The "read me" file on the github page has the following information:

you can change the pulse duration in the file spindle_control.c:

define RC_SERVO_SHORT 15 // Timer ticks for 0.6ms pulse duration (9 for 0.6ms)

define RC_SERVO_LONG 32 // Timer ticks for 2.5 ms pulse duration (39 for 2.5ms)

define RC_SERVO_INVERT 1 // Uncomment to invert servo direction

If you want to have the servo working from 0 --> 180 degrees change RC_SERVO_SHORT and put 9, RC_SERVO_LONG and put 39 If you want invert the servo direction uncomment the line above.

According to the third post here: Futaba S3003 RC servomotor

should I change the values of C_SERVO_SHORT to 5 (~0.3 ms) and C_SERVO_LONG to 26 (2.1 ms) in spindle_control.c?

We don't physically have your servo - this is something only you can experiment with surely?
Hobby servos are not precision components, they vary.

Are C_SERVO_SHORT and C_SERVO_LONG what I need to change in order to change the pulse width though? I altered the values to what I posted above and reuploaded everything, but I don't think anything changed.

bump

Try this test sketch with the Servo library to see how your servo responds to different settings, type a position (0 to 180) or if you type a number greater than 200 it will be interpreted as microseconds, in the top of serial monitor and hit [ENTER], start at 90 (or 1500) and work your way toward zero 5 degrees (or 50 micros) at a time, then toward 180 (2400?).

#include <Servo.h>
Servo servo;


int pos = 0;

void setup() {
  // initialize serial:
  Serial.begin(9600); //set serial monitor baud rate to match
  servo.attach(9);
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int pos = Serial.parseInt();
    pos = constrain(pos, 0, 2400);
    servo.write(pos);
    Serial.print("  degrees =  "); 
    Serial.print(servo.read());
    Serial.print("\t");
    Serial.print("microseconds =  ");
    Serial.println(servo.readMicroseconds());
  }
}

Keep in mind, the Arduino servo library has a default refresh time of 20000 microseconds, if your library has a different refresh rate you may have to adjust accordingly, for example the servo library has a minimum pulse width (0 degrees) of 544 uS, 1500 uS (90 deg) and max of 2400 uS (180 deg). If your lib has a refresh rate of, say, 5000 then 5000 / 20000 = 0.25, you may have to multiply all the above pulse widths by that number.

I got the following out put from that sketch:

degrees = 0 microseconds = 544
degrees = 5 microseconds = 595
degrees = 10 microseconds = 647
degrees = 15 microseconds = 698
degrees = 20 microseconds = 750
degrees = 25 microseconds = 801
degrees = 30 microseconds = 853
degrees = 35 microseconds = 904
degrees = 40 microseconds = 956
degrees = 45 microseconds = 1008
degrees = 50 microseconds = 1059
degrees = 55 microseconds = 1111
degrees = 60 microseconds = 1162

The pulsewidth corresponding to zero degrees is a lot lower than I anticipated. How can I change the firmware to get down to that angle?

bump

The G codes M2, M3 & M5 are for spindle motor control and usually followed by a speed command like, "M2, S300", totally separate from Z axis commands like "G1, Z2.5,F0.2". I thought you were using the servo to move the Z axis?