Application Note

MCode: Programming MDrive I/O


This Application Note covers the topic of writing MDrive MCode programs using the programmable I/O points both as a single I/O point, or as a bank of 4 I/O points as a group.


  • Getting Started
  • MCode OS
  • Programmable I/O

Applicable Product

  • MDrive Linear Actuator
  • MDrive Plus
  • MForce


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

Resource Files

[wpdm_package id=2520 template=


Global or Local variables

Like All MDrive variables, the I/O point configuration can be declared two ways:

  1. Globally
  2. Locally

Global:  Global I/O configurations, are declared outside the main body of the program. These are more typical and are used when you want the I/O point to have the same function at all times.

Local:  Local configurations are declared inside the body of the program and are stored in RAM, thus may be changed on the fly. An example would be where you may want an input to output to perform one function in part of the program and another in a different part of the program.

Event triggering

The most common use of the I/O is to trigger events within a system:

  • Inputs:  to trigger events internal to the MDrive program.
  • Outputs:  to trigger events within a machine or system.

Input example:

The following program example shows an input used to trigger an internal event:

The following program will move the axis to an absolute position based upon the state of I/O 1 and will hold that position until the state changes.

In this example, the program will use a conditional branch (BR) to activate the event. Input-driven events may also use the Call Subroutine (CL) command in a similar fashion.

Output event

The following program example shows an output used to trigger an external event. A real-world example may be that the MDrive performs and completes a task, when complete the program will activate an output to trigger an external process, such as executing a program in a second system MDrive.

Using a Bank of I/O

The MDrive I/O can read inputs and write outputs as a group in Binary Coded Decimal (BCD).

The I/O may be connected as shown below. For purposes of example, we have used switches for inputs and LED’s for outputs. All are configured as general purpose, active when low, sinking.

For this example we will use two basic programs:

  • Inputs: A program that will perform a specific move based on the input decimal value.
  • Outputs: A program that will cause the outputs to operate as a binary up counter.

Move on BCD Input Example

The following application will move the motor to a variety of positions based upon a binary input to I/O 1-4. One of the things this application shows is one of the new Microstep Resolution settings that give the ability to set motion to occur in 0.001˚ increments. The program does a calculation after each move to show motor position in degrees. To make the web view shorter, the example below omits many repetitive branch routines for the various moves. See the full program to view.

Binary up counter – BCD output example

The following program example shows the use of the lower output bank as a binary up-counter. IO1 – IO4 are setup as general purpose outputs, active when HIGH, sinking. The main program will set the outputs, store the decimal equivalent of the outputs, and index the motor a multiple of the output state. Once complete it will increment the register and repeat until the value of the register =15 (binary 1111). It will then clear the register, set the outputs to 0, and restart the process.