You are on page 1of 16

Chapter 5 Practical of stepper Motor

Chapter 5
Practical of stepper Motor

1. Circuit drawing of Stepper Motor controller

-1-
Chapter 5 Practical of stepper Motor

2. Pattern drawing of Stepper Motor controller

(Wiring side)

3. Circuit explanation of Stepper Motor Controller

3.1 Motor driving circuit

This is the circuit which drives the coil of stepper motor. There are circuits
which drive coil, coil, coil and coil respectively.

-2-
Chapter 5 Practical of stepper Motor

Darlington connection-type transistor is used for the drive of the coil. As for
the Darlington connection, 2 stages of transistors are connected inside in
series. The "hfe" of this transistor is the multiplication of the "hfe" of each
transistor inside. In case of 2SD1209K which was used this time, the h fe is
over 4000. Because the ratio of the input electric current and the output
current is big, the rising edge and the falling edge of the control signal can be
made sharp.
The diode to be putting between the collector and the power is for the
protection of the transistor. When the transistor becomes OFF from ON, the
coil of the motor tries to continue to pass an electric current and generates
high voltage. An electric current by this voltage is applied to the diode and the
high voltage which applies over the transistor is prevented.

3.2 Speed control circuit

This is the circuit which controls the rotational speed of the motor.
TR1 becomes ON condition when RB7 becomes H level. In this condition, the
electric charge of capacitor C1 flows through the transistor and the voltage of
the both edges of the capacitor becomes 0V almost.
When RB7 becomes an L level, the transistor becomes OFF condition. In
this condition, the electric current flows through VR1 and R4 into capacitor
C1 and the charging to the capacitor begin. The voltage of the both edges of
the capacitor becomes high gradually as charging is done. As for the change
of this voltage, refer to "Integration circuit".
The voltage of the capacitor is detected by RB5. The software of PIC
interrupts the control of the motor until it checks RB5 after making RB7 an L
level and RB5 becomes H level. When making the value of VR1 small, the
charging time of the capacitor is short and the control of the motor becomes

-3-
Chapter 5 Practical of stepper Motor

quick. The control of the motor becomes slow when making VR1 big. The
speed control range can be changed by changing the value of the capacitor.

3.3 Start/stop circuit

This is the circuit for the clockwise rotating, the counterclockwise


rotating or stopping a motor. The baton switch of the non lock is used. Pull-up
resistor is used for the port to become H level when the switch is OFF. The
RB port of PIC16F84A has an internal pull up feature. However, because RB5
is used for the voltage detection of the capacitor at the circuit this time, an
internal pull up feature isn't used. If using RA port for the voltage detection of
the capacitor, the RB internal pull up feature can be used. The circuit this time
put an external pull-up resistor in the relation of the pattern.

3.4 Oscillator

4-MHz resonator is used because the circuit this time doesn't need high-speed
operation

3.5 Power supply circuit

-4-
Chapter 5 Practical of stepper Motor

The purpose of this circuit is to keep power supply voltage to PIC to 5V


when the power of the stepper motor is more than 5V.
Because the operating voltage of the stepper motor to be using this time is
about 5V, the power supply voltage is +5V. In this case, the voltage which is
applied to PIC becomes less than 5V because of the voltage drop (about 1V)
of the regulator. In case of PIC16F84A, the operation is possible even if the
power falls to about 3V because the operating voltage range is from 2V to
5.5V.It is enough in the 100-mA type.

4. Parts explanation of Stepper Motor controller

4.1 Stepper motor (42SPM-24DCZA)

This is a 2-phase unipolar PM type stepper


motor with 48-poles.

Step angle : 7.5 degrees ( 360 degrees/48 )


Drive voltage : 5 to 6V
Coil current : 250mA(5V)/2 coils

4.2 PIC16F84A

-5-
Chapter 5 Practical of stepper Motor

The control of the stepper motor is done by this PIC. To have explained in
the operation principle, coil, coil, coil and coil are controlled by the
software.

