Stepper Motor Interfacing with 8051

Introduction to Stepper-Motor

Principle of Working

A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The shaft or spindle of a stepper motor rotates indiscrete step increments when electrical command pulses are applied to it in the proper sequence. The motors rotation has several direct relationships to these applied input pulses. The sequence of the applied pulses is directly related to the direction of motor shafts rotation. The speed of the motor shafts rotation is directly related to the frequency of the input pulses and the length of rotation is directly related to the number of input pulses applied.


 


Stepper motor can be operated in two types of sequences:

  1. Half step: In this sequence single coil is energized and then both coils are energized at the same time and motor shaft rotates. Refer figure 1 shown above.
    Step Angle = 45 degree
    No of steps = 8
  2. Full step: In this sequence single coil is energized or both coils are energized at the same time and motor shaft rotates. Refer figure 1 shown above.
    Step Angle = 90 degree
    No of steps = 4

Half step Sequence

Half Step Sequence
StepABA'B'Hex Value
0100008H
111000CH
2010004H
3011006H
4001002H
5001103H
6000101H
7100109H

Full Step Sequence

Full step sequence
StepABA'B'Hex value
0100008H
1010004H
2001002H
3000101H
Full step sequence
StepABCDHex codes
011000CH
1011006H
2001103H
3100109H

When to use a stepper motor


  • A stepper motor can be a good choice whenever controlled movement is required.
  • They can be used to get advantage in applications where you need to control rotation angle, speed, position and synchronism.
  • Because of inherent advantages listed previously, stepper motor have their place in many different applications.

Interfacing

Algorithm for Interfacing

Interfacing Diagram



Assembly Language Program for Interfacing

Program: Write an ALP to rotate stepper motor 90 degree in the clockwise and then anti-clockwise direction which is interfaced to 8051 microcontroller. with highest delay generated by Timer1 in Mode 1

Solution- 

 Given

  • Timer1, in Mode 1 i.e. 16-bit mode
  • XTAL i.e. fosc = 11.0592 MHz (Assume if not given which is fix in case of 8051)
  • Delay to be generated of maximum value.

Delay Generation Calculations
Crystal Freq = 11.0592 MHz

Internally Timer Module divides this Crystal frequency by the factor of 12 to generate 1 machine cycle frequency ,
Therefor 1 machine cycle frequency = Crystal frequeny / 12
                                                          =11.0592 MHz / 12
                                                          = 921.6 KHz
 Hence T = 1 / 921.6 KHz = 1.08 microSeconds

i.e. 1 machine cycle generates delay of = 1.08 microSeconds

As we have to generate maximum time delay and we are using Timer1 in mode1 i.e 16-bit Timer,
Hence it can count maximum machine cycles of 65535 + 1 machine cycle of overflow =65536

Therefor 65536 Number of Machine cycles can generates delay of  = 70.77 milliSeconds

Initial Value to be loaded in Timer Registers = Final Value + 1 - number of Machine cycles required
                                         = 65535 +1 - 65536
                                          =0000 decimal
                                          = 0000 Hexadecimal
Hence Value to be loaded in TL0= 00 H, TH0= 00 H

Assembly Language Program

ORG 00H
Main:Mov A,#OCH //clockwise direction first sequence
Acall Delay
Mov A,#06H     //clockwise direction second sequence
Acall Delay
Mov A,#03H   //clockwise direction third sequence
Acall Delay
Mov A,#09H   //clockwise direction fourth sequence
Acall Delay
Mov A,#O9H //Anti-clockwise direction first sequence
Acall Delay
Mov A,#03H  //Anti-clockwise direction second sequence
Acall Delay
Mov A,#06H //Anti-clockwise direction third sequence
Acall Delay
Mov A,#0CH   //Anti-clockwise direction fourth sequence
Acall Delay
SJMP Main
Delay:Mov TMOD,#10H    //Timer1 in Mode1
Mov TL1,#00H            //Load TL1 with Initial value
Mov TH1,#00H        //Load TH1 with Initial value
SETB TR1             //Start timer1
Here:JNB TF1,Here   //Monitor Timer1 Overflow flag
CLR TF1             //Clear Timer1 Overflow flag
CLR TR1              //Stop Timer
RET
END

Note:-In order to rotate stepper motor in anticlockwise direction just reverse the sequence of excitation of windings (from bottom to top) refer table above

Program: Write an ALP to rotate stepper motor 45 degree in the clockwise direction which is interfaced to 8051 microcontroller.

ORG 00H
Main:Mov A,#O8H
Acall Delay
Mov A,#OCH
Acall Delay
Mov A,#O4H
Acall Delay
Mov A,#06H
Acall Delay
Mov A,#O2H
Acall Delay
Mov A,#03H
Acall Delay
Mov A,#O1H
Acall Delay
Mov A,#09H
Acall Delay
SJMP Main
Delay:Mov TMOD,#10H    //Timer1 in Mode1
Mov TL1,#00H            //Load TL1 with Initial value
Mov TH1,#00H        //Load TH1 with Initial value
SETB TR1             //Start timer1
Here:JNB TF1,Here   //Monitor Timer1 Overflow flag
CLR TF1             //Clear Timer1 Overflow flag
CLR TR1              //Stop Timer
RET
END

Video Simulation in Proteus


References

  • Interfacing image by Jayesh Gopal, WikiNote Volunteer, Pune
  • Created and edited by Prof.S.M.Wagh, SKNCOE, Pune
  • WikiNote Foundation

Last modified: Tuesday, 17 September 2019, 3:40 PM