I did not write a macro for you according to your specifications, but I share what fits my VFD. This is a stripped down version of what I actually use, but it should be pretty easy for you to work with. The parts which I removed handle some VFD parameters, like spindle speed reached and some other monitoring functions. The basic principle is simple, check CW and CCW LEDs and send the matching command to the VFD, as well as the frequency matching the desired spindle RPM, compensated for the SS override and checked for maximum RPM. I allow any RPM between zero to maximum RPM.
- Code: Select all
// ----------------------------------------------------------------------------------------------------
//
// M20305 Seting the spindle speed, runing CW/CCW and reading some VFD and spindle parameters.
// This is a Modbus interface macro and is running in a macro loop.
//
// When this macro is called it will check the Set Spindle Speed and the Speindle Speed Override DRO
// and will calculate the matching frequency. This is set in Modbus register which is sent to the VFD.
//
// After this step it will check the state of RUN CW/CCW LEDs and will set the necessary VFD commands.
//
// ----------------------------------------------------------------------------------------------------
//
// Constants
//
ushort RunSpindleCW = 129; // Rexroth EFC5610 RUN CW command
ushort RunSpindleCCW = 133; // Rexroth EFC5610 RUN CCW command
ushort StopSpindleRun = 136; // Rexroth EFC5610 STOP command
ushort SSetDRO = 869;
ushort SactDRO = 870;
ushort SSOverriddenDRO = 2451;
ushort MaxSpindleSpeedDRO = 178;
double MaximumRPM = 24000;
ushort SpindleRunReg = 0; // Displayed UCCNC Modbus register list
ushort VFDFrequencyReg = 1;
//
// Variables
//
string SspeedOverride;
int IndexOfPercentSign;
string SSpeedOverride;
double SSpeedHz;
//
// Program starts here
//
//-------------- Set spindle speed value firtst ---------------------------------------------------------------
//
//
MaximumRPM = AS3.Getfielddouble(MaxSpindleSpeedDRO);
SSpeedHz = ( AS3.Getfielddouble(SSOverriddenDRO));
if (SSpeedHz > MaximumRPM)
{
SSpeedHz = MaximumRPM; // Force maximum RPM to prevent exception
}
//
// Calculate the matching RPM frequency and send the value to Modbus register.
//
exec.SetModbusregister(VFDFrequencyReg, (ushort) Convert.ToUInt16(SSpeedHz / 0.6));
//
//-------------- Send start/stop command for the spindle --------------------------------------------------------
//
// Check the CW and CCW LEDs and convert the state to spindle control commands.
// The command is set in the Modbus register which is sent to VFD using the UCCNC Modbus internal handler.
//
// Check CW and CCW LEDs, start or stop the spindle based on LED states.
// After exiting this macro the Modbus register is set up for CW, CCW or Stop
//
if ( AS3.GetLED(50) == true ) // If the RUN CW LED is active
{
exec.SetModbusregister(SpindleRunReg, RunSpindleCW); //Turn spindle on in CW rotation if LED is on
}
else
if ( AS3.GetLED(51) == true ) // If the RUN CCW LED is active
{
exec.SetModbusregister(SpindleRunReg, RunSpindleCCW); //Turn spindle on in CCW rotation if LED is on
}
else // CW and CCW LEDs are off, send turn spindle OFF commnad
{
exec.SetModbusregister(SpindleRunReg, StopSpindleRun); // Send Rexroth EFC5610 STOP command to VFD
}
//
// ------------------------------------------------------------------------------------------------------
//
//
//------------------------------------------------------------------------------------------------------
//
// End of program
Of course, Modbus master plugin must be enabled, configured and run as well.