SPINDLE SERVO SPECS

Moderators: TomKerekes, dynomotion

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

Re: SPINDLE SERVO SPECS

Post by turbothis » Mon Apr 08, 2019 8:56 pm

ok gotcha i will get into that....
thanks

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

Re: SPINDLE SERVO SPECS

Post by turbothis » Mon Apr 08, 2019 10:10 pm

this requires a physical bit input for CW and CCW also? bit 154 and 155
my brain is destroyed on the FACTOR count. i have 11872.46 per spindle rev
would this be FACTOR (118724.6/60.0)?

Code: Select all

#include "KMotionDef.h"

#define SPINDLEAXIS 4
#define FACTOR (1000/60.0) //1000 counts/sec / 1000 counts/rev = 1 RPS = 60 RPM
#define SPINDLECW_BIT 154
#define SPINDLECCW_BIT 155
#define SPEEDVAR 99
#define STATEVAR 98
#define KMVAR 1


// desired speed is passed from KMotionCNC in variable KMVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed

main()
{
	float speed = *(float *)&persist.UserData[SPEEDVAR];  // value stored is actually a float 
	float LastState = persist.UserData[STATEVAR];  // get last state 
	
	if (LastState==1)  
	{
		// if spindle was CW now we want CCW 
		// spin down
		
		ClearBit(SPINDLECW_BIT);
		ClearBit(SPINDLECCW_BIT);
		Jog(SPINDLEAXIS,0);
		while (!CheckDone(SPINDLEAXIS)) ;
	}
	
	// turn spindle on CCW and ramp to new speed
	SetBit(SPINDLECCW_BIT);
	
	// spindle is already on, so ramp to new speed
	Jog(SPINDLEAXIS,speed * FACTOR);
	printf("Jogging Spindle %f counts/sec\n",speed * FACTOR);
	
	persist.UserData[STATEVAR] = -1;  // remember we are CCW
}

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

Re: SPINDLE SERVO SPECS

Post by turbothis » Tue Apr 09, 2019 5:44 pm

i got my spindle rapid performance good using the MDi
just need to get the program set for S commands

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

Re: SPINDLE SERVO SPECS

Post by TomKerekes » Tue Apr 09, 2019 6:04 pm

Hi turbothis,
this requires a physical bit input for CW and CCW also? bit 154 and 155
Well how to control Spindles can vary depending on the Spindle Drive used. Most have some type of enable and direction inputs that need to be controlled. Since I believe you have a dual DAC type of drive it can be driven forward or reverse seamlessly as an axis so those might be removed or ignored.
i have 11872.46 per spindle rev
would this be FACTOR (118724.6/60.0)?
Did you intentionally move the decimal point?
Regards,

Tom Kerekes
Dynomotion, Inc.

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

Re: SPINDLE SERVO SPECS

Post by turbothis » Tue Apr 09, 2019 6:24 pm

ya, i am terrible at getting this type of numbers hammered out
so it would be FACTOR (11872.46/60.0) then?

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

Re: SPINDLE SERVO SPECS

Post by TomKerekes » Tue Apr 09, 2019 6:29 pm

Hi turbothis,
so it would be FACTOR (11872.46/60.0) then?
I believe so.
Regards,

Tom Kerekes
Dynomotion, Inc.

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

Re: SPINDLE SERVO SPECS

Post by turbothis » Tue Apr 09, 2019 6:50 pm

ok so i got rid of the bit stuff and ended up with this

Code: Select all

#include "KMotionDef.h"

#define SPINDLEAXIS 4
#define FACTOR (11872.46/60.0) //1000 counts/sec / 1000 counts/rev = 1 RPS = 60 RPM
#define SPEEDVAR 99
#define STATEVAR 98
#define KMVAR 1


// desired speed is passed from KMotionCNC in variable KMVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed

