Transcript analog_03

The 68HC11 Microcontroller
Chapter 11: 68HC11 Analog to Digital Converter
The 68HC11 Microcontroller
Han-Way Huang
Minnesota State University, Mankato
H. Huang Transparency No.11-1
The 68HC11 Microcontroller
Basics on A/D Conversion
- Almost any measurable quantity, for example, current, voltage, temperature, speed, and
time, is analog in nature.
- Analog signals must be represented in digital format in order to be processed by the digital
computer.
- An analog to digital (A/D) converter can convert a electrical voltage to a digital value.
- A non-electrical quantity must be converted into electrical voltage before it can be
converted into digital value.
- A transducer is normally used to convert a non-electrical quantity into a electrical voltage
so that it can be further processed by a computer.
- The accuracy of an A/D converter is dictated by the number of bits it used to represent the
digital value.
-An A/D conversion system is illustrated in Figure 11.1
H. Huang Transparency No.11-2
The 68HC11 Microcontroller
Nonelectric quantity
such as
temperature
pressure
light
weight
airflow
humidity
.
.
.
Transducer
Such as a
sensor,
load cell,
photocall, or
thermocouple
.
.
.
voltage
signal
conditioning
circuit
voltage
A/D
converter
Digital
value
Computer
(optional)
Figure 11.1 The A/D conversion process
H. Huang Transparency No.11-3
The 68HC11 Microcontroller
Optimal Voltage Range for the A/D Converter
- A/D converter needs a low reference voltage and a high reference voltage to operate.
- The low reference voltage (VLREF) is often set to 0 and the
high reference voltage (VHREF) is often set to VCC.
- Most A/D converters are ratiometric.
- To take advantage the whole dynamic range of the A/D converter, we should set scale and
shift the sensor output to VLREF ~ VHREF.
- The A/D conversion result x corresponds to an analog voltage given by
Vx = VLREF + (range  x)  (2n – 1)
where, range = VHREF – VLREF
H. Huang Transparency No.11-4
The 68HC11 Microcontroller
Example 11.1 Assume there is a 12-bit A/D converter with VLREF = 0V and VHREF = 5V.
Find out the corresponding voltage values for A/D conversion results of 100, 400, 800,
1200, and 2400.
Solution:
range = VHREF – VLREF = 5 V.
V(100) = 0V + (100  5)  (212 – 1) = 0.12 V
V(400) = 0V + (400  5)  (212 – 1) = 0.49 V
V(800) = 0V + (800  5)  (212 – 1) = 0.98 V
V(1200) = 0V + (1200  5)  (212 – 1) = 1.46 V
V(2400) = 0V + (2400  5)  (212 – 1) = 2.93 V
H. Huang Transparency No.11-5
The 68HC11 Microcontroller
An Overview of the 68HC11 A/D Converter
-
-
Eight-channel, 8-bit, multiplexed input, successive-approximation conversion method.
A weighted array of capacitors are used to implement the successive-approximation
method.
A clock signal is required to control the A/D conversion that must have a frequency
no lower than 750 KHz.
Reference voltages are required for the conversion: one is high reference (VRH) voltage,
the other is low reference (VRL) voltage. The difference between VRH and VRL cannot be
lower than 2.5 V.
Accuracy is only guaranteed for VRL = 0 V and VRH = 5 V.
The conversion is ratiometric. The input voltage VRL converts to $00 and the input voltage
VRH converts to $FF.
H. Huang Transparency No.11-6
The 68HC11 Microcontroller
The Clock Frequency Issue
-
The A/D converter requires a clock to operate.
Either the E clock or the on-chip RC clock signal can be used.
The RC clock runs at 1.5 MHz.
To choose the E clock signal, clear the bit 6 of the OPTION register to 0.
To select RC clock signal, set the bit 6 of the OPTION register to 1. This circuit requires
10 ms to start and settle.
- The 68HC11 completes the conversion of one sample in 32 clock cycles.
Registers Related to the A/D Operation
- ADCTL:
- OPTION:
- ADR1-4:
A/D control/status register
bits 7 and 6
A/D result registers 1 to 4
H. Huang Transparency No.11-7
The 68HC11 Microcontroller
A/D Control Register (ADCTL)
Value after
reset
7
6
CCF
0
0
0
5
4
SCAN MULT
u
u
3
2
1
0
CD
CC
CB
CA
u
u
u
u
ADCTL
at $1030
CCF : Conversion complete flag. This read-only flag is set when all four
A/D result registers contain valid conversion results. Each time the
ADCTL register is written, this bit is automatically cleared to 0 and a
conversion sequence is started.
SCAN: Continuous scan control. When this bit is 0, the four requested
conversions are performed once to fill the four result registers. When this
bit is 1, conversions continue in a round-robin fashion with the result
registers being updated as data becomes available.
MULT : Multiple-channel/single-channel control. When this bit is 0, the
A/D system performs four consecutive conversions on the single channel
specified by the four channel select bits (CD through CA, bits 3-0 of the
ADCTL register). When this bit is 1, the A/D system is configured to
perform a conversion on each of four channels, with each result register
corresponding to one channel.
CD: Channel select D.
CC: Channel select C.
CB: Channel select B.
CA: Channel select A.
These four bits are used to select one of the sixteen A/D channels. When
a multiple-channel mode is selected, the two least significant bits (CB and
CA) have no meaning, and the CD and CC bits specify which group of
four channels is to be converted. The channels selected by the four
channel select bits are shown in Table 11.1.
H. Huang Transparency No.11-8
The 68HC11 Microcontroller
CD
CC
CB
CA
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
Channel
signal
AN0
AN1
AN2
AN3
AN4*
AN5*
AN6*
AN7*
reserved
reserved
reserved
reserved
VRHpin**
VRLpin**
(V RH)/2**
reserved**
Result in ADRx
if MULT = 1
ADR1
ADR2
ADR3
ADR4
ADR1
ADR2
ADR3
ADR4
ADR1
ADR2
ADR3
ADR4
ADR1
ADR2
ADR3
ADR4
* Not avaliable in 48-pin package.
** These channels are intended for factory testinig.
Table 11.1 Analog-to-digital channel assignments
H. Huang Transparency No.11-9
The 68HC11 Microcontroller
The OPTION Register
Value after
reset
ADPU
CSEL
IREQ
DLY
CME
0
CR1
CR2
0
0
0
1
0
0
0
0
OPTION
at $1039
ADPU: A/D power up. When set to 1, it enables the A/D converter. After setting this bit,
the user must wait at least 100 ms before using the A/D converter.
CSEL: clock select. When set to 1, the RC clock signal is selected. Otherwise, the E
clock is selected. It takes 10 ms for RC clock to stabilize.
H. Huang Transparency No.11-10
The 68HC11 Microcontroller
The Procedure for Using the A/D Converter
Step 1. Connect the hardware properly. Scale and shift the analog inputs, when necessary,
so that they fall between VRH and VRL.
Step 2. Set the ADPU bit of OPTION register to enable the A/D converter.
Step 3. Select the appropriate clock signal by setting or clearing the CSEL bit of the
OPTION register.
Step 4. Wait for the A/D converter to stabilize.
Step 5. Select the appropriate channel(s) and operation modes by programming the ADCTL
register.
Step 6. Wait until the CCF flag of the ADCTL register becomes 1 and collect the conversion
results.
H. Huang Transparency No.11-11
The 68HC11 Microcontroller
Example 11.5 Write an instruction sequence to set up the following A/D conversion
parameters:
Nonscan mode
Single-channel mode
Select channel AN0
Choose the E clock as the clock source for the A/D converter
Enable A/D converter
Solution:
Set bit 5 of ADCTL to 0 to select nonscan mode.
Set bit 4 of ADCTL to 0 to select single-channel mode.
Set bits 3-0 of ADCTL to 0000 to select channel AN0.
Write the value $00 into the ADCTL register.
Set the bit 7 of the OPTION register to enable A/D charge pump.
Clear the bit 6 of the OPTION register to select E clock as the A/D control clock signal.
Wait for 100 ms for the converter to stabilize.
H. Huang Transparency No.11-12