USB Stepper Motor Driver

USB Stepper Motor Driver, PIC18F4550 USB Stepper Motor Controller

 

 

 

 

USB Stepper Motor Driver


In this project we are going to drive a unipolar Stepper motor (5 wire) using USB interface from a PC Computer. This project is an application of the USB Interface Board PIC18F4550 which was published here in the past. You can run other stepper motors too. It is simple and easy to make, we are going to use PIC18F4550 microcontroller which has an in built USB (USB 2.0) functionality which allows it to connect with any computer with a USB port and Windows OS. We will try to provide as much as details we can for achieving this project.

USB Stepper Motor driverUSB Stepper Motor driver

 

 

 

 

 

 

 

OLD METHOD: The legacy (OLD) method was to use a parallel port (DB 9), which were far more easy with simple port control commands, which were good enough to glow few led directly connected to COMM pins of a parallel port, and with a simple loop written in VB it was easy to generate a pulse of blinking led for a stepper motor.

USB: However laptops and portable computers don’t come with those big D9 (parallel or printer) port anymore, as the USB ports - due to its excellent characteristics and small size has taken its replacement for almost for any external device. USB interface for this project is going to be little complex then the old parallel port method.

The microcontroller which will serve as the communication channel between the Computer and Stepper motor, the PIC18F4550 microcontroller, can work in two USB speed 12Mbps(full speed) and 1.2Mbps(low speed).

For our project we will run this microcontroller board in Full speed (12Mpbs). The project can be also achieved with a PIC18F2550 with little modification in the firmware, but since 18F4550 has more number of pins on a standard Dual Inline package (40 pins, 20 pins on each side), so we will go with that. PIC18F4550 is far more cheap and inexpensive then an Arduino board. In fact the stepper motor here costs more than the entire board and components used.

usb stepper motor

 

 

 

 

 

 

 

Stepper Motor

The stepper motor used here is a 5 wire Stepper motor (M35SP-8) which is going to be operated by an application written in C#, (visual studio) which will communicate with the microcontroller board via USB, and microcontroller will drive the Motor connected with it according to the output directed by the software written in C#. The entire project and its necessary project files with schematics can be found at the end of this page.

Unipolar Stepper motor - 5 wire

The M35SP-8 Stepper Motor has a step angle of 7.5 degree, with one Common wire and 4 control wires connected to each coils. Hence we need only 4 control links for generating the pulse which will drive this stepper motor. For information on the specification of MS35SP-8 refer the respective datasheet.

 

Stepper Motor Wiring

The Figure below shows the labeling of the Stepper motor used for this project. If you wish to use any other stepper motor then you have to follow wiring labels of that respective stepper motor.

stepper motor wiring5 wire Stepper Motor Driver Color code wiring

Running other Stepper motors

The USB interface board we are using here has 6 control pins, it means you can control 6 LEDs (example) with this board. Out of which, only 4 pins are required to control our M35SP-8 Stepper motor, remaining 2 will be unused.

However you can run more kinds of stepper motor too. Since we have 6 control lines available hence the project can be easily modified to run other stepper motors too. Any stepper motor has one common ground wire and remaining are control wires, So technically with this USB interface board you can run a 5 wire, 6 wire and 7 wire stepper motor easily (6 control and one Common power).  

 

USB Interface Board Schematic


First start with the USB interface board, which will require a firmware to be loaded in the microcontroller and later, a windows driver, after the board is ready. I strongly recommend making this board on PCB.

You can find a detailed tutorial and specifications for making this board alone in my previous USB Interface post. The firmware used here is the same firmware as in PIC18F4550 board with no modification. The components required are pretty much clear in the schematic or you are free to explore USB Interface Board post for detailed component list.

-Firmware Download

After making this board, connect it with computer USB port and it would ask you for driver.

-WIN XP driver
-WIN 7 Driver

The only thing here different is the C# application, which is written for running the stepper motor.

 

Schematic:

USB Stepper Motor Driver schematic

Connect two led across RD4 and RD5, which will display the status of the USB Board. IF the Communication between the computer and USB Board is successful then both the LED’s would blink alternatively.

The pins RD0-RD3 of the microcontroller is interfaced with 4 coils of the stepper motor, and the “Common wire” is interfaced the external 9V motor supply.  

USB Interface Board PIC18F4550 Microcontroller

 

PIC18F4550 USB Stepper Motor Circuit

USB stepper Motor Driver Circuitry