4.3 three terminal regulator (78L05)

This is used to make the stable voltage of +5V.


A 100-mA type is used.

4.4 Motor drive transistor


(2SD1209K)

This is a Darlington connection-type transistor.


At first, I used 2SD1590 (8A type) as the transistor for the
drive. However, in case of the motor which was used this time,
the coil current was about 250 mA. So, I changed into the small
type transistor. The maximum collector current of 2SD1209K
is 1A and "hfe" is more than 4000.

4.5 Transistor for the motor speed control ( 2SC1815 )

This is the transistor to control the speed of the motor.

4.6 Diode for the transistor protection

This is the diode to protect a transistor from the


back electromotive force which occurs with the coil of
the stepper motor. It depends on the kind of the stepper

-6-
Chapter 5 Practical of stepper Motor

motor but it is to be OK if it is possible to pass a hundreds-of-mA electric


current.

4.8 Resonator

This is a 4 MHz resonator

4.9 Variable resistor for the speed control

B type is used

4.10 Resistor

It is to be OK at 1/8 W

4.11 Resistor for pull up

This is the series resistor to be using for start/stop


switch pull up.

4.12 Multilayer ceramic capacitor


This capacitor is used to bypass the high frequency
noise of the input and output of the power
supply.

4.13 Electrolytic capacitor

This capacitor is used as the ripple filter capacitor of


the power circuit

-7-
Chapter 5 Practical of stepper Motor

4.14 Connector for the stepper motor connection


A 6-pin connector is used to connect a stepper motor.
The motor used this time, 5-pin connector is OK. Because
the power of the X coil and the Y coil is connected inside
the motor. However, a power line is divided by the kind of
the motor. So, 6-pin are used for two power lines to be able
to be connected.
5. Software of stepper Motor controller

5.1 The flow chart

-8-
Chapter 5 Practical of stepper Motor

5.2 Source code file of stepper motor controller

001 ;********************************************************
002 ;
003 ; Stepper Motor controller
004 ;
005 ; Author : Seiichi Inoue
006 ;********************************************************

-9-
Chapter 5 Practical of stepper Motor

007
008 list p=pic16f84a
009 include p16f84a.inc
010 __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
011
012 ;**************** Label Definition ********************
013 cblock h'0c'
014 mode ;Operation mode
015 ;0=stop 1=right 2=left
016 count1 ;Wait counter
017 count2 ;Wait counter(for 1msec)
018 endc
019
020 rb0 equ 0 ;RB0 of PORTB
021 rb1 equ 1 ;RB1 of PORTB
022 rb2 equ 2 ;RB2 of PORTB
023 rb5 equ 5 ;RB5 of PORTB
024 rb7 equ 7 ;RB7 of PORTB
025
026 ;**************** Program Start ***********************
027 org 0 ;Reset Vector
028 goto init
029 org 4 ;Interrupt Vector
030 clrf intcon ;Clear Interruption reg
031
032 ;**************** Initial Process *********************
033 init
034 bsf status,rp0 ;Change to Bank1
035 clrf trisa ;Set PORTA all OUT
036 movlw b'00100111' ;RB0,1,2.5=IN RB7=OUT
037 movwf trisb ;Set PORTB
038 movlw b'10000000' ;RBPU=1 Pull up not use
039 movwf option_reg ;Set OPTION_REG
040 bcf status,rp0 ;Change to Bank0
041 clrf mode ;Set mode = stop
042 clrf count1 ;Clear counter
043 clrf count2 ;Clear counter
044 movlw b'00000101' ;Set PORTA initial value
045 movwf porta ;Write PORTA
046 bsf portb,rb7 ;Set RB7 = 1
047 btfsc portb,rb5 ;RB5 = 0 ?

- 10 -
Chapter 5 Practical of stepper Motor

048 goto $-1 ;No. Wait


