These posts focus on controlling intelligent precision electric motors from Windows applications written in C#. Specifically, we will be controlling a Schneider Electric M-Drive stepper motor with an integrated encoder and controller.
Posts in this Series
Now before you think this is a sales pitch, I want to be clear that this is my personal blog and I am not employed or being compensated by Schneider Electric in any way. They did not supply me with any special assistance or provide me with any free or discounted hardware.
A stepper motor is a relatively simple thing. While there are a myriad of internet resources describing how stepper motors work, I’ll just stick to the Schneider website. These two blog posts do a very nice job of explaining how a stepper motor works, and how micro-stepping works. In all honesty, you don’t really need to read those posts to understand the rest of this series – but since there is no virtue in ignorance, take a moment to read them anyway.
Gathering Hardware Together
Various motors are available from Schneider. This invaluable hardware document contains a lot of technical motor specifications for the various models, including mechanical and electrical specifications. Keep in mind that the various sizes also come in single, double, triple and sometimes quad stack configurations. Increasing stacks increases the motor’s length and torque.
After choosing and obtaining a motor, you will also need a 12-48 VDC power supply. The current requirements are clearly spelled out in the hardware document. Check the hardware document for the proper power connector and wire gauge you will need.
You will also need a means to communicate with the motor from your PC via an RS422 port. Again, check the hardware document for the type of RS422 connector needed for the motor side. As for the PC, the easiest solution is a USB to RS422 converter. While Schneider sells their own converters, they are overpriced and do not have good driver support. I’ve had great success with products from US Converters, specifically the single port XS890 and the four port UTS-M14. The new RS422 port should be accessible from Windows as “COM3” (or higher).
Gathering Software Together
Once your motor is connected and powered up, you will need some sort of software to communicate with the motor. Any terminal emulator will do. Schneider offers their own free IMS Terminal program that works fine but does occasionally lock up. I don’t use it anymore. I mean, just look at it. It’s horrible!
To make things easier for myself, I have written a program called MDrive, which is available in source code form on Codeplex. More on that in part 3. Until then, here is a pretty screen shot.
Once everything is connected, powering up the motor will cause it to display a copyright message and a “>” prompt on your terminal emulator. To make the motor spin one revolution, type “
MR 51200”. This invaluable MCode document is the official guide to the various commands you can send to the motor. The next post will cover MCode programming.
To wrap up this post, I want to provide an overview of the features of the motor:
The MDrive is a stepper motor that is configured for 200 full steps per revolution. That means the smallest amount you can turn the motor shaft is 1.8 degrees. With micro-stepping enabled, the motor can position itself in any one of 256 locations between each full step. This allows positioning of the motor to any of 51200 positions per revolution, allowing you to turn the motor shaft as little as 0.007 degrees. The motor can spin at speeds as slow as 1 micro-step per second (~0.001 rpm) and as fast as 1000 rpm with a low load.
The MDrive contains an embedded computer that controls the movement of the stepper motor and can communicate with an external PC via RS422. The computer can accept a myriad of commands to control all aspects of motion. There is a kind of scripting language that allows you to define complex sequences of motions. In addition, the computer has non-volatile memory that can be used to store programs and data.
The MDrive contains an embedded magnetic encoder with a resolution of 2048 positions per revolution. The encoder allows the computer to track the actual motion of the motor shaft. This means that if the shaft stops spinning, the embedded computer can recognize the stall event and take appropriate action. The encoder also allows the motor to return to an exact position time and time again – even if the stepper motor previously stalled or the shaft missed a few steps and fell behind. Another neat feature is that the computer can detect movement of the shaft even if the stepper motor is not running. The encoder also has an index mark, allowing you to return the shaft to a known “home” position.
The MDrive has several digital i/o lines and an analog input line. The computer can be programmed to react to changes in the input lines and drive the output lines in just about any way you desired.
The MDrive supports scripting, which allows it to run independently from a PC. A script can be configured to start up when the motor is powered up - allowing the motor to run autonomously in a rather complex environment. The motor can also be controlled via the RS422 communications port and remain part of a more complex external computer controlled system.