simple 2 axis lathe initial lathe set up

Moderators: TomKerekes, dynomotion

Post Reply
turbothis
Posts: 310
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

simple 2 axis lathe initial lathe set up

Post by turbothis » Sat Nov 11, 2023 2:42 am

just getting my lathe converted to cnc and are now in the code section of it

1 two DC servo motors with 2000 count encoders. X is 6mm pitch and Z axis looks to be 10mm. both will be direct coupled
2 10volt output to VFD. 3 phase spindle motor with a single ( Z right? ) from a hall sensor


so far i got the spindle working CW and CCW with accurate RPM
going to wire in the hall tomorrow. i am thinking it will run off a 5V from JP8 and then signal into JP15 opto inputs?
i got a C code example for my initial code. says pin 36 input.....

when i try and user button my init the encoders stay yellow. do the encoders need to be wired in for them to go blue?

what i got so far

Code: Select all

#include "KMotionDef.h"

// counts pulses on single pulse encoder for Spindle
#define SPINDLE_PULSE_BIT 36
#define SPINDLE_AXIS 7


int main() {
    int NewState, LastState = ReadBit(SPINDLE_PULSE_BIT);

    for (;;) {
        NewState = ReadBit(SPINDLE_PULSE_BIT);

        if (NewState != LastState) {
            LastState = NewState;
            if (NewState) {
                chan[SPINDLE_AXIS].Position++;
            }
        }
    }


	ch0->InputMode=ENCODER_MODE;
	ch0->OutputMode=DAC_SERVO_MODE;
	ch0->Vel=100;
	ch0->Accel=1000;
	ch0->Jerk=10000;
	ch0->P=1;
	ch0->I=0;
	ch0->D=0;
	ch0->FFAccel=0;
	ch0->FFVel=0;
	ch0->MaxI=200;
	ch0->MaxErr=200;
	ch0->MaxOutput=200;
	ch0->DeadBandGain=1;
	ch0->DeadBandRange=0;
	ch0->InputChan0=0;
	ch0->InputChan1=1;
	ch0->OutputChan0=0;
	ch0->OutputChan1=1;
	ch0->MasterAxis=-1;
	ch0->LimitSwitchOptions=0x100;
	ch0->LimitSwitchNegBit=0;
	ch0->LimitSwitchPosBit=0;
	ch0->SoftLimitPos=1e+09;
	ch0->SoftLimitNeg=-1e+09;
	ch0->InputGain0=1;
	ch0->InputGain1=1;
	ch0->InputOffset0=0;
	ch0->InputOffset1=0;
	ch0->OutputGain=1;
	ch0->OutputOffset=0;
	ch0->SlaveGain=1;
	ch0->BacklashMode=BACKLASH_OFF;
	ch0->BacklashAmount=0;
	ch0->BacklashRate=0;
	ch0->invDistPerCycle=1;
	ch0->Lead=0;
	ch0->MaxFollowingError=1000000000;
	ch0->StepperAmplitude=250;

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

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

	ch0->iir[2].B0=1;
	ch0->iir[2].B1=0;
	ch0->iir[2].B2=0;
	ch0->iir[2].A1=0;
	ch0->iir[2].A2=0;
    EnableAxis(0);

	ch1->InputMode=ENCODER_MODE;
	ch1->OutputMode=DAC_SERVO_MODE;
	ch1->Vel=100;
	ch1->Accel=1000;
	ch1->Jerk=10000;
	ch1->P=1;
	ch1->I=0;
	ch1->D=0;
	ch1->FFAccel=0;
	ch1->FFVel=0;
	ch1->MaxI=200;
	ch1->MaxErr=200;
	ch1->MaxOutput=200;
	ch1->DeadBandGain=1;
	ch1->DeadBandRange=0;
	ch1->InputChan0=1;
	ch1->InputChan1=2;
	ch1->OutputChan0=1;
	ch1->OutputChan1=3;
	ch1->MasterAxis=-1;
	ch1->LimitSwitchOptions=0x100;
	ch1->LimitSwitchNegBit=0;
	ch1->LimitSwitchPosBit=0;
	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=250;

	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=1;
	ch1->iir[2].B1=0;
	ch1->iir[2].B2=0;
	ch1->iir[2].A1=0;
	ch1->iir[2].A2=0;
    EnableAxis(3);

	DefineCoordSystem(0,-1,1,-1);

    
}

turbothis
Posts: 310
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Sat Nov 11, 2023 2:56 am

Image
Attachments
Capture.PNG

turbothis
Posts: 310
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Sat Nov 11, 2023 2:59 am

on a side note, i get this error when i bring up the help menus
Attachments
fffff.PNG

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