049
050 start
051 ;************* Check switch condition *****************
052 btfsc portb,rb1 ;RB1(stop key) = ON ?
053 goto check1 ;No. Next
054 clrf mode ;Yes. Set stop mode
055 goto drive ;No. Jump to motor drive
056 check1
057 btfsc portb,rb2 ;RB2(right key) = ON ?
058 goto check2 ;No. Next
059 movlw d'1' ;Yes. Set right mode
060 movwf mode ;Save mode
061 goto drive ;No. Jump to motor drive
062 check2
063 btfsc portb,rb0 ;RB0(left key) = ON ?
064 goto drive ;No. Jump to motor drive
065 movlw d'2' ;Yes. Set left mode
066 movwf mode ;Save mode
067
068 ;******************** Motor drive *********************
069 drive
070 movf mode,w ;Read mode
071 bz start ;mode = stop
072 bsf portb,rb7 ;Set RB7 = 1
073 btfsc portb,rb5 ;RB5 = 0 ?
074 goto $-1 ;No. Wait
075 movlw d'5' ;Set loop count(5msec)
076 movwf count1 ;Save loop count
077 loop call timer ;Wait 1msec
078 decfsz count1,f ;count - 1 = 0 ?
079 goto loop ;No. Continue
080 bcf portb,rb7 ;Set RB7 = 0
081 btfss portb,rb5 ;RB5 = 1 ?
082 goto $-1 ;No. Wait
083 movf porta,w ;Read PORTA
084 sublw b'000000101' ;Check motor position
085 bnz drive2 ;Unmatch
086 movf mode,w ;Read mode
087 sublw d'1' ;Right ?
088 bz drive1 ;Yes. Right

- 11 -
Chapter 5 Practical of stepper Motor

089 movlw b'00001001' ;No. Set Left data


090 goto drive_end ;Jump to PORTA write
091 drive1
092 movlw b'00000110' ;Set Right data
093 goto drive_end ;Jump to PORTA write
094 ;-------
095 drive2
096 movf porta,w ;Read PORTA
097 sublw b'000000110' ;Check motor position
098 bnz drive4 ;Unmatch
099 movf mode,w ;Read mode
100 sublw d'1' ;Right ?
101 bz drive3 ;Yes. Right
102 movlw b'00000101' ;No. Set Left data
103 goto drive_end ;Jump to PORTA write
104 drive3
105 movlw b'00001010' ;Set Right data
106 goto drive_end ;Jump to PORTA write
107 ;-------
108 drive4
109 movf porta,w ;Read PORTA
110 sublw b'000001010' ;Check motor position
111 bnz drive6 ;Unmatch
112 movf mode,w ;Read mode
113 sublw d'1' ;Right ?
114 bz drive5 ;Yes. Right
115 movlw b'00000110' ;No. Set Left data
116 goto drive_end ;Jump to PORTA write
117 drive5
118 movlw b'00001001' ;Set Right data
119 goto drive_end ;Jump to PORTA write
120 ;-------
121 drive6
122 movf porta,w ;Read PORTA
123 sublw b'000001001' ;Check motor position
124 bnz drive8 ;Unmatch
125 movf mode,w ;Read mode
126 sublw d'1' ;Right ?
127 bz drive7 ;Yes. Right
128 movlw b'00001010' ;No. Set Left data
129 goto drive_end ;Jump to PORTA write

- 12 -
Chapter 5 Practical of stepper Motor

130 drive7
131 movlw b'00000101' ;Set Right data
132 goto drive_end ;Jump to PORTA write
133 ;-------
134 drive8
135 movlw b'00000101' ;Compulsion setting
136
137 drive_end
138 movwf porta ;Write PORTA
139 goto start ;Jump to start
140
141 ;************* 1msec Timer Subroutine *****************
142 timer
143 movlw d'200' ;Set loop count
144 movwf count2 ;Save loop count
145 tmlp nop ;Time adjust
146 nop ;Time adjust
147 decfsz count2,f ;count - 1 = 0 ?
148 goto tmlp ;No. Continue
149 return ;Yes. Count end
150
151 ;********************************************************
152 ; END of Stepper Motor controller
153 ;********************************************************
154
155 end

