18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11<br />

Listing 11-3. Controls a stepper motor.<br />

10 REM A=address of output port<br />

20 A=0E400H<br />

30 DO<br />

40 INPUT “Speed (1-15)? ”,S<br />

50 INPUT “Mode (1=wave, 2=2-phase, 3=1/2-step, 4=stop)?”,M<br />

60 INPUT “Direction (0=Clockwise, 1=Counterclockwise)? ”,D<br />

70 IF M=1 THEN X=4<br />

80 IF M=2 THEN X=0<br />

90 IF M=3 THEN X=2<br />

100 IF M=4 THEN X=6<br />

110 XBY(A)=S+(X+D)*10H<br />

120 WHILE 1=1<br />

130 END<br />

powering one and two phases. Wave drive uses the least power, but with reduced torque<br />

compared to 2-phase drive. Half-step drive uses twice as many steps per revolution, and so<br />

offers finer control.<br />

Bit 4 (pin 12 of U2) sets the direction of rotation.<br />

Figure 11-5. Using a UDN2993 to control a DC motor with pulse-width<br />

modulation.<br />

194 <strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!