Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
328 views19 pages

Stepper Motor Description

This document provides instructions for building and programming an educational kit for controlling a stepper motor using a microcontroller board. It includes a block diagram of the system components, descriptions of how to connect the circuit and program the microcontroller to operate the stepper motor in different modes, speeds and directions. Example programs are provided to demonstrate basic motor control functions like rotating a set number of steps clockwise or counter-clockwise, and more advanced programs control motor speed and direction using buttons.

Uploaded by

Kamal Ra J
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
328 views19 pages

Stepper Motor Description

This document provides instructions for building and programming an educational kit for controlling a stepper motor using a microcontroller board. It includes a block diagram of the system components, descriptions of how to connect the circuit and program the microcontroller to operate the stepper motor in different modes, speeds and directions. Example programs are provided to demonstrate basic motor control functions like rotating a set number of steps clockwise or counter-clockwise, and more advanced programs control motor speed and direction using buttons.

Uploaded by

Kamal Ra J
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

This project is actually an educational kit.

One can study the full operation of unipolar type


stepper motor using this board. As it is micro controller based it can be programmable also and
one can learn micro controller interfacing with LEDs, key board and stepper motor. Thus single
board serves the purpose of learning stepper motor control as well as learning micro controller
programming.

General description and system block diagram:-

The complete board consists of transformer, control circuit, keypad and stepper motor as shown
in snap. The given figure shows the block diagram of project.

System block diagram

The circuit has inbuilt 5 V power supply so when it is connected with transformer it will give the
supply to circuit and motor both. The 8 Key keypad is connected with circuit through which user
can give the command to control stepper motor. The control circuit includes micro controller
89C51, indicating LEDs, and current driver chip ULN2003A. One can program the controller to
control the operation of stepper motor. He can give different commands through keypad like, run
clockwise, run anticlockwise, increase/decrease RPM, increase/decrease revolutions, stop motor,
change the mode, etc. before we start with project it is must that we first understood the
operation of unipolar stepper motor.

Unipolar stepper motor:-

In the construction of unipolar stepper motor there are four coils. One end of each coil is tide
together and it gives common terminal which is always connected with positive terminal of
supply. The other ends of each coil are given for interface.  Specific color code may also be
given. Like in my motor orange is first coil (L1), brown is second (L2), yellow is third (L3),
black is fourth (L4) and red for common terminal.

By means of controlling a stepper motor operation we can

1. Increase or decrease the RPM (speed) of it


2. Increase or decrease number of revolutions of it
3. Change its direction means rotate it clockwise or anticlockwise
To vary the RPM of motor we have to vary the PRF (Pulse Repetition Frequency). Number of
applied pulses will vary number of rotations and last to change direction we have to change pulse
sequence.

So all these three things just depends on applied pulses. Now there are three different modes to
rotate this motor

1. Single coil excitation


2. Double coil excitation
3. Half step excitation

The table given below will give you the complete idea that how to give pulses in each mode

Pulses for stepper motor module

Note:- In half step excitation mode motor will rotate at half the specified given step resolution.
Means if step resolution is 1.8 degree then in this mode it will be 0.9 degree. Step resolution
means on receiving on 1 pulse motor will rotate that much degree. If step resolution is 1.8 degree
then it will take 200 pulses for motor to compete 1 revolution (360 degree).

Now let me give you the specification of the stepper motor that I have used.

Max rated voltage: -    5 V


Max rated current per coil: – 0.5 Amp
Step resolution: -    1.8 degree / pulse
Max RPM: -    20 in single/double coil excitation mode and 60 in half step mode
Torque: – 1.5 Kg/cm2

RPM calculation:-
One can calculate the exact RPM at which motor will run. We know that motor needs 200 pulses
to complete 1 revolution. Means if 200 pulses applied in 1 second motor will complete 1
revolution in 1 second. Now 1 rev. in 1 sec means 60 rev. in 1 minute. That will give us 60 RPM.
Now 200 pulses in 1 sec means the PRF is 200 Hz. And delay will be 5 millisecond (ms). Now
lets see it reverse.

*  If delay is 10 ms then PRF will be 100 Hz.


*  So 100 pulses will be given in 1 sec
*  Motor will complete 1 revolution in 2 second
*  So the RPM will be 30.

In same manner as you change delay the PRF will be changed and it will change RPM

Stepper motor control board circuit:-


Stepper motor control board circuit

The circuit consists of very few components. The major components are 7805, 89C51 and
ULN2003A.

Connections:-

