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.

Control Circuits<br />

Listing 11-4. Controls direction and speed of a DC motor with BASIC-52’s<br />

PWM output.<br />

10 PORT1=0FBH<br />

20 T=1<br />

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

40 INPUT “High (on) pulse width (25 to 0FFFFh)? ”,H<br />

50 INPUT “Low (off time) pulse width (25 to 0FFFFh)? ”,L<br />

60 IF D=0 THEN PORT1=PORT1.AND.0FEH ELSE PORT1=PORT1.OR.1<br />

70 PRINT “Press any key to end program”<br />

80 DO<br />

90 PWM H,L,T<br />

100 G=GET<br />

110 UNTIL G0<br />

120 PORT1=PORT1.AND.0FBH<br />

130 END<br />

You can stop the motor in any of three ways. You can bring bits 0-3 of the port low to stop<br />

the timer. You can bring bit 7 high, which removes power from U4’s outputs. Or, you can<br />

bring pins 9 and 10 of U5 high, which continues to apply power to the motor, but ignores<br />

the step input.<br />

Listing 11-3 prompts you for a motor speed, mode of operation, and direction, and then runs<br />

the motor as requested. You can stop the program, and the motor will continue to run, as<br />

long as it remains connected to the port and you don’t write anything else to it.<br />

Speed Control of a Continuous DC Motor<br />

If you prefer ordinary continuous dc motors to steppers, Figure 11-5 shows a circuit that<br />

uses BASIC-52’s PWM output to control motor speed.<br />

This circuit uses another Allegro chip, the UDN2993B (U1). Pins 1 and 8 of U1 connect to<br />

the motor’s power supply, which can range from 10 to 40V. Pins 6 and 7 connect to the<br />

motor. Pin 5 is the +5V logic supply, and pins 4, 5, 12, and 13 are additional grounds. At<br />

pins 10, 11, 14, and 15, you can connect and control a second motor.<br />

Pin 3 of U1 controls motor direction, and connects to bit 0 of Port 1 (P1.0) on the<br />

8052-BASIC. Pin 2 of U1 switches power to the motor, with a logic low shutting the motor<br />

off, and a logic high allowing current to flow. This pin connects to Port1, bit 2 (P1.2) of the<br />

8052-BASIC, which is the PWM output.<br />

BASIC-52’s PWM expression causes a series of pulses to appear at P1.2, with this syntax:<br />

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

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

Saved successfully!

Ooh no, something went wrong!