ok i got the spindle performing well
the only issue is i have to double push the CW/CCW buttons to work
which ever button i push first is the way it will rotate. (first push does nothing but pick which way to rotate)
the second time i push one of the buttons it will turn on spindle. ( this can be either CW or CCW as the first button push locks in which direction to rotate)
my CW
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
int LastState = persist.UserData[STATEVAR]; // get last state
if (CS0_axis_a == -1 && !ch2->Enable) // is A axis not defined in the Coordinate System and not enabled?
EnableAxis(2); // yes, enable the axis
if (LastState==-1)
{
// if spindle was CCW now we want CW
// spin down
ClearBit(SPINDLECW_BIT);
ClearBit(SPINDLECCW_BIT);
Jog(SPINDLEAXIS,0);
while (!CheckDone(SPINDLEAXIS)) ;
}
// turn spindle on CW and ramp to new speed
SetBit(SPINDLECW_BIT);
LastState = 1; // Add string
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 CW
}
my CCW
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
int LastState = persist.UserData[STATEVAR]; // get last state
if (CS0_axis_a == -1 && !ch2->Enable) // is A axis not defined in the Coordinate System and not enabled?
EnableAxis(2); // yes, enable the axis
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 jog
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[KMVAR]; // value stored is actually a float
int LastState = persist.UserData[STATEVAR]; // get last state
persist.UserData[SPEEDVAR] = persist.UserData[KMVAR]; // Always save the last desired speed
if (LastState==0 || *css_mode == 2)
{
// if spindle is off (or CSS mode) and User Changes the speed
// just save the desired speed
return 0;
}
// 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);
}
my off
Code: Select all
#include "KMotionDef.h"
#include "MySpindleDefs.h"
// 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()
{
// spin down
ClearBit(SPINDLECW_BIT);
ClearBit(SPINDLECCW_BIT);
Jog(SPINDLEAXIS, 0);
printf("Jogging Spindle Stop\n");
persist.UserData[STATEVAR] = 0; // remember we are Off
while (!CheckDone(SPINDLEAXIS));
if (CS0_axis_a == -1) // is A axis not defined in the Coordinate System?
DisableAxis(2); // yes, disable the axis, otherwise leave it enabled
}