Each macro is sending appropriate commands via UCCNC Modbus interface to the inverter. UCCNC sends these commands to the VFD and reads back the status. The G-code execution is stopped until the appropriate action is finished, i.e. M3 command will result in waiting until the VFD reports back that the spindle speed is reached, likewise the M4. M5 command will result in waiting until the spindle is reported stopped by the VFD. This way there is no need to have a special delay in UCCNC, code execution can begin as soon as the speed is reached.
- Code: Select all
//
// M3 macro
//
// This macro is to be used with Modbus control.
// Usable only with Bosch Rexroth EFC5610 or compatible VFD.
//
// Read screen object for spindle speed and convert the RPM to freqency.
// Set Modbus register 1 to the frequency value.
// Set Modbus register 0 to RUN CW command.
// Wait for the spindle to spin up before excit
//
string SpindleSpeedValue; // SetSpindleSpeed screen object string
double SSpeedValue; // SetSpindleSpeed screen object converted
ushort SFrequency; // Spindle speed frequency to VFD
ushort RunSpindleCW = 129; // Rexroth EFC5610 RUN CW command
ushort SpindleSpeedReached = 0; // Set to 1 when spindle speed is reached
SpindleSpeedValue = AS3.Getfield(869); // Get the S-word from the display
SSpeedValue = Convert.ToDouble(SpindleSpeedValue); // Concert string to double
SFrequency = (ushort) (SSpeedValue / 0.6); // Frequency = Spindle S-word / 0.6
exec.SetModbusregister(1, SFrequency); // This frequency will be sent to VFD
exec.SetModbusregister(3, 0); // This register contains the "Speed arrival" flag
SpindleSpeedReached = 0;
exec.SetModbusregister(0, RunSpindleCW);
exec.DospinCW();
//
// Now wait for the spindle speed to reach the set RPM
//
while (SpindleSpeedReached == 0)
{
exec.GetModbusregister(3, out SpindleSpeedReached);
}
- Code: Select all
//
// M4 macro
//
// This macro is to be used with Modbus control.
// Usable only with Bosch Rexroth EFC5610 or compatible VFD.
//
// Read screen object for spindle speed and convert the RPM to freqency.
// Set Modbus register 1 to the frequency value.
// Set Modbus register 0 to RUN CW command.
// Wait for the spindle to spin up before exit
//
string SpindleSpeedValue; // SetSpindleSpeed screen object string
double SSpeedValue; // SetSpindleSpeed screen object converted
ushort SFrequency; // Spindle speed frequency to VFD
ushort RunSpindleCCW = 133; // Rexroth EFC5610 RUN CCW command
ushort SpindleSpeedReached = 0; // Set to 1 when spindle speed is reached
SpindleSpeedValue = AS3.Getfield(869); // Get the S-word from the display
SSpeedValue = Convert.ToDouble(SpindleSpeedValue); // Concert string to double
SFrequency = (ushort) (SSpeedValue / 0.6); // Frequency = Spindle S-word / 0.6
exec.SetModbusregister(1, SFrequency); // This frequency will be sent to VFD
exec.SetModbusregister(3, 0); // This register contains the "Speed arrival" flag
SpindleSpeedReached = 0;
exec.SetModbusregister(0, RunSpindleCCW);
exec.DospinCCW();
//
// Now wait for the spindle speed to reach the set RPM
//
while (SpindleSpeedReached == 0)
{
exec.GetModbusregister(3, out SpindleSpeedReached);
}
- Code: Select all
//
// M5 macro
//
// This macro is to be used with Modbus control.
// Usable only with Bosch Rexroth EFC5610 or compatible VFD.
//
// This macro stops the spindle and waits for VFD to report back.
// Exit when the spindle is reported stopped by the VFD.
//
ushort StopSpindleRun = 136; // Rexroth EFC5610 STOP command
ushort CommStateReg; // Value of Communication State Register
ushort SpindleSpeedReached = 1; // Set to 0 when spindle speed is not reached or lost
exec.SetModbusregister(0, StopSpindleRun); // Send Rexroth EFC5610 STOP command to VFD
//
// First wait for the spindle speed to drop
//
while (SpindleSpeedReached == 1) // Zero indicates spindle speed lost
{
exec.GetModbusregister(3, out SpindleSpeedReached);
}
//
// Wait for the spindle speed to stop
//
exec.GetModbusregister(2, out CommStateReg);
while ((CommStateReg & 0x0002) == 1) // Test bit 1 in Communication State Register
{
exec.GetModbusregister(2, out CommStateReg);
}
exec.Stopspin(); // Execute UCCNC macro call
The above macros are tested with this G-code, which does nothing useful except some movement and spindle spinning. Please note, don't run this G-code with the spindle risking of touching any work. The rotation is reversed in the code and nasty things might happen. This code is just for testing the spindle rotation changes and the stop, not for milling.
- Code: Select all
M3 S6123
G1 X120 F880
M5
M4 S12345
G1 X90 F880
M5
M3
G1 X80 F280
M5
M30
(end)
I don't know if anyone is interested in this, but will continue update this thread after changes. I think my macros can be used even for other VFD with some modification, but I can not test with anything else than my Bosch Rexroth EFC5610.