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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Control Circuits<br />

Listing 11-5. Controls direction and speed of Figure 11-6’s DC motor.<br />

10 REM A=base address of 82C55<br />

20 A=0FC00H<br />

30 REM configure 8255 for all outputs<br />

40 XBY(A+3)=80H<br />

50 INPUT “Direction (0 or 1)? ”,D<br />

60 IF D=0 THEN XBY(A+3)=0EH ELSE XBY(A+3)=0FH<br />

70 INPUT “Speed (0-15)? ”,S<br />

80 XBY(A)=S<br />

90 REM bring 555’s Reset (PC.6) high (off)<br />

100 XBY(A+3)=0DH<br />

110 XBY(A)=S<br />

120 G=GET<br />

130 DO : G=GET : UNTIL G0<br />

140 REM Remove 555’s Reset<br />

150 XBY(A+3)=0CH<br />

160 END<br />

low pulses will be 10,000 microseconds, or 10 milliseconds, wide. For accurate time<br />

calculations, set XTAL to match your crystal’s frequency.<br />

In Listing 11-4, the number of cycles is 1, so the PWM statement results in one low pulse<br />

followed by one high pulse. Lines 100-110 then use a GET operator to check to see if the<br />

user has pressed a key and if not, the PWM output repeats. Checking for a key press enables<br />

you to stop the program, since BASIC-52 ignores CONTROL+C keypresses while a PWM<br />

statement is executing.<br />

<strong>The</strong> DO loop in the program results in a delay between each PWM statement. During the delay,<br />

P1.2 is high, so the motor is powered. Because of the delay, with a 12-Megahertz crystal, if<br />

L=1200h and H=25, P1.2 will have equal on and off times of about 5 milliseconds. Increasing<br />

L will lower the motor’s speed, and decreasing L or increasing H will raise it.<br />

Although you can control a second motor with the ’2993B, you get only one PWM output<br />

on the 8052-BASIC, so it’s not feasible to control two motors independently in this way.<br />

Figure 11-6 shows another way to control the speed of a DC motor. As in Figure 11-4, the<br />

circuit uses a 4066B quad analog switch to select a timing resistance for a 555 timer. Varying<br />

the timing resistance varies the duty cycle of the 555’s output, and thus the motor’s speed.<br />

You can select timing resistances that result in the motor speeds you want. <strong>The</strong> values shown<br />

will vary the duty cycle from about 90 to 20 percent.<br />

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

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

Saved successfully!

Ooh no, something went wrong!