Sie sind auf Seite 1von 12

TUTORIAL FOR RUNNING A

STEPPER-MOTOR USING
KRYPTON BOARD
[WEL – LAB,IIT BOMBAY]
Contents:

Design Problem.....

Description.....

Implementation.....

System Bring up....


Design problem:

a)To actuate the stepper motor,so that the wheel attached to the
rotor rotates in steps of x degrees.

b)To control the direction of rotation using a switch.

c) To control the speed of rotation using a switch.

Description:

Stepper motor is a DC motor in which the rotor is made to


rotate in steps of X-degrees,where the value x depends upon the
type of excitation.
In this problem we shall consider a simple unipolar stepper motor
and wave drive sequence for excitation which shall be explained
shortly.
The conceptual model of a unipolar stepper motor in the
problem is as shown below.

Figure 1: Conceptual model of stepper motor


(Courtesy:http://www.stepperworld.com/Tutorials/pgUnipolarTutorial.ht
m)
The rotor aligns in the direction of the electromagnetic field,
created by exciting a particular winding. The rotor should rotate in
steps of 90 degrees in the above model when windings are excited
one by one in a sequence, based on the required direction in the
above model. Ofcourse the above model is a simplified one and in a
practical stepper motor the windings are distributed in such a way
that the rotor rotates in finer steps. Also note that in the stepper
motor provided, the centre taps are shorted and thus the number of
terminals accessible are 5.

In practical scenarios various stepping sequences are used based


on the considerations like torque,power,vibration etc.In our design
problem, we shall consider the simplest kind of excitation, namely the
wave-drive stepping sequence. The sequence is as shown below.

Figure 2: Voltage waveforms to the four end of the coils 1a,1b,2a,2b


respectively.Common terminal is grounded(Courtesy:Wikipedia).

In other words the sequence 0001, 0010, 0100, 1000 is to be fed


to the coil terminals 1a,1b,2a,2b respectively in a periodic manner. To
change the direction of rotation the sequence is to be reversed i.e
0001,0010,0100,1000 is to be fed the coils periodically.

To change the speed of rotation, the sequence have to be fed


to the coils at a faster rate.
Implementation:

Before proceeding to implementation let us consolidate our


problem statement.

Consolidated Problem Statement from Krypton's point of view:


The system has to generate the sequence
0001, 0010, 0100, 1000 if S1 is ON
0001, 1000, 0100, 0010 if S1 is OFF
Note: Hence S1 is a direction switch
Let the sequence be output at Pins 70, 72, 74, 76 respectively(These
pins are mapped to the LCD connector and hence easy to wire).
S1 is mapped to pin 48 of CPLD.

Let S2 be reset switch i.e if S2 is turned ON the stepper motor


stops rotating and the output should remain constant at an initial
value, 0001. S2 is mapped to pin 45 of CPLD.

Let S3 and S4 be speed control switches i.e Depending upon the


value of S3 and S4, the rate at which the output changes, varies.
S3 and S4 are mapped to 44 and 43 respectively.

S3S4 Rate of change of output

00 1.5Hz

01 6Hz

10 24Hz

11 96Hz

As we now have a consolidated problem specifications, let us


move on to implementing the system on the Krypton CPLD board
using VHDL.
The architecture:

One possible architecture of the system is as shown below:

Figure 3: Architecture. The numbers in square bracket represent the


pin number of the CPLD to which it is to be mapped.

Counter:

Since 4 different clock speeds, each greater than its


predecessor by 4-times is to be generated, a counter with on-board
crystal of 50MHz frequency as its clock source is used.

The frequency of waveform generated at the most significant


bit(counter(24)) will be 50Mhz/2^25 = 1.5Hz
Frequence of waveform at counter(22) will be 6Hz
Frequence of waveform at counter(20) will be 24Hz
Frequence of waveform at counter(18) will be 96Hz

Let us use ripple counter in our design.


The entity description of the ripple counter shall be

entity generic_counter is

port (gclk:in std_logic;


clr:in std_logic;
counter_out:out std_logic_vector(24 downto 0)
);
end generic_counter;

