Application Notes
Converting MDrive MCode to Liberty MCode
Home > Resources > Application Notes > Converting MDrive MCode to Liberty MCode
Description
There are minor differences between classic MCode and Liberty* MCode. This application note discusses those differences and takes you step-by-step through converting a program written for MDrivePlus to Liberty* MCode.
Applicable
- Liberty* MDrive
- MDrive Linear Actuator
- MDrive Plus
- MForce
Requirements
MDrive MCode Device
- MDrive Plus
- MDrive Linear
- MForce
Liberty* MCode Device
- Liberty* MDrive
- Liberty* Motion Module
*Previously Lexium
Details
When upgrading a system component from MDrive to Liberty* MDrive the key difference in programming is in how the I/O points are configured and used.. In the MDrive the non-isolated I/O points may be programmed as inputs or outputs.
In the Liberty* MDrive, the I/O points are fixed as inputs and outputs. In MDrive programs, the sink/source state of the I/O point is set in the user program. In the Liberty* MDrive the sink/source state is set by the bias of the Reference input.
The other key difference is the Analog Input. In the MDrive, the input is 10-bit, with a range of 0 to 1024. The Liberty* MDrive has a 12-bit analog input with a range of 0 to 4096. Programs not using I/O can generally be loaded onto the device and work without modification. The sample program we will convert uses an input to trigger a routine that will slew the axis a multiple of the analog input and one output set up as a moving output. The program is labeled as SU, so that it will execute on power up or reset.
Program Code (MDrive MCode)
Below is the MDrive MCode program. The bold highlighted lines of code will need to be changed in order to port the program over to a Liberty* Motion product.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | PG 100 ‘Enter program mode ‘Main program and setup LB SU A=1000000 ‘Set Acceleration S1=0,1 ‘I/O1 as user input S2=17,1 ‘I/O2 as moving out S5=9 ‘Analog as 0 to 5 VDC ‘Wait for input loop LB Wa BR M1,I1=1 ‘Conditional branch SL 0 ‘Stop/no motion BR Wa,I1=0 ‘Loop if input inactive ‘Motion on input LB M1 SL=I5*100 ‘Slew rate: Analog X 100 BR Wa ‘Jump to wait loop ‘End and exit program mode E PG S ‘keep this line |
The first point we will change is I/O #1
Modify the Input
| MDrivePlus | Liberty* MDrive |
| S1=0,1 | Is=1,0 |
The S1—S4 command has been changed to Is for input setup and Os for output setup In the example, I/O #1 is set as a general purpose input with a sinking interface. To modify the command to function with the Liberty* MDrive, The Is (Input setup) command is used by entering Is=[input number],[input function]. Is=1,0 then sets input 1 as a gen- eral purpose input. The available input functions are listed below:
| Input Function Table | |
| 0 | General purpose input |
| 1 | Homing function, will function as specified by the homing command (HM). |
| 2 | Limit +, will function as specified by the limit command (LM). |
| 3 | Limit —, will function as specified by the limit command (LM). |
| 4 | G0 input, will run program at address 1 upon activation. |
| 5 | Soft stop, stops motion with deceleration and halts program execution. If program is paused (PS), input is ignored. |
| 6 | Pause, pause/resume program with motion |
| 7 | Jog +, Will Jog motor in the positive direction at Max. Velocity (VM). The Jog Enable (JE) Flag must be set for this to function. |
| 8 | Jog —, Will Jog motor in the negative direction at max. velocity (VM). The jog enable (JE) flag must be set for this to function. |
| 11 | Reset, When set as RESET input, then the action is equivalent to a ^C entered into a terminal. Note: If setting the input to sourcing, active true, ground the input first or a reset will occur. |
| 12 | Capture input will operate with the Trip Capture (TC) trip to run a subroutine when active NOTE: THIS FUNCTION APPLIES TO INPUT 1 ONLY! |
Modify the Output
In this program, an output is setup to be active during a move. To change this to function with a Liberty* MDrive we will use the Os (output setup) command.
| MDrivePlus | Liberty* MDrive |
| S2=17,1 | Os=1,17 |
As with the input, the Os command replaces the S2 command in the form of Os=[outut number],[function], in this case Os=1,17 The available output functions are listed on the next page.
| Output Function Table | |
| 16 | USER: General purpose user output. |
| 17 | MOVING: output will be active while the axis is in motion. |
| 18 | ERROR: will be active when a software error occurs. |
| 19 | STALL: Indicates a stall has been detected [Closed loop models only]. |
| 20 | VCHANGE: velocity changing indicates the axis is accelerating or decelerating. |
| 21 | LOCKED ROTOR: indicates the rotor is in a locked state [Closed loop models only]. |
| 23 | MOVINGPOS: indicates the axis is moving to a specified position. |
| 24 | HMT ACTIVE: indicates when HMT is active [Closed loop models only]. |
| 25 | MAKE UP ACTIVE: indicates when HMT is making up steps [Closed loop models only]. |
| 28 | TRIP OUT, applies to output 3 only, active low only. Os=3,28,0 |
| 29 | ATTENTION: indicates a status or statuses as configured by the AO variable. |
Modify the Analog Input
To setup the Analog input we will return to the Is (input setup) command.
| MDrivePlus | Liberty* MDrive |
| S5=9,0 | Is=5,9,0 |
To set the analog input to voltage mode, 0 to +5VDC level the Is command is used as IS=5, [mode],[level] or Is=5,9,0 The parameters for the IS=5 command are listed below.
| Analog input mode table | |
| 9 | Voltage mode |
| 10 | Current mode |
| Analog level table | |
| 0 | 0 to +5V (voltage mode), 0 to 20 mA (current mode) |
| 1 | 0 to 10V (voltage mode), 4 to 20 mA (current mode) |
Modify the Analog Input scaling
The analog input on the Liberty* MDrive is 12-bit instead of ten, to set the program to have the same scale factor we need to divide the scale by 4
| MDrivePlus | Liberty* MDrive |
| SL=I5*100 | SL=I5*25 |
This will give us the same slew rate as with the MDrivePlus.
*Previously Lexium
When it comes to your form, fit and function requirements, don’t settle. Get precisely what you need working with us. We know motion.
Contact us with any questions about how we can help you with your motion application or for assistance with your IMS products.