Application note

Configuring MDrive I/O: MCode Basics

Home > Resources > Application notes > Configuring MDrive I/O: MCode Basics


Setting up the hardware interface for the MDrive I/O only represents half of the battle. Before it can function it must be configured in software using the “S” command.


  • MDrive Linear Actuator
  • MDrive Plus
  • MForce


  1. MDrive r MForce Motion Control or Ethernet product
  2. DC power supply
  3. Optional: +5 to +34 VDC Auxiliary supply
  4. +5 to +24 VDC I/O supply (if using sourcing outputs).
  5. Input and/or output devices
  6. Cabling: 22 AWG shielded twisted pairs for I/O, Shielded twisted pair for power, AWG determined by length and current


S command (I/O setup)

The I/O setup command establishes how the I/O point will function in the system, note that each I/O point MUST be setup individually if changed from the factory default:

  • Will it be an input or an output?
  • Will it be general purpose, or set to a dedicated function?
  • Will it be a sinking or sourcing type?
  • Will it be ACTIVE when logic HIGH or LOW?

Setup parameters

The I/O setup command has three parameters that define its operational characteristics, these are:

  1. Function: Assigns the point to an input or output function.
  2. The active state defines the point as being ACTIVE when HIGH or LOW.
  3. Sink/Source: Sets the point as a sinking or sourcing type. NOTE: sourcing outputs only available on Plus2 models.

I/O Functions

The following table lists the function codes relevant to the first parameter: Input or Output functions.

Input Functions Output Functions
Param # Function Param # Function
0 General purpose 16 General purpose
1 Homing 17 Moving
2 Positive limit 18 Fault/Error
3 Negative limit 19 Stall
4 G0 20 Velocity changing
5 Soft stop
6 Pause running program
7 Jog positive
8 Jog negative
11 Reset

Active state

The Active State parameter defines the level at which the I/O point will be active and may be set to:

0 – I/O is Active when logic LOW (0 volts, ground)
1 – I/O is Active when logic HIGH (+5 to +24 VDC)

With outputs, the Active setting becomes of particular importance. The impact of the Active state setting will impact functionality based upon the hardware configuration of the output point and whether it will be sinking or sourcing. The following table details the output circuit conditions for each state and sink/source configuration.

Sink/Source Active State Output State Circuit Condition
Sinking Active HIGH Output = 1 Sink OFF, High impedance
Output = 0 Sink ON
Active LOW Output = 1 Sink ON
Output = 0 Sink OFF, High impedance
(Plus2 Only)
Active HIGH Output = 1 Source ON
Output = 0 Source OFF, High impedance
Active LOW Output = 1 Source OFF, High impedance
Output = 0 Source ON



The Sink/Source parameter identifies the I/O point as sinking or sourcing. If the hardware is connected using any of the configurations shown in the Connecting Power and I/O tutorial, this should be set to match the hardware connection.

0 – Sinking – Point will change states when pulled to ground.
1 – Sourcing – Point will change states when sourced (+5 to +24 VDC).

General I/O usage commands

An I/O instruction results in the change of parameters or the state of an input or output. The syntax for these commands are as follows: type the command then an equal sign, then the data. Example: O2=0 will set output 2 to 0.

This tutorial only covers the General purpose I/O points with the following set of commands to be exampled in the programming part of this tutorial. The Clock I/O and Capture/Trip I/O are only slightly different in their configuration. Please refer to the MCode manual for this instructions.

Mnemonic Function Usage example Description
Individual I/O point control commands
I<io point> Read an individual input state as 1 or 0 PR I4 Read the state of input 4
CL k3,I4=1 Call subroutine k3 when I/O 4 is ACTIVE (1)
O<io point> Set the logic state of an individual output O3=1 Set output 3 HIGH (1)
Binary coded decimal (BCD) commands
OL=<0-15> Set the logic state of the lower output bank OL=15 Set outputs 1 – 4 HIGH (All MDrives) See Details
OH=<0-15> Set the logic state of the upper output bank OH=15 Set outputs 9 – 12 HIGH (Plus2 MDrives) See Details
OT=<0-255> Set the logic state of both output banks OH=255 Set outputs 1 – 4 and 9 – 12 HIGH (if standard I/O this will only set the available points, 1 – 4) See Details
IL Read lower input bank as BCD PR IL Read inputs 1 – 4 as group (response will be 0 – 15 based on I1 being LSb and I4 being MSb) See Details
IH Read upper input bank as BCD PR IH Read inputs 9 – 12 as group (response will be 0 – 15 based on I9 being LSb and I12 being MSb – Plus2MDrives only) See Details
IN Read both input banks as BCD PR IN Read inputs1 – 4 and 9 – 12 as group (response will be 0 – 255 based on I1 being LSb and I12 being MSb) See Details
Input filtering commands
D<input>=<0-255> Set the input filtering to time in milliseconds D1=150 Set the filter for input 1 to 150 milliseconds. Input must be stable for 150 msec before a change will be detected.
Input trip
TI=<input>, <subroutine> Sets the operation of an input trip TI=2, K3 Execute subroutine labeled K3 when input 2 is active. See Details

Resource files

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 SEM products.

Browse our resource section and find the most useful tools and documents for all our products.