Figure-4: 4-bit ripple counter

Figure-4 shows 4-bit ripple counter. A 4-bit counter can be


structurally defined very easily in VHDL. But in order to define a 25
bit counter in VHDL a considerable number lines of code have to
written. Therefore there is provision in VHDL to define a repetitive
structure using a very few number of lines of code. This provision is
made available to us using generate statements.

The syntax of generate statement is as shown:

grp_name: for index in 1 to 24 generate


begin

component_instances: component_name port map(data,q(i-


1),clr,q(i),qbar(i));

end generate;
The connections established between the componant instances using the
above statement is as shown below.24 such component instances will be
generated using such simple structural definition.

Figure-5: Connection established between two component instances


using generate statement.

Multiplexer:

A 4:1 multiplixer can be easily defined using VHDL construct as


shown below

PROCESS (select_in)
BEGIN
CASE select_in IS
WHEN "00" =>
temp_clk <= counter_out(24);
WHEN "01" =>
temp_clk <= counter_out(22);
WHEN "10" =>
temp_clk <= counter_out(20);
WHEN "11" =>
temp_clk <= counter_out(18);
END CASE;
END PROCESS;
Here select_in is a standard logic vector of length 2, that accepts
input from S3 and S4 switches (hence mapped to pins 44 and 43 of
the CPLD respectively)

State Machine:
The state machine is required to generate the wave-drive
stepping sequence. The state-machine shown below is self-
explanatory.

Figure-6: State-machine to generate the wave-drive stepping


sequence.

The above state-machine can be defined using the HDL code given
below.
PROCESS (temp_clk, reset) PROCESS (state)
BEGIN BEGIN
IF reset = '1' THEN CASE state IS
state <= s0; WHEN s0 =>
ELSIF (temp_clk'EVENT AND temp_clk output <= "0001";
= '1') THEN WHEN s1 =>
CASE state IS output <= "0010";
WHEN s0=> WHEN s2 =>
IF input = '1' THEN output <= "0100";
state <= s1; WHEN s3 =>
ELSE output <= "1000";
state <= s7;
END IF; END CASE;
WHEN s1=> END PROCESS;
IF input = '1' THEN
state <= s2;
ELSE
state <= s0;
END IF;
WHEN s2=>
IF input = '1' THEN
state <= s3;
ELSE
state <= s1;
END IF;
WHEN s3=>
IF input = '1' THEN
state <= s0;
ELSE
state <= s2;
END IF;
END CASE;
END IF;
END PROCESS;
Driving the stepper motor:

The sourcing/sinking capability of the I/O pins of the CPLD is


not good enough to drive the motor. Hence the motor is interfaced
to Krypton through L293D IC. The IC has 4 buffers, enough to
control two motors in 2 directions, or to control 4 motors, all in one
direction. However in our case,we connect the output of all the
buffers to 4 terminals of the coils available and the common terminal
to the ground, for the reasons apparent in the description of
stepper motor excitation given above.The block diagram of the IC is
as shown in Figure-6

Figure-6: Block diagram of the L293D IC.

From Figure-7 we observe that the motor supply(Vcc1),the logic


supply(Vcc2), the enable pins (pin.no 1 and pin.no 9) are shorted
and connected to the 5v supply in the krypton board. The buffers
are therefore permanantly enabled.Here A+,A- are the two terminals
of coil A and B+,B- are the two terminals of coil B. The colours of
the wires in the diagram mentioned above, are indicative of the wires
connected to the terminals of the coil in the stepper motor
provided.The numbers in square brackets are CPLD pin numbers.
Figure 7: L293D pin diagram and connections to the coil of the
stepper motor.

System bring up:

The VHDL code is written,analysed, elaborated and synthesized


using Altera Quartus II IDE and CPLD is programmed with resulting
svf file. The connections from CPLD to the L293D IC and from the
L293D to the motor is made on the breadboard by following the
connection diagram given in Figure-7. The power switch on the board
is turned ON. And volla! The system should be now up and running.

Das könnte Ihnen auch gefallen