Unipolar stepper motor control with PIC16F877A – CCS C

Interfacing unipolar stepper motor with PIC16F877A

This post shows how to control speed and rotation direction of unipolar stepper motor using PIC16F877A microcontroller and CCS PIC C compiler.
Related topic:
Bipolar stepper motor control with PIC16F877A microcontroller

Usually the unipolar stepper motor has 5 wires one for motor supply and the other for coils. This motor has 4 coils and they are connected as shown in the figure below:
Unipolar stepper motor coils

The unipolar stepper motor can be controlled in full step mode or half step mode, the usual method is the full step driving mode. The following table shows driving sequences:
Unipolar stepper motor driving sequence

Interfacing PIC16F877A with unipolar stepper motor circuit:
In the circuit there are 2 pushbuttons which are connected to RB0 and RB1 pins, they are used to choose motor rotation direction.
To control the stepper motor speed a potentiometer (10K) is used and it is connected to analog channel 0(AN0).

ULN2003 (or ULN2004) chip is used to energize the stepper motor coils.
The ULN2003 (ULN2004) is a Darlington transistor array which contains seven open collector Darlington pairs with common emitters. For stepper motor controller we need 4 transistors form this chip which means 4 inputs and 4 outputs are needed.
PIC16F877A unipolar stepper motor ULN2003 circuit

Instead of the ULN2003 chip, another chip can be used which is L293D dual H-bridge circuits as shown in the circuit schematic below.
For the L293D chip VS voltage always +5V and VSS voltage is the same as the motor voltage for example if the motor voltage is 12V VSS should be connected to +12V power supply.
PIC16F877A unipolar stepper motor L293D circuit
For both circuits the PIC16F877A needs +5V between its VDD and VSS pins.

Interfacing PIC16F877A with unipolar stepper motor CCS C code:
A pot connected to AN0 is used to control the speed of the stepper motor. The microcontroller reads the analog data from AN0 and uses the digital value to change the delay between motor driving sequences.

Interfacing PIC16F877A with unipolar stepper motor video:
The following video shows a hardware circuit for this project.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.