Search This Blog

Sunday, November 20, 2011

8051 interfacing with stepper motor

8051 Interfacing with stepper motor
fig shows interfacing connection
-------------------------------
; 4 PINS OF STEPPER MOTOR CONTROLLED BY 4 BITS OF 8051 P1.0 - P1.3
; IT IS INTERFACED USING DARLINGTON ARRAYS SUCH AS ULN2003 AS
; 8051 LACKS CURRENT TO RUN THE MOTOR. SO ULN2003 IS USED FOR ENERGIZING STATOR.
; PROGRAM BELOW SHOWS JUST ROTATING THE MOTOR STEP WISE
; BUT STEP WIDTH IS UNKNOWN

MOV A, #66H    ; LOAD THE STEP SEQUENCE

BACK :
MOV P1, A    ; LOAD SEQUENCE TO PORT
RR A        ; CHANGE SEQUENCE ROTATE CLOCKWISE
ACALL DELAY    : WAIT FOR IT
SJMP BACK    ; NOW KEEP GOING

DELAY :
MOV R2, #100

H1 :
MOV R3, #255

H2 :
DJNZ R3, H2
DJNZ R2, H1
RET

END

; THIS OTHER PROGRAM CODE HOW IN SAME INTERFACING TO ROTATE A STEPPER MOTOR
; 64 DEGREES IN CLOCKWISE DIRECTION USING 4 STEP SEQUENCE
; IT TAKES SOME CALCULATIONS
; CONSIDER A MOTOR WITH STEP ANGLE 2 DEGREE
; SO STEPS PER REVOLUTION = 180
; NO OF ROTOR TEETH = 45
; MOVEMENT PER 4 STEP SEQUENCE IS 8 DEGREES
; FOR 64 DEGREE MOVEMENT WE NEED TO SEND 8 CONSECUTIVE 4 STEP SEQUENCE
; THAT IS IT WILL COVER 32 STEPS

ORG 0000H
MOV A, #66H
MOV R1, #32H    ; 32 STEPS TO BE TAKEN

BACK :
RR A        ; ROTATE CLOCKWISE
MOV P1, A    ;
ACALL DELAY    ;
DJNZ R1, BACK    ;
END
-----------------

Now few question arises
q1) why did we took 66h as step value??
Ans))

A normal 4 step sequence is like below.
Step #
Winding A
Winding B
Winding C
Winding D
1
1
0
0
1
2
1
1
0
0
3
0
1
1
0
4
0
0
1
1
Going from step 1 to 4 we rotate motor clockwise
Going from step 4 to 1 we rotate motor counter clockwise

The stepper motor discussed here has total 6 leads. 4 leads representing 4 windings and 2 commons for centre tapped leads. Here we have used 2 phase 4 step sequence. It must also be noted we can start from any step.  Be it step 1,2,3 or 4. But we must continue in proper order for proper rotation.
In programs on blog I have mostly begun from step 3.
 other step sequences are as below

Half Step 8 Step Sequence
Step #
Winding A
Winding B
Winding C
Winding D
1
1
0
0
1
2
1
0
0
0
3
1
1
0
0
4
0
1
0
0
5
0
1
1
0
6
0
0
1
0
7
0
0
1
1
8
0
0
0
1



Wave drive 4 step sequence

Step #
Winding A
Winding B
Winding C
Winding D
1
1
0
0
0
2
0
1
0
0
3
0
0
1
0
4
0
0
0
1





 q2) how much movement is associated with a step angle??

Step angle
Steps per revolution
.72
500
1.8
200
2
180
2.5
144
5
72
7.5
48
15
24


 ------------------

Edit - 1: Changed the Line DJNZ R0 to R1 as it was a mistake in typing.