1. The transformer terminals are given to bridge rectifier to generate rectified DC.
2. It is filtered and given to regulator IC 7805 to generate 5 V pure DC. LED indicates
supply is ON.
3. All the push button micro switches J1 to J8 are connected with port P1 as shown to form
serial keyboard.
4. 12 MHz crystal is connected to oscillator terminals of 89C51 with two biasing capacitors.
5. All the LEDs are connected to port P0 as shown
6. Port P2 drives stepper motor through current driver chip ULN2003A.
7. The common terminal of motor is connected to Vcc and rest all four terminals are
connected to port P2 pins in sequence through ULN chip.

Now by downloading different programs in to 89C51 we can control the operation of stepper
motor. Let us see all different kind of program.

Program 1:-
It is advisable to begin with easy program. So in this program we shall see minimal functionality.
Only first two switches and first three LEDs will be used. When you press one switch the motor
will start rotating in clockwise direction and stops when completes one revolution. Pressing
second switch will do the same job but in anticlockwise direction. The speed will be 10 RPM
fixed. Motor runs in single coil excitation mode. First LED indicates key press event. Second
blinks when motor rotates clockwise and third blinks when motor rotates anticlockwise.

Org 00h
mov r0,#01h      ; initileze key count
mov p1,#0ffh      ; P1 as input port
lop:    mov a,p1
cjne a,#0ffh,jmp
ajmp lop              ; loop until any key
; is pressed
jmp:  clr p0.0               ; indicates keypress
loop:  rrc a
jnc num               ; get key no.
inc r0
sjmp loop
num: acall dely          ; key debounce delay
setb p0.0

cjne r0,#01h,nxt      ; for 1st key


acall clkwise             ; rotate motor
sjmp over                 ; clock wise
nxt:    cjne r0,#02h,over ; for 2nd key
acall aclkwise          ; rotate anticlock

over:  mov p2,#00h        ; restore initial


mov p1,#0ffh           ; data and
mov r0,#01h
sjmp lop                   ; jump to loop again

clkwise:
mov r1,#32h           ; load count 50d
go: clr  p0.1
mov p2,#01h          ;give 4 pulses in loop
acall delay              ; total 200 pulses
mov p2,#02h          ; each coil energized
acall delay              ; one by on in single
setb p0.1
mov p2,#04h          ; coil excitation
acall delay              ; 30 ms delay in betwn
mov p2,#08h          ; means speed is
acall delay              ; 10 RPM
djnz r1,go
ret
aclkwise:
mov r1,#32h
go1:clr p0.2
mov p2,#01h
acall delay
mov p2,#08h       ; revert the pulse
acall delay           ; sequence for
setb p0.2
mov p2,#04h       ; anticlockwise
acall delay
mov p2,#02h
acall delay
djnz r1,go1
ret

delay:
mov r5,#1Eh        ; load count 30
lop2: mov r6,#FAh     ; give 1 ms delay
lop1:nop                    ; so it gives full
nop                       ; 30 ms delay
djnz r6,lop1
djnz r5,lop2
ret
dely:
mov r5,#0C8h      ; load count 200
lop2: mov r6,#0FAh   ; for 200ms delay
lop1: nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end
Program 2:-
Here in this program we shall limit the motor to rotate only 7.2o in either direction when the key
is pressed. When first key is pressed motor rotates in clockwise direction and when second is
pressed anticlockwise direction. LED1 and LED2 indicate the clockwise and anticlockwise
rotation.
Note: – In industries this is also known as “jogging” (jog control). This is done to check in which
direction motor will start running.

Org 00h
mov r0,#01h                     ; initileze key count
mov p1,#0ffh                    ; P1 as input port
lop:   mov a,p1
cjne a,#0ffh,jmp
ajmp lop                             ; loop until any key is pressed
jmp:     clr p0.0                   ; indicates keypress
loop:    rrc a
jnc num                              ; get key no.
inc r0
sjmp loop
num: acall dely                  ; key debounce delay
setb p0.0

cjne r0,#01h,nxt               ; for 1st key


acall clkwise                      ; rotate motor
sjmp over                          ; clock wise
nxt: cjne r0,#02h,over      ; for 2nd key
acall aclkwise                    ; rotate anticlock

over:   mov p2,#00h         ; restore initial


mov p1,#0ffh                     ; data and
mov r0,#01h
sjmp lop                             ; jump to loop again

clkwise:
clr p0.1
mov p2,#01h                     ;give 4 pulses in loop
acall delay                         ; as 1.8o step resolution
mov p2,#02h                     ; total 7.2o rotation
acall delay                         ; in single coil
setb p0.1
mov p2,#04h                     ; excitation
acall delay                         ; 30 ms delay in betwn
mov p2,#08h                     ; means speed is
acall delay                         ; 10 RPM
ret
aclkwise:
clr p0.1
mov p2,#01h
acall delay
mov p2,#08h                     ; revert the pulse
acall delay                          ; sequence for
setb p0.1
mov p2,#04h                     ; anticlockwise
acall delay
mov p2,#02h
acall delay
ret

