Limit switch issue

Moderators: TomKerekes, dynomotion

Post Reply
yangx
Posts: 1
Joined: Thu Nov 21, 2024 2:30 pm

Limit switch issue

Post by yangx » Thu Nov 21, 2024 3:03 pm

Dear Tom, we are using a KFlop and a KStep to control a linear stage with 2 Optical Limit Switch (3.3V trigger signal, connected to Pin 34 and 35). Below is our code.
//Z axis-channel 13, 34-35
ch1->InputMode=NO_INPUT_MODE;
ch1->OutputMode=STEP_DIR_MODE;
ch1->Vel=4000;
ch1->Accel=40000;
ch1->Jerk=400000;
ch1->P=0;
ch1->I=0.01;
ch1->D=0;
ch1->FFAccel=0;
ch1->FFVel=0;
ch1->MaxI=200;
ch1->MaxErr=1e+06;
ch1->MaxOutput=200;
ch1->DeadBandGain=1;
ch1->DeadBandRange=0;
ch1->InputChan0=1;
ch1->InputChan1=0;
ch1->OutputChan0=13;
ch1->OutputChan1=0;
ch1->MasterAxis=-1;
ch1->LimitSwitchOptions=0x113;
ch1->LimitSwitchNegBit=35;
ch1->LimitSwitchPosBit=34;
ch1->SoftLimitPos=1e+09;
ch1->SoftLimitNeg=-1e+09;
ch1->InputGain0=1;
ch1->InputGain1=1;
ch1->InputOffset0=0;
ch1->InputOffset1=0;
ch1->OutputGain=-1;
ch1->OutputOffset=0;
ch1->SlaveGain=1;
ch1->BacklashMode=BACKLASH_OFF;
ch1->BacklashAmount=0;
ch1->BacklashRate=0;
ch1->invDistPerCycle=1;
ch1->Lead=0;
ch1->MaxFollowingError=1000000000;
ch1->StepperAmplitude=20;

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

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

ch1->iir[2].B0=0.000769;
ch1->iir[2].B1=0.001538;
ch1->iir[2].B2=0.000769;
ch1->iir[2].A1=1.92081;
ch1->iir[2].A2=-0.923885;

SetBitDirection(34,0);
SetBitDirection(35,0);

The strange thing is when we move the axis for a certain distance, the axis will be disabled quite often during movement even if the optical limit switch is not physically triggered (blocked) at all. This only happens when we connect two optical switches to pin 34 and 35 and set ch1->LimitSwitchOptions to 0x113. If setting ch1->LimitSwitchOptions to 0x112, only one optical switch is functional and it works perfectly.

Is it possible that the two pins interfere with each other? Thanks.

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

Re: Limit switch issue

Post by TomKerekes » Thu Nov 21, 2024 7:04 pm

You possibly have noise on the wiring. How is it wired? Those pins need to be driven high and low.

Since you have a KStep it would be better to use the 24V Opto-isolated inputs available on KStep.

OptoIns.png
Regards,

Tom Kerekes
Dynomotion, Inc.

xuphoenix
Posts: 14
Joined: Sun Apr 19, 2020 3:32 am

Re: Limit switch issue

Post by xuphoenix » Thu Nov 21, 2024 11:36 pm

Thanks, Tom.

The signal wire of the limit switch is directly connected to KFLop IO34 and IO35.

The tricky thing is if I keep the two optical limit switches connected to IO34 and IO35 and set LimitSwitchOptions to 0x112 //means just use the positive one. It works perfectly.

Once I change LimitSwitchOptions to 0x113 //, both the negative and positive sensors are enabled. The axis will often be stopped and disabled during movement even without triggering the optical switch.

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

Re: Limit switch issue

Post by TomKerekes » Fri Nov 22, 2024 12:04 am

The signal wire of the limit switch is directly connected to KFLop IO34 and IO35.
That doesn't explain how it is wired.

The tricky thing is if I keep the two optical limit switches connected to IO34 and IO35 and set LimitSwitchOptions to 0x112 //means just use the positive one. It works perfectly.
IO34 and IO35 are high impedance 3.3V LVTTL Inputs. You can not just connect them to a switch. When the switch is open the input will be floating and its voltage will be indeterminate. You might get lucky and sometimes work.

IO26 - IO33 have 150 Ohm pull down resistors. These will be guaranteed to be low when disconnected (switch open). So you could use a switch to connect them to 3.3V.

As I said it would be better to use the opto-isolated inputs. Long limit switch wiring running all over the system can pick up noise which will not be isolated from the high speed digital circuits.
Regards,

Tom Kerekes
Dynomotion, Inc.

xuphoenix
Posts: 14
Joined: Sun Apr 19, 2020 3:32 am

Re: Limit switch issue

Post by xuphoenix » Sat Nov 23, 2024 3:21 am

Thanks, Tom. I changed IO 34 and IO 35 to IO 32 and IO 33, which are connected to the signal pin of a 3.3V optical limit switch. This solved my issue.

Post Reply