Originally Posted by
TomKerekes
I assume SpindleSpeed.c is the program I posted?
Yes, that's what I saved it as.
Originally Posted by
TomKerekes
Did you do an S command?
Yes, I't responds the same way by not deactivating Bit 159.
Originally Posted by
TomKerekes
Axis 7 is only being used to read the spindle encoder. For that the axis doesn't need to be enabled. It also should not be included in the Coordinated Motion System as axis A. But that would interfere with the solenoid bits,
I'll clear those parts.
My Spindle Deffinitions:
Code:
#define SPINDLEAXIS 7 // Axis Channel to Jog to rotate Spindle
#define FACTOR (10000/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 SPINDLEBREAK_BIT 157 // bit to activate/deactivate spindle break
#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
This code is used to ClearBit (activates) and SetBit (deactivates) the spindle break (Bit157).
Code:
#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);
ClearBit(Coolant);
Delay_sec(0.5);
ClearBit(SPINDLEBREAK_BIT);
printf("Jogging Spindle Stop\n");
persist.UserData[STATEVAR] = 0; // remember we are Off
while (!CheckDone(SPINDLEAXIS)) ;
}
lets me turn on spindle CCW
Code:
#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);
SetBit(SPINDLEBREAK_BIT);
LastState = -1;
persist.UserData[STATEVAR] = -1; // remember we are CCW
}
Lets me turn on Sindle CW.
Code:
#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);
SetBit(SPINDLEBREAK_BIT);
LastState = -1;
persist.UserData[STATEVAR] = -1; // remember we are CCW
}