delay:
mov r5,#1Eh                      ; load count 30
lop2: mov r6,#FAh             ; give 1 ms delay
lop1:nop                            ; so it gives full
nop                                    ; 30 ms delay
djnz r6,lop1
djnz r5,lop2
ret

dely:
mov r5,#0C8h                    ; load count 200
lop2: mov r6,#0FAh           ; for 200ms delay
lop1:nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end

Program 3:-

This is also easy program. Now three keys are used and three LEDs are used. Please refer table.
The speed of motor is again fixed at 20 RPM. The mode is double coil excitation.
Org 00h
mov r0,#01h         ; initileze key count
mov p1,#0ffh        ; P1 as input port
lop:   mov a,p1
cjne a,#0ffh,jmp
ajmp lop               ; loop until any key is pressed

jmp:     clr p0.0              ; indicates keypress


loop:    rrc a
jnc num                ; get key no.
inc r0
sjmp loop
num: acall dely          ; key debounce delay
setb p0.0

cjne r0,#01h,nxt   ; for 1st key rotate motor


acall clkwise          ; clock wise
sjmp over
nxt: cjne r0,#02h,nxt2  ; for 2nd key
acall aclkwise           ; rotate anticlock
nxt2:   cjne r0,#03h,over ; for 3rd key
mov p2,#00h             ; stop motor
over:   mov r0,#01h
sjmp lop          ; jump to loop again

clkwise:
lop:   clr p0.1
mov p2,#03h        ; at a time two coils
acall delay            ; energized in double
mov p2,#06h        ; coil excitation mode
acall delay
setb p0.1
mov p2,#0Ch
acall delay
mov p2,#09h
acall delay
mov p1, #0FFh      ; continue loop
mov a,p1               ; until any key is
cjne a,#0FFh,out   ; not pressed
sjmp lop
out:   ret
aclkwise:
lop1: clr p0.1
mov p2,#03h
acall delay
mov p2,#09h        ; revert the pulse
acall delay            ; sequence for
setb p0.1
mov p2,#0Ch        ; anticlockwise
acall delay
mov p2,#06h
acall delay
mov p1, #0FFh
mov a,p1
cjne a,#0FFh,out1
sjmp lop1
out1:  ret

delay:
mov r5,#0Fh         ; load count 15
lop2: mov r6,#FAh      ; give 1 ms delay
lop1:nop                    ; so it gives full
nop                       ; 15 ms delay
djnz r6,lop1          ; to give speed
djnz r5,lop2           ; of 20 RPM
ret

dely:
mov r5,#0C8h          ; load count 200
lop2: mov r6,#0FAh       ; for 200ms delay
lop1:nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end

Program 4:-
This  program is same as above but now the mode is changed to half step and RPM is now 30.

Org 00h
mov r0,#01h        ; initileze key count
mov p1,#0ffh       ; P1 as input port
lop:   mov a,p1
cjne a,#0ffh,jmp
ajmp lop               ; loop until any key is pressed
jmp:     clr p0.0              ; indicates keypress
loop:    rrc a
jnc num                ; get key no.
inc r0
sjmp loop
num: acall dely         ; key debounce delay
setb p0.0

cjne r0,#01h,nxt      ; for 1st key


acall clkwise             ; rotate motor
sjmp over                  ; clock wise
nxt: cjne r0,#02h,nxt2  ; for 2nd key
acall aclkwise           ; rotate anticlock
nxt2:   cjne r0,#03h,over  ; for 3rd key
mov p2,#00h             ; stop motor
over:   mov r0,#01h
sjmp lop                     ; jump to loop again