6. Processing explanation of stepper Motor controller

6.1 Label definition


The data area is automatically assigned from 0ch by CBLOCK directive.
ENDC is used for the ending of assignment.
The purpose of each data area is shown below.

- 13 -
Chapter 5 Practical of stepper Motor

Label Purpose
This is the area which manages the condition of the motor control.
mode :
0=Stop, 1=Clockwise, 2=Counterclockwise
This is the count area to make control waiting time.
count1 :
It counts 1 millisecond five times and 5 milliseconds are made.
count2 : This is the counter to make 1 millisecond.

6.2 Program start

Instruction is executed from Zero addresses of the program memory when


making the power ON of the PIC. When there is interruption processing,
processing is begun from the addresse 4. Because it isn't using interruption
this time, there is not program execution from the addresse 4. It makes the
interruption prohibition condition if the interruption occurs. It isn't necessary
to do this processing.

6.3 Initialization process

The following processing is done as the processing of being initialized after


the turning on

The initialization of the mode of port A


All ports are set to output mode.

The initialization of the mode of port B


RB0, 1, 2 and 5 are set to input mode. And RB7 is set to output mode.

Port B pull-ups are disabled (RPBU=1)


Because RB5 is used as the high impedance input at the circuit this time, the
RB pull up feature should not be used.

Setting of a stop mode

- 14 -
Chapter 5 Practical of stepper Motor

Immediately after turned on, it sets a motor to the stop mode. When there is
not this step, the original value of mode becomes 0. It is put for the safety.

Counters for the control waiting time are initialized


There is not a problem even if there is not this processing. They are put for the
safety.

Port A initialization
It sets 0101 as the initial state of port A. Because it drives with the transistor,
the logic reverses. It is in the condition, =H =L =H =L, from the bit on the left.

Discharging of the capacitor for the speed control


It makes RB7 H level and it makes TR1 ON and discharging in the electric
charge of the capacitor for the speed control. The end of the discharge is
confirmed by RB5.

6.4 Switch condition confirmation process


It detects the ON condition of the stop switch, the RRC switch, the RLC
switch. A condition is set to mode according to the kind of the switch which
was made ON. The order of the detection is a stop, a RRC, a RLC. When
more than one switch is pushed at the same time, the switch which detected
ON earlier is effective.
This processing is done every time it controls 1 step of motor.

6.5 Motor drive process


A stop mode is checked first. In case of the stop mode, it doesn't drive the
motor and it jumps to the switch condition confirmation process.

In case of not being a stop mode, the following process is done.

Discharging of the capacitor for the speed control


Discharging the capacitor as the preparation to make the timing of the speed
control.

The wait processing of 5 milliseconds


- 15 -
Chapter 5 Practical of stepper Motor

In the high-speed control, the rotor doesn't follow the change of the magnetic
pole and the step motor doesn't rotate normally. It sets a timer value to turn a
full speed normally.
In case of the motor which was used this time, it doesn't rotate normally when
making less than 5 milliseconds.

The charging of a capacitor for the speed control and the confirmation
process
It makes RB7 an L level and it begins charging the capacitor. It confirms that
the charging completes by RB5. It is completion if RB5 becomes H level.
Correctly, it is not charging completion and it is the fact that the voltage of the
capacitor became above the threshold voltage of RB5.

The motor drive process


After the speed control timing, a motor is driven. The control state of the
motor is confirmed first. This is done by reading the condition of port A.
Next, whether it is a clockwise mode or a counterclockwise mode is judged.
The following control state which should drive a motor by the result is set to
port A. Because there are four conditions, processing is done in each
condition.
After the motor drive process, it jumps again to the switch condition
confirmation process.

- 16 -

You might also like