Re: simple 2 axis lathe initial lathe set up

Post by TomKerekes » Sat Nov 11, 2023 2:32 pm

Hi,
i am thinking it will run off a 5V from JP8 and then signal into JP15 opto inputs?
i got a C code example for my initial code. says pin 36 input.....
You would need to check the specification for the hall sensor. If KFLOP’s 5V is used then the signal will not be isolated.

The code uses Bit 36 not Pin 36.

when i try and user button my init the encoders stay yellow. do the encoders need to be wired in for them to go blue?
The axes must be configured and enabled before the forever loop. Anything after a forever loop will never be executed.

Axis 3 is being enabled instead of 1.
Regards,

Tom Kerekes
Dynomotion, Inc.

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

Re: simple 2 axis lathe initial lathe set up

Post by TomKerekes » Sat Nov 11, 2023 2:33 pm

Regarding the help Version 5.3.0 should not do this.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 310
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Sat Nov 11, 2023 6:22 pm

i am running Kmotion 435h because i am scared of new things and it works perfect on my mill

ok buttered up the code
how would i wire in the hall?
run 5v from bit 16 on the JP8 to hall then signal to bit 36 on JP2?

Code: Select all

#include "KMotionDef.h"

// counts pulses on single pulse encoder for Spindle
#define SPINDLE_PULSE_BIT 36
#define SPINDLE_AXIS 7


int main() {
    int NewState, LastState = ReadBit(SPINDLE_PULSE_BIT);

    for (;;) {
        NewState = ReadBit(SPINDLE_PULSE_BIT);

        if (NewState != LastState) {
            LastState = NewState;
            if (NewState) {
                chan[SPINDLE_AXIS].Position++;
            }
        }
    


	ch0->InputMode=ENCODER_MODE;
	ch0->OutputMode=DAC_SERVO_MODE;
	ch0->Vel=100;
	ch0->Accel=1000;
	ch0->Jerk=10000;
	ch0->P=1;
	ch0->I=0;
	ch0->D=0;
	ch0->FFAccel=0;
	ch0->FFVel=0;
	ch0->MaxI=200;
	ch0->MaxErr=200;
	ch0->MaxOutput=200;
	ch0->DeadBandGain=1;
	ch0->DeadBandRange=0;
	ch0->InputChan0=0;
	ch0->InputChan1=1;
	ch0->OutputChan0=0;
	ch0->OutputChan1=1;
	ch0->MasterAxis=-1;
	ch0->LimitSwitchOptions=0x100;
	ch0->LimitSwitchNegBit=0;
	ch0->LimitSwitchPosBit=0;
	ch0->SoftLimitPos=1e+09;
	ch0->SoftLimitNeg=-1e+09;
	ch0->InputGain0=1;
	ch0->InputGain1=1;
	ch0->InputOffset0=0;
	ch0->InputOffset1=0;
	ch0->OutputGain=1;
	ch0->OutputOffset=0;
	ch0->SlaveGain=1;
	ch0->BacklashMode=BACKLASH_OFF;
	ch0->BacklashAmount=0;
	ch0->BacklashRate=0;
	ch0->invDistPerCycle=1;
	ch0->Lead=0;
	ch0->MaxFollowingError=1000000000;
	ch0->StepperAmplitude=250;

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

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

	ch0->iir[2].B0=1;
	ch0->iir[2].B1=0;
	ch0->iir[2].B2=0;
	ch0->iir[2].A1=0;
	ch0->iir[2].A2=0;
    EnableAxis(0);

	ch1->InputMode=ENCODER_MODE;
	ch1->OutputMode=DAC_SERVO_MODE;
	ch1->Vel=100;
	ch1->Accel=1000;
	ch1->Jerk=10000;
	ch1->P=1;
	ch1->I=0;
	ch1->D=0;
	ch1->FFAccel=0;
	ch1->FFVel=0;
	ch1->MaxI=200;
	ch1->MaxErr=200;
	ch1->MaxOutput=200;
	ch1->DeadBandGain=1;
	ch1->DeadBandRange=0;
	ch1->InputChan0=1;
	ch1->InputChan1=2;
	ch1->OutputChan0=1;
	ch1->OutputChan1=3;
	ch1->MasterAxis=-1;
	ch1->LimitSwitchOptions=0x100;
	ch1->LimitSwitchNegBit=0;
	ch1->LimitSwitchPosBit=0;
	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=250;

	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=1;
	ch1->iir[2].B1=0;
	ch1->iir[2].B2=0;
	ch1->iir[2].A1=0;
	ch1->iir[2].A2=0;
    EnableAxis(1);

	DefineCoordSystem(0,-1,1,-1);

	return 0;
    }
}