clkwise:
lop:   clr p0.1
mov p2,#01h         ; alternate pulses
acall delay             ; given one from
mov p2,#03h         ; single coil second
acall delay              ; from double coil
mov p2,#02h         ; in half step mod
acall delay
mov p2,#06h
acall delay
setb p0.1
mov p2,#04h
acall delay
mov p2,#0Ch
acall delay
mov p2,#08h
acall delay
mov p2,#09h
acall delay
mov p1, #0FFh       ; continue loop
mov a,p1                ; until any key is
cjne a,#0FFh,out   ; not pressed
sjmp lop
out:   ret
aclkwise:
lop1: clr p0.1
mov p2,#01h
acall delay
mov p2,#03h         ; revert the pulse
acall delay             ; sequence for
mov p2,#08h        ; anticlockwise
acall delay
mov p2,#09h
acall delay
setb p0.1
mov p2,#04h
acall delay
mov p2,#0Ch
acall delay
mov p2,#02h
acall delay
mov p2,#06h
acall delay
mov p1, #0FFh
mov a,p1
cjne a,#0FFh,out1
sjmp lop1
out1:  ret
delay:
mov r5,#0Ah          ; load count 10
lop2: mov r6,#FAh         ; give 1 ms delay
lop1: nop                        ; so it gives full
nop                         ; 10 ms delay
djnz r6,lop1            ; to give speed
djnz r5,lop2            ; of 30 RPM
ret
dely:
mov r5,#0C8h         ; load count 200
lop2: mov r6,#0FAh        ; for 200ms delay
lop1: nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end

Program 5:-

Now its time to start with harder programs. In this program all above facilities are there and two
more are included increasing and decreasing RPM. Five switches and four LEDs are used. See
the table for key functions and LED indications.
f equ 0fh                            ; direction flag
Org 00h
mov 30h, #3Ch       ; make a table of
mov 31h, #1Eh        ; four load values
mov 32h, #14h        ; for variable delay
mov 33h, #0Fh
mov r1, #30h           ;initial location in r1
mov r0,#01h            ; initialize key count
mov p1,#0ffh           ; P1 as input port
lop:   mov a,p1
cjne a,#0ffh,jmp
ajmp lop                   ; loop until any key
; is pressed
jmp:     clr p0.0                 ; indicates keypress
loop:    rrc a
jnc num                   ; get key no.
inc r0
sjmp loop
num: acall dely            ; key debounce delay
setb p0.0

cjne r0,#01h,nxt      ; for 1st key


acall clkwise             ; rotate motor
sjmp over                 ; clock wise
nxt: cjne r0,#02h,nxt2  ; for 2nd key
acall aclkwise           ; rotate anticlock
nxt2:   cjne r0,#03h,nxt3    ; for 3rd key
mov p2,#00h               ; stop motor
nxt3:   cjne r0,#04h,nxt4    ; for 4th key
acall incrpm                 ; increase RPM
jnb f, aclk                     ; and continue to rotate
acall clkwise                ; motor in same
sjmp over                     ; direction as it was
aclk:    acall aclkwise            ; running by
sjmp over                     ; checking flag f
nxt3:   cjne r0,#05h,over     ; for 5th key
acall decrpm                ; decrease RPM and
jnb f, aclkw                   ; again continue to
acall clkwise                 ; rotate motor
sjmp over
aclks:   acall aclkwise
sjmp over

over:   mov r0,#01h


sjmp lop                    ; jump to loop again
clkwise:
setb f                        ; for clkwise set directional
lop:   clr p0.1 ; flag
mov p2,#03h            ; at a time two coils
acall delay                ; energized in double
mov p2,#06h            ; coil excitation mode
acall delay
setb p0.1
mov p2,#0Ch
acall delay
mov p2,#09h
acall delay
mov p1, #0FFh           ; continue loop
mov a,p1                    ; until any key is
cjne a,#0FFh,out       ; not pressed
sjmp lop
out:   ret
aclkwise:
clr f                           ; for aclkwise clear
lop1: clr p0.1                  ; directional flag
mov p2,#03h
acall delay
mov p2,#09h             ; revert the pulse
acall delay                 ; sequence for
setb p0.1
mov p2,#0Ch            ; anticlockwise
acall delay
mov p2,#06h
acall delay
mov p1, #0FFh
mov a,p1
cjne a,#0FFh,out1
sjmp lop1
out1:  ret

incrpm:
clr p0.3                   ; indication
cjne r1,#33h,incr   ; if max limit is
ajmp noin                ; reached no increase
incr: inc r1                    ; increase otherwise
acall dely
setb p0.3
noin:  ret                        ; led stays on for max limit

decrpm:
clr p0.3                    ; indication
cjne r1,#30h,incr    ; if min limit is
ajmp noin                 ; reached no decrease
incr: dec r1                    ; decrease otherwise
acall dely
setb p0.3
noin:  ret                         ; led stays on for min limit

delay:
mov 10h,@r1           ; load content of
lop2: mov r6,#FAh        ; address in r1
lop1:nop                       ; so it gives variable
nop                          ; delay every time
djnz 10h,lop1           ; to give variable
djnz r5,lop2              ; speed of motor
ret

dely:
mov r5,#0C8h           ; load count 200
lop2: mov r6,#0FAh         ; for 200ms delay
lop1:nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end

