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.

Using Sensors to Detect and Measure<br />

Listing 9-4. Measures and displays solar energy detected by solar-cell<br />

circuits at Channel 8 of ADC0848.<br />

10 REM set A to address of ADC<br />

20 A=0C000H<br />

30 REM set C to channel to read (1-8)<br />

40 C=8<br />

50 REM use single-ended mode, select channel, start convert<br />

60 XBY(A)=8+C-1<br />

70 REM FS=full-scale voltage (5V)/full-sun output (4.75V)<br />

80 FS=1.05<br />

90 B=XBY(A)<br />

100 T=INT(FS*B*100/255+.5)<br />

110 PRINT “Solar energy = ”,T," percent of full sun"<br />

120 PRINT “press any key to take another measurement”<br />

130 D=GET : IF D=0 THEN GOTO 130<br />

140 GOTO 60<br />

150 END<br />

Level Translating<br />

As you can see, not every sensor has an output that can connect directly to the ADC0848’s<br />

inputs. A sensor’s output may vary from -2 to -1V, from -0.5 to +0.5V, or from -12 to +12V.<br />

In all of these cases, you need to shift the signal levels and sometimes adjust the signal range<br />

to be compatible with a converter that requires inputs between 0 and 5 volts.<br />

Figure 9-9 shows a general-purpose circuit that can amplify or reduce input levels, and can<br />

also raise or lower the entire signal by adding or subtracting a voltage. Separate, independent<br />

adjustments control the gain and offset. <strong>The</strong> circuit is a series of three op amps: a buffer, a<br />

level shifter, and an amplifier. <strong>The</strong> example circuit uses three of the devices in an LF347<br />

quad JFET-input op amp. <strong>The</strong> LF347 has fast response and high input impedance. You may<br />

use a different op amp if you prefer.<br />

<strong>The</strong> first op amp is a noninverting amplifier whose output at pin 1 equals VIN. <strong>The</strong> op amp<br />

presents a high-impedance input to VIN, to minimize loading effects.<br />

<strong>The</strong> second op amp is an inverting summing amplifier that shifts pin 1’s voltage up or down<br />

as R5 is adjusted. Adjusting R5 raises and lowers the voltage at pin 7, but the signal’s shape<br />

and peak-to-peak amplitude remain constant.<br />

<strong>The</strong> third op amp is an inverting amplifier whose gain is adjusted by R4. This amplifier<br />

increases or decreases the peak-to-peak amplitude of its input.<br />

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

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

Saved successfully!

Ooh no, something went wrong!