Example Programs

Product Families:

Topics

RS Logix 5000 Examples for Lexium MDrive

 

LabVIEW Examples for Lexium MDrive

Example LabVIEW Libraries for Lexium MDrive.

 

Homing to a hard stop

System designers often want to home an axis to a hard stop to avoid the additional complexity and expense of a home sensor. The usual problem with this approach is that the stepper motor produces torque based on its position within its electrical and mechanical cycles. When it stalls, those cycles cause the motor to move back and forth against the stop. When motion is stopped, the motor may come to rest some distance from the stop. This distance is can be random. If this position were used as a home position, poor accuracy would result.

The following sample code uses an iterative approach to try to capture the position closest to home that the motor reaches as it repeatedly hits the hard stop. Since the capture loop in the program runs quickly and asynchronously to the motor’s motion, the lowest value can be captured. This can be tested by stopping the motor, setting the hold current, HC, to zero, and moving the axis manually to the stop and checking the position register (PR P). This is the value we are trying to find. Once we find that value, we move a fixed distance from that value using an absolute move to that value +/- a set amount. We do this because we cannot move to the exact position of the hard stop. Once at this position, we either set the position to zero (P=0), or to some offset value X (P=X).

 

LabVIEW Examples

Example code for communicating to MDrive family of products using LabVIEW. It does not support some more advanced functions such as Party Mode or Checksum Mode, but it should give you a head start into your application.

 

VBA Examples

VBA Example programs to control MDrive Motion Control products using an Excel spreadsheet.

 

CANopen – Profile velocity mode

Profile Velocity Mode – demonstrates the ability to move at constant velocity using Service Data Objects (SDOs).

SEM CANopen products support the ability to move in velocity mode. Once in Profile Velocity Mode, any new target velocity will be executed immediately.

 

CANopen – Profile position mode

Profile Position Mode – demonstrates the different move types supported for position control executed via Service Data Objects (SDOs).

SEM CANopen products support relative and absolute moves to position. Using either relative or absolute moves, the user can also select (by the control word data) if the target position should be reached before another target position is allowed (finish first) or if the SEM product should execute a newly received target position even if still in motion (immediate).

 

Move on BCD

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 run program, enter EX 1 into the terminal. You can index the motor by moving the switches to the center (OFF) position to represent a 4-bit binary number where switch 4 is the most significant bit.

The terminal will display the decimal equivalent, as well as the axis position in degrees.

This program illustrates the following functions:

  1. The ability to input BCD to the I/O group and control processes based on the value of the inputs.
  2. The ability to manipulate numeric position data to display it in familiar units of measure.
 

Multiple Position Trips

Example program to show how to use multiple position trips within a program.

This program will index the motor, while printing the position and velocity at each trip point, then repeat. It illustrates defining multiple position trips within a single program.

 

Binary Counter

The following program addresses the lower output bank as a group using the OL variable. A subroutine sets the Output group from a Register value, which is incremented each time the subroutine runs and then moves the motor based upon a multiple of the output group state. When the register reaches a count of 15, a subroutine will run to reset it to zero, restarting the process.

The 4-bit binary number will display on the LED bank as the device counts up.

Enter “EX 1” into the terminal to run the program. The program will automatically begin to count up in binary, while the motor will move a distance that is a multiple of that count.

This illustrates the following functions:

  • The ability to output BCD via the I/O group.
  • The ability to use and manipulate numeric data and perform operations based upon that data.
 

Electronic Gearing

This program demonstrates the use of high speed inputs to allow for electronic gearing operations.

 

High Speed Input Trip Capture

This program demonstrates the use of High Speed Trip Capture Input.

 

Basic Motion Sample

This program is a very basic motion sample which makes a basic point-to-point relative move.

 

Move on Input

This program demonstrates the use of inputs to initiate a point-to-point move.

 

On Error Handler

This program demonstrates the use of the On Error (OE) handler function.

 

Toggle Program

This program demonstrates the use of one momentary input to toggle between different functions.

 

Boolean Logic

