Home > Resources > Example Programs

Example Programs

Example MCode programs to aid in fully using SEM motion control products.
Product
Example Programs

Example LabVIEW Libraries for Lexium MDrive.

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).

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 Example programs to control MDrive Motion Control products using an Excel spreadsheet.

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.

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).

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.

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.

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.
Next

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.