This topic shows how to drive 5V unipolar stepper motor in 3 modes one-phase, two-phase and half step. The microcontroller used in this project is Microchip PIC12F1822 and the motor drive circuit is ULN2003.
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 Control Example with PIC12F1822Β circuit:
All the three control modes have the same circuit schematic as shown below.
Here PIC12F1822 uses its internal oscillator.
The potentiometer connected to AN0 is used to control motor speed and direction of rotation.
Unipolar Stepper Motor Control Example with PIC12F1822 CCS C code:
One Phase On Mode (Full Step mode):
In one phase control mode only one coil is energized at once. This mode produces smooth motion with low power consumption. Control sequence has 4 steps as shown in the table below:
CCS C code:
/*Β UnipolarΒ stepperΒ MotorΒ controlΒ usingΒ PIC12F1822Β (one-phaseΒ fullΒ stepΒ mode)Β CCSΒ PICΒ CΒ code Β Β Β http://ccspicc.blogspot.com/ Β Β Β [email protected] */ #include <12F1822.h> #fuses NOMCLR INTRC_IO PLL_SW #device ADC = 8 // Set ADC resolution to 8-bit #use delay(clock=32000000) #use fast_io(A) unsigned int8 i, step_number = 0; void stepper(int8 step){ Β Β switch(step){ Β Β Β Β case 0: Β Β Β Β Β Β output_a(0b100000); Β Β Β Β break; Β Β Β Β case 1: Β Β Β Β Β Β output_a(0b010000); Β Β Β Β break; Β Β Β Β case 2: Β Β Β Β Β Β output_a(0b000100); Β Β Β Β break; Β Β Β Β case 3: Β Β Β Β Β Β output_a(0b000010); Β Β Β Β break; Β Β } } void main() { Β Β setup_oscillator(OSC_8MHZΒ |Β OSC_PLL_ON);Β Β Β Β Β Β Β Β Β Β Β Β // Set internal oscillator to 32MHz (8MHz and PLL) Β Β output_a(0); Β Β set_tris_a(1);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Configure RA0 pin as input Β Β setup_adc(ADC_CLOCK_DIV_32);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Set ADC conversion time to 32Tosc Β Β setup_adc_ports(sAN0);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Configure AN0 pin as analog Β Β set_adc_channel(0);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Select channel AN0 Β Β while(TRUE){ Β Β Β Β output_a(0); Β Β Β Β iΒ =Β read_adc();Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Read from AN0 and store in i Β Β Β Β while(i >= 128){ // Move motor in direction 1 Β Β Β Β Β Β step_number++; Β Β Β Β Β Β if(step_number > 3) Β Β Β Β Β Β Β Β step_numberΒ =Β 0; Β Β Β Β Β Β stepper(step_number); Β Β Β Β Β Β delay_ms(257Β -Β i); Β Β Β Β Β Β iΒ =Β read_adc();Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Read from AN0 and store in i Β Β Β Β } Β Β Β Β while(i < 128){ // Move motor in direction 2 Β Β Β Β Β Β if(step_number < 1) Β Β Β Β Β Β Β Β step_numberΒ =Β 4; Β Β Β Β Β Β step_number--; Β Β Β Β Β Β stepper(step_number); Β Β Β Β Β Β delay_ms(iΒ +Β 2); Β Β Β Β Β Β iΒ =Β read_adc();Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Read from AN0 and store in i Β Β Β Β } Β Β } }
Two Phases On Mode (Alternate Full Step mode):
In two-phase mode two coils are energized. This mode produces high torque but its motion is not smooth like the one phase mode. The following table shows this mode sequence:
Read more: Unipolar Stepper Motor Control Example with PIC12F1822 Microcontroller