Most of cd-rom or dvd-rom drives has a bipolar stepper motor, this motor has two windings and each winding has 2 inputs which means that this type of motor has 4 wires.
This topic shows circuit schematic and C code for controlling the bipolar stepper motor speed and direction using PIC18F4550 microcontroller.
The stepper motor can be controlled in full step mode or half step mode. The full step mode is a little bit easier than the half step control mode. In this topic the full step control mode is used.
To control the bipolar stepper motor we need two H-bridge circuits and for that L293D motor driver chip is used, this cheap chip can work as a dual H-bridge drivers.
In the full step control mode always both windings are energized according to the following two tables where table1 shows the driving sequence for rotation direction 1:
And the following table shows driving sequence for the other rotation direction:
Interfacing PIC18F4550 with bipolar stepper motor circuit:
The following image shows circuit schematic diagram of this project a potentiometer connected to AN0 channel is used to control the speed as well as the rotation direction of the stepper motor as shown in the video below.
PIC18F4550 internal oscillator is used (8MHz) and MCLR pin function is disabled, it needs +5V on its VDD and VSS pins.
Interfacing PIC18F4550 with bipolar stepper motor CCS C code:
The following code is the full C code of this project where a potentiometer which is connected to channel AN0 is used to control the rotation direction and the speed of the stepper motor.
The microcontroller reads the analog value from the output of the pot and uses the digital value to control the rotation direction and the speed with ADC resolution of 8 bits.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | // Interfacing PIC18F4550 with CD-ROM bipolar stepper motor CCS C code #include <18F4550.h> #fuses NOMCLR INTRC_IO #use delay(clock = 8000000) #use fast_io(D) unsigned int8 speed_, value; void main() { setup_oscillator(OSC_8MHZ); // Set internal oscillator to 8MHz setup_adc(ADC_CLOCK_DIV_8); // Set ADC conversion time to 8Tosc setup_adc_ports(AN0); // Configure RA0(AN0)as analog set_adc_channel(0); // Select channel 0 input output_d(0); set_tris_d(0); delay_ms(100); // Wait 100ms while(TRUE) { value = read_adc(); if(value < 2)value = 1; if(value < 0x80) { speed_ = value; output_d(0b00000110); delay_ms(speed_); output_d(0b00000101); delay_ms(speed_); output_d(0b00001001); delay_ms(speed_); output_d(0b00001010); delay_ms(speed_); } else if(value > 0x80) { speed_ = 256 - value; output_d(0b00000101); delay_ms(speed_); output_d(0b00000110); delay_ms(speed_); output_d(0b00001010); delay_ms(speed_); output_d(0b00001001); delay_ms(speed_); } } } |
Interfacing PIC18F4550 with bipolar stepper motor video:
The following video shows the project in hardware circuit.
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.