Program 6:-

Now I am adding one more functionality in the program. Now instead of continuously running
motor, motor will run till desired no. of revolutions entered. Means motor will automatically
stops when it completes desired revolutions. One can increase or decrease revolutions in step of
one (1, 2, 3 …).  I have used 6 keys and 5 LEDs.
In the first program we have limit the number of applied pulses to 200. Now again we shall load
the number every time that will change number of applied pulses. There is no maximum limit but
sure there is minimum limit that is 1 revolution.

Org 00h
mov 30h, #3Ch           ; make a table of
mov 31h, #1Eh           ; four load values
mov 32h, #14h           ; for variable delay
mov 33h, #0Fh
mov r1, #30h              ; initial location in r1
mov 2fh,#32h             ; initial load value
mov 2eh,#01h            ; for no. of rev.
mov r0,#01h               ; initialize key count
mov p1,#0ffh              ; P1 as input port
lop:   mov a,p1
cjne a,#0ffh,jmp
ajmp lop                       ; loop until any key is pressed

jmp:     clr p0.0                     ; indicates keypress


loop:    rrc a
jnc num                        ; get key no.
inc r0
sjmp loop
num: acall dely                  ; key debounce delay
setb p0.0
cjne r0,#01h,nxt
acall clkwise
sjmp over
nxt:  cjne r0,#02h,nxt2
acall aclkwise
sjmp over
nxt2: cjne r0,#03h,nxt3
acall incrpm
sjmp over
nxt3: cjne r0,#04h,nxt4
acall decrpm
sjmp over
nxt4: cjne r0,#05h,nxt5
acall increv
sjmp over
nxt5:cjne r0,#06h,over
acall decrev

over:   mov p2,#00h


mov p1,#0ffh
mov r0,#01h
sjmp lop
clkwise:
mov r1,2Fh              ; load variable count
go: clr  p0.1
mov p2,#01h          ; single coil
acall delay              ; excitation
mov p2,#02h
acall delay              ; variable delay
setb p0.1
mov p2,#04h
acall delay
mov p2,#08h;
acall delay
djnz r1,go
ret
aclkwise:
mov r1,2Fh
go1:clr p0.2
mov p2,#01h
acall delay
mov p2,#08h
acall delay
setb p0.2
mov p2,#04h
acall delay
mov p2,#02h
acall delay
djnz r1,go1
ret
incrpm:
clr p0.3                     ; indication
cjne r1,#33h,incr     ; if max limit is
ajmp noin                  ; reached no increase
incr: inc r1                      ; increase otherwise
acall dely
setb p0.3
noin:  ret                         ; led stays on for max limit

decrpm:
clr p0.3                    ; indication
cjne r1,#30h,decr   ; if min limit is
ajmp noin                 ; reached no decrease
decr: dec r1                   ; decrease otherwise
acall dely
setb p0.3
noin: ret                         ; led stays on for min limit
increv:
clr p0.4                    ; indication
inc 2Eh                    ; increment multiplying factor
mov a,#32h
mov b,2Eh
mul ab                      ; multiply it by load value
mov 2Fh,a                ; stores the new load value
acall dely
setb p0.4
ret
decrev:
clr p0.4
mov r4,2Eh
cjne r4,#01h,decn     ; check for min
ajmp out2                   ; limit of multiplying
decn: dec 2Eh                 ; factor. If not reached
mov a,#32h              ; decrease it
mov b,2Eh
mul ab                       ; multiply it with load
mov 2Fh,a                 ; value and store the
acall dely                  ; new load value
setb p0.4
out2: ret

delay:
mov 10h,@r1              ; load the count
lop2: mov r6,#FAh           ; from table
lop1: nop
nop
djnz 10h,lop1
djnz r5,lop2
ret
dely:
mov r5,#0C8h             ; load count 200
lop2: mov r6,#0FAh          ; for 200ms delay
lop1: nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end

Program 7:-
This program adds two more things to above program. It changes the mode of operation of
stepper motor also it adds jog control. It changes three different modes on pressing one key. All
eight keys and eight LEDs are now used.

When J7 key is pressed first time the mode will change from single coil to double coil. When
pressed second time mode will change from double coil to half step. And on pressing third time
again the same mode will repeat. When J8 key is pressed the motor will rotate in previously
selected direction. Means if motor was running in clockwise direction then the jog will be in
same direction.

Program 8:-

In above program motor doesn’t rotate continuously. In this program motor rotates continuously
and one can change the RPM and operating mode while running. 6 keys and 8 LEDs are used.
by
Ashutosh M Bhatt
www.multyremotes.com

You might also like