turbothis
Posts: 310
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Sun Nov 12, 2023 6:30 pm

i got the hall wired to bit 36 and it does show it working in the digital I/O tab
i get no rpm reading though

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

Re: simple 2 axis lathe initial lathe set up

Post by TomKerekes » Sun Nov 12, 2023 7:03 pm

The initialization and return is now inside the ‘for’ loop so it executes once and returns. The for loop should be after the initialization but before the return. You might read this.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 310
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Sun Nov 12, 2023 8:19 pm

great!
ill get chatbot helping more on this

so far we come up with
the X axis screw of 0.23622 Inches pitch and 2000 count then the Z screw of 0.3937 Inches pitch and 2000 count
Attachments
Capture.PNG

turbothis
Posts: 310
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Sun Nov 12, 2023 8:44 pm

ok ya that makes sense!

Code: Select all

#include "KMotionDef.h"

// counts pulses on single pulse encoder for Spindle
#define SPINDLE_PULSE_BIT 36
#define SPINDLE_AXIS 7


int main() {

    int NewState, LastState = ReadBit(SPINDLE_PULSE_BIT);


	ch0->InputMode=ENCODER_MODE;
	ch0->OutputMode=DAC_SERVO_MODE;
	ch0->Vel=100;
	ch0->Accel=1000;
	ch0->Jerk=10000;
	ch0->P=1;
	ch0->I=0;
	ch0->D=0;
	ch0->FFAccel=0;
	ch0->FFVel=0;
	ch0->MaxI=200;
	ch0->MaxErr=200;
	ch0->MaxOutput=200;
	ch0->DeadBandGain=1;
	ch0->DeadBandRange=0;
	ch0->InputChan0=0;
	ch0->InputChan1=1;
	ch0->OutputChan0=0;
	ch0->OutputChan1=1;
	ch0->MasterAxis=-1;
	ch0->LimitSwitchOptions=0x100;
	ch0->LimitSwitchNegBit=0;
	ch0->LimitSwitchPosBit=0;
	ch0->SoftLimitPos=1e+09;
	ch0->SoftLimitNeg=-1e+09;
	ch0->InputGain0=1;
	ch0->InputGain1=1;
	ch0->InputOffset0=0;
	ch0->InputOffset1=0;
	ch0->OutputGain=1;
	ch0->OutputOffset=0;
	ch0->SlaveGain=1;
	ch0->BacklashMode=BACKLASH_OFF;
	ch0->BacklashAmount=0;
	ch0->BacklashRate=0;
	ch0->invDistPerCycle=1;
	ch0->Lead=0;
	ch0->MaxFollowingError=1000000000;
	ch0->StepperAmplitude=250;

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

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

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

	ch1->InputMode=ENCODER_MODE;
	ch1->OutputMode=DAC_SERVO_MODE;
	ch1->Vel=100;
	ch1->Accel=1000;
	ch1->Jerk=10000;
	ch1->P=1;
	ch1->I=0;
	ch1->D=0;
	ch1->FFAccel=0;
	ch1->FFVel=0;
	ch1->MaxI=200;
	ch1->MaxErr=200;
	ch1->MaxOutput=200;
	ch1->DeadBandGain=1;
	ch1->DeadBandRange=0;
	ch1->InputChan0=1;
	ch1->InputChan1=2;
	ch1->OutputChan0=1;
	ch1->OutputChan1=3;
	ch1->MasterAxis=-1;
	ch1->LimitSwitchOptions=0x100;
	ch1->LimitSwitchNegBit=0;
	ch1->LimitSwitchPosBit=0;
	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=250;

	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=1;
	ch1->iir[2].B1=0;
	ch1->iir[2].B2=0;
	ch1->iir[2].A1=0;
	ch1->iir[2].A2=0;
	
	
	EnableAxis(0);
    EnableAxis(1);
    

	DefineCoordSystem(0,-1,1,-1);
	
	for (;;) {
        NewState = ReadBit(SPINDLE_PULSE_BIT);

        if (NewState != LastState) {
            LastState = NewState;
            if (NewState) {
                chan[SPINDLE_AXIS].Position++;
            }
        }
    }
	return 0;
    
}

now i get readings of about 100,000 rpm at an actual 500 rpm on the spindle. i have a sweet digital rpm reader

i feel like the C code, spindle S command and thread specs might not be working together?
is there a better way in making the spindle into an axis with a single pulse for closed loop VFD drive?
Attachments
thread.PNG
thread.PNG (3.82 KiB) Viewed 465 times
spindle.PNG
spindle.PNG (5.9 KiB) Viewed 465 times
61XGTjQag8L._AC_SX425_.jpg

Post Reply