This program demonstrates the use of Boolean operators with input switches. Requirements:

  1. Compatible product
  2. DC power supply
  3. Communications/Network
  4. I/O points 1-4 connected to switches
 

Avoiding Encoder Overflow

This program demonstrates the use of a position trip to reset the encoder counter (C2) every 100000 encoder counts. Requirements:

  1. Compatible product
  2. DC power supply
  3. Communications/Network
  4. Switches connected to I/O points 1 & 2
 

If-Then Sample

This program demonstrates the use of the program branch function to perform if-then logic operations using inputs. Requirements:

  1. Compatible product
  2. DC power supply
  3. Communications/Network
  4. Switch connected to I/O point 1
  5. Motor, if using an MForce
 

Integer Math

This program demonstrates the use of integer math functions. Required:

  1. Compatible product
  2. DC power supply
  3. Communications/Network
 

Limit Switch Test

This program demonstrates the use of limit switches. Required:

  1. Compatible product
  2. DC power supply
  3. Communications/Network
  4. Switches connected to  I/O 1 and 2
 

Move on Analog Input

This program demonstrates a move to an absolute position based on the level of the Analog input.

 

Position Trip Redefine

This program demonstrates the ability to redefine position trips while the axis is in motion

 

Turn Table

This program will find shortest route to absolute position. This program sets up a matrix to find distance and direction by comparing whether the current position is greater than the requested position and whether the requested move is 180 deg.

Operation

Enter desired position in .01 deg (180 deg = 18000) into ‘V1 variable (V1=18000). Execute program at address 1 (EX 1)

 

Basic Motion Sample

This program is a very basic motion sample which makes a basic point-to-point relative move. The program will function the same regardless of the MCode product used.

 

Trip On Relative Position

This program will show the use the trip on relative position function (TR).

Program slews the motor at 600 RPM  =  10 RPS. Sets a trip on relative position which produces a 255 * 50 nS pulse every 512 steps. Runs and stops when I1 toggles. Stops quickly when I2 goes low.  (NOT AN E-STOP)

Hardware requirement: Switch connected to Inputs 1 and 2

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Interface application.

 

Analog speed control

This program demonstrates the use of the analog input in a speed control application.

The program subroutine performs calculations using the user registers R1-R4 and slews the axis bi-directionally based upon the value seen on the analog input.

Hardware requirement: 10kΩ potentiometer connected to the Analog input.

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program files may be downloaded below.

 

Analog slew with stall detection

This program will use the analog input reading to ram the velocity until the motor stalls. When the stall occurs, an error is generated.

A subroutine is triggered by the error to: Print the Error number and stalled sate of the motor,

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program files may be downloaded below.

 

Position teach

This program allows the user to “teach” the product a +/- move profile based on manually positioning the motor shaft. The shaft is manually moved to a position, then an input is toggled to store that position in encoder counts to a user variable. The shaft is moved to second position, the input is again toggled to store the second position in a second variable. The motor will then move between the two stored positions.

Note that the input settings are undefined in the program, as the default settings are used.

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program files may be downloaded below.

 

Closed loop with homing

This program demonstrates the use of the home to home switch instruction (HM) in closed loop, also there is a move on input routine. The Homing method used is HM1, which will slew at VM (Max Velocity) in the negative direction, when input 1 is activated, the axis will creep in the plus direction at VI (Initial Velocity).

See the MCode Home to home switch command and change the homing method to experiment with different methods of homing. Output 1 is set to activate when the axis is moving. Stalling the motor will generate an error, activating output 2.

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program files may be downloaded below.

 

Closed loop on error

This program illustrates closed loop control with an On Error (OE) routine which will perform math functions on the counters to display the position error.

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program files may be downloaded below.

 

Binary mask

This program will demonstrate ability to execute various subroutines depending on the binary value of inputs 1-3 while masking all inputs above input 3. The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program file may be downloaded below.

 

Move on Input

This program will perform a point-to-point move that will trigger on the active state of an input.

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program files may be downloaded below.