Help Needed Diagnosing Z Axis Encoder Discrepancy

Moderators: TomKerekes, dynomotion

Post Reply
Wayne
Posts: 9
Joined: Mon Nov 25, 2024 2:49 pm

Help Needed Diagnosing Z Axis Encoder Discrepancy

Post by Wayne » Sat Sep 13, 2025 8:53 pm

Dear Tom,

I hope you're doing well.

I'm reaching out for help with a puzzling issue I’ve encountered on the Z axis encoder. I’ve attached my initialization file, which I’ve stripped down to just the Z axis to better isolate the problem.

Here’s what I’m seeing:
• As the Z carriage moves down, the ZDRO matches the encoder reading divided by the Z axis parameter (Z_Param) in the Trajectory Planner perfectly—until it reaches -19mm.
• Beyond -19mm, the encoder reading begins to drift from the ZDRO. I’ve included a table below to show the deviation:

Code: Select all

Z DRO (mm)   Z Encoder Pos/Z_Param  Z Encoder Pos/Z_Param 
							         (with Encoder Zeroed at -20mm)
-18.000      -18.000                 
-19.000      -19.000                 
-20.000      -20.001                 0.000
-21.000      -21.012                -1.000
-22.000      -22.022                -2.000
-23.000      -23.039                -3.000
-24.000      -24.056                -4.000
-25.000      -25.069                -5.000
-26.000      -26.081                -6.000
-27.000      -27.099                -7.000
-28.000      -28.112                -8.000
-29.000      -29.128                -9.000
-30.000      -30.142               -10.000
Interestingly, if I move the Z carriage to -20mm, disable the Z axis, zero the encoder and re-enable it, the ZDRO and encoder readings below that point align correctly again.

I’ve tested the encoder connection either through Encoder #10 via Kogna’s JP8 or Encoder #0 via Kanalog’s JP1, and the results are identical—so I don’t think it’s a hardware connection issue. The magnetic encoder I used has minimum edge separation of 0.25us (4MHz).

Would you be able to take a look and let me know what might be causing this discrepancy? Any guidance would be greatly appreciated.

Many thanks!!!
#include "KMotionDef.h"

int main()
{
ch2->InputMode=ENCODER_MODE;
ch2->OutputMode=CL_STEP_DIR_MODE;
ch2->Vel=272000;
ch2->Accel=2720000;
ch2->Jerk=15000000;
ch2->P=0.2;
ch2->I=0.008;
ch2->D=1.6;
ch2->FFAccel=0;
ch2->FFVel=0.004;
ch2->MaxI=10000;
ch2->MaxErr=1e+09;
ch2->MaxOutput=10000;
ch2->DeadBandGain=1;
ch2->DeadBandRange=0;
ch2->InputChan0=0; // OR ch2->InputChan0=10;
ch2->InputChan1=0;
ch2->OutputChan0=146;
ch2->OutputChan1=0;
ch2->MasterAxis=-1;
ch2->LimitSwitchOptions=0x100;
ch2->LimitSwitchNegBit=2;
ch2->LimitSwitchPosBit=2;
ch2->SoftLimitPos=1e+30;
ch2->SoftLimitNeg=-1e+30;
ch2->InputGain0=3.2;
ch2->InputGain1=1;
ch2->InputOffset0=0;
ch2->InputOffset1=0;
ch2->OutputGain=-1;
ch2->OutputOffset=0;
ch2->SlaveGain=1;
ch2->BacklashMode=BACKLASH_OFF;
ch2->BacklashAmount=200;
ch2->BacklashRate=2000;
ch2->invDistPerCycle=1;
ch2->Lead=0;
ch2->MaxFollowingError=10000;
ch2->StepperAmplitude=20;

ch2->iir[0].B0=1;
ch2->iir[0].B1=0;
ch2->iir[0].B2=0;
ch2->iir[0].A1=0;
ch2->iir[0].A2=0;

ch2->iir[1].B0=1;
ch2->iir[1].B1=0;
ch2->iir[1].B2=0;
ch2->iir[1].A1=0;
ch2->iir[1].A2=0;

ch2->iir[2].B0=0.000768788;
ch2->iir[2].B1=0.00153758;
ch2->iir[2].B2=0.000768788;
ch2->iir[2].A1=1.92076;
ch2->iir[2].A2=-0.923833;

EnableAxisDest(2, ch2->Position);

DefineCoordSystem(-1,-1,2,-1);

SetBitDirection(21,1); SetBit(21);

return 0;
}

User avatar
TomKerekes
Posts: 2868
Joined: Mon Dec 04, 2017 1:49 am

Re: Help Needed Diagnosing Z Axis Encoder Discrepancy

Post by TomKerekes » Sat Sep 13, 2025 11:28 pm

Hi Wayne,

I see you are running Closed Loop Step/Dir. You might have a mismatched microstep/encoder count/input gain. In such a case the servo will need to make bigger and bigger connections the farther you go. With a max output of 10000 steps after that limit is exceeded the servo will stop making corrections.

To test change to open loop and make a big move and check if the Position and Destination match closely within expected mechanical tolerances.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

User avatar
TomKerekes
Posts: 2868
Joined: Mon Dec 04, 2017 1:49 am

Re: Help Needed Diagnosing Z Axis Encoder Discrepancy

Post by TomKerekes » Sat Sep 13, 2025 11:36 pm

It looks like the gain is off by about 1.4%

A lead screw pitch of 5mm vs 0.2in would be 1.6% difference.
Regards,

Tom Kerekes
Dynomotion, Inc.

Wayne
Posts: 9
Joined: Mon Nov 25, 2024 2:49 pm

Re: Help Needed Diagnosing Z Axis Encoder Discrepancy

Post by Wayne » Mon Sep 15, 2025 1:39 pm

Hi Tom,
Thanks for the insight — I’ve gone ahead with the adjustment and everything is now working as expected. Your professional and prompt response is greatly appreciated; it’s been really helpful!!!
Many thanks!

Post Reply