main()
{
	float speed = *(float *)&persist.UserData[SPEEDVAR];  // value stored is actually a float 
	float LastState = persist.UserData[STATEVAR];  // get last state 
	
	if (LastState==1)  
	{
		
		Jog(SPINDLEAXIS,0);
		while (!CheckDone(SPINDLEAXIS)) ;
	}
	
	
	
	// spindle is already on, so ramp to new speed
	Jog(SPINDLEAXIS,speed * FACTOR);
	printf("Jogging Spindle %f counts/sec\n",speed * FACTOR);
	
	persist.UserData[STATEVAR] = -1;  // remember we are CCW
}

i really dont know what the VAR or variable thing means or refers to. any pointers on this?

plus here are my M settings

Image

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

Re: SPINDLE SERVO SPECS

Post by TomKerekes » Tue Apr 09, 2019 7:27 pm

Hi turbothis,

It seems you have assigned the same program for turning on the spindle (M3) and for setting the speed (S). Also M3 is normally to set the Spindle CW not CCW.

Actually I made a mistake and mislead you earlier. The best example programs to use are in the \C Programs\SpindleUsingJogs\CSS folder. These use a header file that is included to avoid duplicating things.

Please read this carefully and follow the instructions. It describes how the Var is used to pass the desired speed from KMotionCNC to the S Program.
Regards,

Tom Kerekes
Dynomotion, Inc.

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

Re: SPINDLE SERVO SPECS

Post by turbothis » Tue Apr 09, 2019 7:36 pm

great! i will do my homework and try to not burn up all your time
some of this stuff is very hard for me though
i cant thank you enough
once this lathe is done i plan on getting 2 more kflop/kanalog boards for my remaining 2 machines

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

Re: SPINDLE SERVO SPECS

Post by turbothis » Tue Apr 09, 2019 8:04 pm

outstanding
it is working good

for some reason the CCW program spins CW too

Code: Select all

#include "KMotionDef.h"

#include "MySpindleDefs.h"

int   *css_mode = &persist.UserData[PC_COMM_CSS_MODE];			// Mode 1=Normal RPM mode. 2=CSS

// desired speed is passed from KMotionCNC in variable KMVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed

main()
{
	float speed = *(float *)&persist.UserData[SPEEDVAR];  // value stored is actually a float 
	float LastState = persist.UserData[STATEVAR];  // get last state 
	
	if (LastState==1)  
	{
		// if spindle was CW now we want CCW 
		// spin down
		
		ClearBit(SPINDLECW_BIT);
		ClearBit(SPINDLECCW_BIT);
		Jog(SPINDLEAXIS,0);
		while (!CheckDone(SPINDLEAXIS)) ;
	}
	
	// turn spindle on CCW and ramp to new speed
	SetBit(SPINDLECCW_BIT);
	
	LastState = -1;
	
	if (*css_mode != 2)
	{
		// spindle is already on, so ramp to new speed
		if (USE_POS_NEG_VOLTAGE)
			Jog(SPINDLEAXIS,speed * FACTOR * LastState);
		else
			Jog(SPINDLEAXIS,speed * FACTOR);
		
		printf("Jogging Spindle %f counts/sec\n",speed * FACTOR);
	}	
	persist.UserData[STATEVAR] = -1;  // remember we are CCW
}


my new Hdefs.H

Code: Select all

#define SPINDLEAXIS 2			// Axis Channel to Jog to rotate Spindle
#define FACTOR (11872.46/60.0)  	// to convert RPM to counts/sec (counts/rev / 60.0sec)
#define SPINDLECW_BIT 154   	// bit to activate to cause CW rotation
#define SPINDLECCW_BIT 155		// bit to activate to cause CCW rotation
#define SPEEDVAR 99				// global persistant variable to store latest speed
#define STATEVAR 98				// global persistant variable to store latest state (-1=CCW,0=off,1=CW)
#define KMVAR PC_COMM_CSS_S 	// variable KMotionCNC will pass speed parameter (113)
#define USE_POS_NEG_VOLTAGE 0 	// 0 = output Magnitude, 1 = output positive and negative speed 

Post Reply