The output voltage across the RD pins of the microcontroller would be enough to glow few LED, but it is not enough to run our MS35SP-8 stepper motor, hence we are going to use a Darlington pair of transistors for high voltage switching.

 

uln2003-Interface

For such purpose we will use ULN2003 IC, UlN2003 is a monolithic high voltage Darlington array IC, which contains an array of transistors (bipolar transistors) which will do the switching for us, with excitation of low voltage input.  

On the USB interface board we cannot increase the voltage more than 5v, or it will kill the microcontroller instantly (Refer the PIC18F4550 datasheet) and the output pulses generated will be low voltage hence ULN2003 is used, which would drive our load (stepper motor). We will feed the ULN2003 with 9V power supply which will run the stepper motor. Refer the ULN2003 datasheet for its technical specifications. A typical L293D motor Driver can be also used for such purpose, but that will make circuitry little bit more complex, hence uln2003 is good enough.

After making the USB interface board to work, it’s a good idea to test with 4 leds, after that interface it with uln2003 as showed in the schematic above, make sure you check all the connections before testing it out. Be careful because we are introducing 9V to the ULN2003, the microcontroller directly cannot bear 9v as mentioned before.

Note: Do not forget to connect the Ground pin (GND) of the Microcontroller board to the ULN2003 GND pin (pin8)

 

Application C#


After the USB board is successfully installed on the PC with the drivers provided, the led on RD4 and RD5 would start to blink alternatively. Now start the application. The Application here is written on C# forms. Open the project file and everything will be quiet easy to code and modify, or to add more steps for stepper motor.

 

Application for controlling and driving USB Stepper Motor

CS application

You can also alter the time delay in between each step by entering the ms value on the software application for this driver.

Stepper Motor Stepping Sequence

As of now only three modes has been added for this stepper motor.

Stepper Motor Modes Steppings

 

 

 

The truth table below shows how pins are set and phases are energized according to the modes.

 

Single Step Wave mode: C1, C2, C3, C4 are coils connected to RD0, RD1, RD2 and RD3 pins of USB pic18f4550. In this mode only single phase is energized (Single phase excitation) for the running the motor. Single stepping (wave) mode gets completed in 4 cycles, A, B, C and D which then repeats over again from the beginning (loop) at the end. At the end of 4 cycles the Stepper motor shaft completes one revolution.

 

Stepper-Motor-Steppings-Wave-single step

 

Full Step Sequence mode: This mode drives with Dual phase excitation, which means that two phases are energized at a time and hence results in more torque. This mode also has 4 cycles, A, B, C, and D. However the motor in this mode runs with little more toques then that of wave mode.  At the end of last cycle the motor loops over the same.

 

Half wave stepper motor stepping

 

Half Step sequence mode: This mode is the combination of both Single phase excitation and dual phase excitation, in this both single and dual phases are energized alternatively for running the Stepper Motor. This mode of operation has 8 cycles or steps for completing one rotation of the motor shaft. This mode provides pretty good resolution but the speed is going to be slow.

 

Half wave Stepper motor steppings

You can toggle the modes the way you want in the application running on the desktop for the speed and step mode you want.

If you want to run a 6 wire stepper motor then you can easily modify the code on the C# application, by adding some more port control commands and sequence of loop. The source code is pretty much self-explanatory and can be very easily modified.

USB Stepper Motor project

Testing Stepping Pulse with LED

Before connecting and ULN2003 to the circuit board, you can test if the Stepper motor Stepping pulses are generating on the pins the way it is supposed to be, by connecting 4  led across the RD0 to RD3. Watch this video below for a small demonstration.

Don’t connect the LED across the output pins of ULN2003 or the Led’s will get damaged, Connect them directly to the RD pins with 1 k resistance each. Start the software and hit Start motor button.

LED connected to stepper motor for testing usb LED connected to stepper motor for final test

The label on the C# application will update according to the Stepping pulse sent to the PIC18F4550, If everything is working fine and the led’s are blinking in the way shown in the stepping truth table above, then  connect the uln2003 and stepper motor to the board.

Stepper Motor Interfaced to ULN2003

 

 

PROJECT FILES

-C# Stepper motor Driver Software application
-Firmware for microcontroller

-Driver download – XP
-Vista and Win 7

-Schematics

 

Thanks for reading
Rakesh Mondal.

USB Stepper Motor Controller Driver Project

Add new comment

Plain text

  • Allowed HTML tags: <blockquote> <code>
  • No HTML tags allowed.