Monday, May 23, 2016

Interfacing PIC16F84A microcontroller with stepper motor


CD-ROM bipolar stepper motor drive with PIC16F84A and CCS PIC C compiler
This topic shows circuit schematic and C code for interfacing PIC16F84A microcontroller with CD-ROM bipolar stepper motor.
Related Topics:
CD-ROM Bipolar stepper motor drive using PIC18F4550 and CCS PIC C
Bipolar stepper motor control with PIC16F877A microcontroller
The following circuit schematic shows the connection between the microcontroller PIC16F84A and the stepper motor where a dual H-bridge circuit which is L293D chip is used between them.
Interfacing PIC16F84A with stepper motor circuit CCS PIC C
The two pushbuttons are used to choose motor rotation direction.
Interfacing PIC16F84A microcontroller with stepper motor CCS PIC C code:
The motor speed is fixed by the code but we can change it by changing the delay between the four phases.
// Interfacing PIC16F84A with CD-ROM bipolar stepper motor CCS C code
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(clock = 8000000)
#use fast_io(A)
#use fast_io(B)

void main()
{
   output_a(0);
   set_tris_a(0);
   port_b_pullups(TRUE);
   output_b(0);
   set_tris_b(3);
   while(TRUE)
   {
      output_a(0);
      while(!input(PIN_B0))
      {
         output_a(0b00000110);
         delay_ms(5);
         output_a(0b00000101);
         delay_ms(5);
         output_a(0b00001001);
         delay_ms(5);
         output_a(0b00001010);
         delay_ms(5);
      }
      while(!input(PIN_B1))
      {
         output_a(0b00000101);
         delay_ms(5);
         output_a(0b00000110);
         delay_ms(5);
         output_a(0b00001010);
         delay_ms(5);
         output_a(0b00001001);
         delay_ms(5);
      }
   }
}

Interfacing PIC16F84A microcontroller with stepper motor video: The following video shows a hardware circuit of this project.