Mach3 Plugin
KMotion/KFlop Mach3
Mach3 is a popular CNC program available for purchase through ArtSoftControls.
Traditionally Mach3 has relied on little hardware support and performed low level motion and even stepper motor step pulses directly by the PC. The pulses were output using the PC's parallel port. This required a special Microsoft Windows Kernel driver with a high interrupt rate and was limited to 50~100K steps per second.
Mach3 has the capability for adding "plugins" that allow additional functionality and hardware support. DynoMotion has developed a plugin that allows Mach3 to work with a KMotion or KFLOP Motion Controller. The offloads most of the real-time requirements from the PC, allows USB connectivity, much higher step rates, and allows easily adding other motor types including brushless servos.
This is an overview of the overall setup process of getting Mach3 and KMotion to play together.
1. Install Mach3
Mach3 should be installed before KMotion so that the KMotion installation program can copy the necessary files (Dynomotion.dll) into the Mach3 plugin directory. The KMotion installation will also add a registry entry under "App Paths" so that Mach3.exe will have access to the necessary KMotion DLL libraries, programs, and data files
It is not necessary to load the Mach3 Kernel driver.
If KMotion has already been installed, it should be re-installed to make the necessary links between the programs.
2. Install KMotion
At the end of the KMotion installation an option to install the Mach3 Plugin will be displayed.
Check the Mach3 Plugin option and select Next.
You will be prompted to enter the directory where Mach3 was installed.
A check will be made that a valid Mach3.exe exists in that directory, and the Dynomotion.dll will be copied to the plugins subdirectory.
3. Within KMotion configure/tune your motors
Follow the normal procedures to use the KMotion Executive program to configure and tune all of your motor axes. The simplest method to configure the system is to enter and change values in the various KMotion Executive Screens, download them to the KMotion Board, and test and tune for correct operation using the Step Response Screen as well as Console commands.
4. Within KMotion create a configuration and initialization program
After each axis is functioning properly, the configuration for that axis can be copied to the clipboard as a valid C program code.
See the circled button below.
C Code to configure axis 0 might look like the code shown below. Detailed knowledge of C programming is not required to paste these into a User Program. The configuration for each axis should be pasted into a single program. Later this program may be executed at any time to completely configure the KMotion Board. The KMotion Executive program would not be needed to do this. The RESET button from within Mach3 will be configured to execute this program.
ch0->InputMode=ENCODER_MODE;
ch0->OutputMode=MICROSTEP_MODE;
ch0->Vel=100.000000;
ch0->Accel=1000.000000;
ch0->Jerk=10000.000000;
ch0->P=1.000000;
ch0->I=0.000000;
ch0->D=0.000000;
ch0->FFAccel=0.000000;
ch0->FFVel=0.000000;
ch0->MaxI=200.000000;
ch0->MaxErr=200.000000;
ch0->MaxOutput=200.000000;
ch0->DeadBandGain=1.000000;
ch0->DeadBandRange=0.000000;
ch0->InputChan0=0;
ch0->InputChan1=1;
ch0->OutputChan0=0;
ch0->OutputChan1=1;
ch0->LimitSwitchOptions=0x0;
ch0->InputGain0=1.000000;
ch0->InputGain1=1.000000;
ch0->InputOffset0=0.000000;
ch0->InputOffset1=0.000000;
ch0->invDistPerCycle=1.000000;
ch0->Lead=0.000000;
ch0->MaxFollowingError=1000000000.000000;
ch0->StepperAmplitude=250.000000;
ch0->iir[0].B0=1.000000;
ch0->iir[0].B1=0.000000;
ch0->iir[0].B2=0.000000;
ch0->iir[0].A1=0.000000;
ch0->iir[0].A2=0.000000;
ch0->iir[1].B0=1.000000;
ch0->iir[1].B1=0.000000;
ch0->iir[1].B2=0.000000;
ch0->iir[1].A1=0.000000;
ch0->iir[1].A2=0.000000;
ch0->iir[2].B0=1.000000;
ch0->iir[2].B1=0.000000;
ch0->iir[2].B2=0.000000;
ch0->iir[2].A1=0.000000;
ch0->iir[2].A2=0.000000;
Besides C code to configure each axis, other commands such as those shown highlighted below may be used to enable each axis (and set the destination) and to define which axis channels are in the coordinated motion system. The DefineCoordSystem(0,1,-1,-1); statement defines a two axis coordinate system where X is axis channel 0, Y is axis channel 1, and the Z and A axes are not used.
The circled button can be used to save, compile, download, and run the C program in one step. Note that once a C program has been executed to change configuration settings within the KMotion Board, the values in the KMotion Executive screens may be different from the current settings within the board. To synchronize the screens with what is actually in the board the channel should be "Uploaded".
Additional initialization operations may also be added to the C Progam. These might include brushless motor phase finding, homing, activating IO bits, etc..
After the Initialization program is finalized and working it should be saved in a known location so that Mach3 may be configured to execute it as described in the next step.
5. Within Mach3 - configure plugin (enter name of KMotion Init program)
We are now ready to Execute Mach3. The first time Mach3 is executed after adding the Dynomotion Plugin Mach3 will prompt the user which Motion Device should be used. The Dynomotion Plugin should be selected. After the Mach3 Application comes up use the Config|Config Plugins menu to bring up the Config Plugins dialog shown below.
Next click in the circled area to bring up the Dynomotion Plugin Configuration Screen.
Specify the KMotion Initialize User Program that was created in step 4 above (you may browse to the file using the >> button).
The Windows Buffer ahead Time may be changed to keep more or less buffering ahead in the KMotion Board. Using a value too small may cause the buffer to run empty and "starve" for data if Windows becomes non-responsive for longer than that amount of time. Using a value too large will cause feed rate changes and feed hold commands to be less responsive.
The plugin can be configured to Automatically run Initialize on Mach Startup if desired. Caution:This option should be left off if there is any potential danger with unexpected machine motion when launching Mach3.
After setting al parameters press OK to save the parameters into the Mach3 XML parameter file and return to the main Mach Screen. Pushing Mach3's Reset button will now execute the Initialize program.
6. Within Mach3 - configure motor tuning (set resolution, speeds, and acceleration)
Select Config|Motor Tuning to bring up the Motor Tuning Dialog. This screen allows the setting of Machine resolution, Max Velocity, and Max Acceleration for each axis in use. Note that the sliders are typically not very useful since the max step rates are much higher using a KMotion Motion Controller than with the original PC Generated Steps. It's usually best to just enter values directly into the cells.
After the parameters have been entered and saved, Press OK to return to the main screen.
7. Within Mach3 - configure IO Bits.
Various M Codes may be used within Mach3 to activate
IO bits on KMotion. Select the Menu Config|Ports & Pins to bring
up the Dialog shown below. When using the KMotion Plugin, Pin
Numbers now correspond to KMotion IO Bit Numbers rather than
Parallel port Pins. Some of the terminology on the screen may be
misleading as it was designed expecting to use a parallel port. Note
Mach3 typically defaults after an initial install with Output #1 enabled
for spindle control on Pin0 (as shown below). Bit 0 is often used
on a KMotion board as an Encoder input. Having Mach configure the
IO bit as an output will cause the encoder to be inoperable.
Disable the output if this is the case.
That's it! Reset should now properly initialize the machine. Jogging and G Code should now be functional.
Refer to the Mach3 documentation for more information on advanced features.
Here is how a GCode file appears on Mach3 Mill.
Here the same example GCode file cut (or more accurately burned) into a piece of wood using a Harbor Freight Mini-mill driven with KMotion and Mach3.