Chapter 8 Data Acquisition and Distribution
Chapter 8 Data Acquisition and Distribution
1
OVERVIEW OF ANALOG VARIABLES
Most of real variables come to microcontroller s are analog in nature. They
are continuously variable and can take an infinite range of different values,
whether we are talking about temperature, sound level, frequency or other
variables.
It is necessary, therefore, for the microcontroller to be able to read values
that are analog and if necessary generate output values that are analog, even
though internally the microcontroller is relentlessly a digital device.
The process of converting an analog signal to digital, along with all the
attendant signal manipulation, is usually called ‘data acquisition’.
Once data from the outside world has been acquired, it needs to be processed
and put to use. It may also need to be averaged, scaled, linearised or stored.
Quite possibly it will be used for some form of control purpose and it may
need to be displayed, or transmitted to another device.
2
PROPERTIES OF ANALOG AND DIGITAL QUANTITIES
3
A Data Acquisition System
When converting an analog signal to digital form, it is usually not enough just to find a suitable ADC
(Analog to Digital Converter). Usually, more than one input is required and the signal needs
processing before it can be converted. In most cases, therefore, it is necessary to build up a complete
data acquisition system. The elements of such a system are shown below. This shows, in block
diagram form, a system with multiple inputs, amplification, filtering, source selection, sample and
hold, and finally the ADC itself. The different elements are outlined in the sections which follow.
Filter Multiplexer
Removes unwanted Selects which ADC
signal components, input channel is Converts its
Transducer usually for anti- connected to its Analog Input to a Voltage
Generates signal aliasing purposes output
Sample & Hold Digital Output Reference
Samples its input
signal, and holds
that voltage as a
steady value at its
output
Sample Digital
Output
The acquisition time, i.e. the time for the hold capacitor to charge to acceptable final value, called tac, is given by:
tac = Amplifier Settling Time + Hold Capacitor Charging Time + Temperature Coefficient
= 2 us (can be ignored sometimes) + 7.6 RC (for 10-bit ADC, 2.3RC is for 8-bit ADC) + Temperature Coefficient(ignored)
= 2 us + 7.6 (RSS + RIC + RS) 120 pF
*Acquisition time increases with increasing resistance, capacitance and with accuracy required.
Overall time needed to complete a single conversion = tac + conversion time of 19.2 us + 2 TAD delay after complete conv.
= sampling rate in term of frequency (approximation)
The Amplifier settling time is specified as 2ms. The Temperature Coefficient applies only when temperatures is above6 25 oC,
and is specified as:
Temperature Coefficient = (Temperature - 25oC)(0.05ms/ oC)
It can be seen that this creates a time delay of only 0.5ms for every 10oC above 25o, so its impact in most cases is slight.
Integrating an ADC onto the Microcontroller
It is now possible to integrate much of a data acquisition system onto a single chip, and/or
into a microcontroller. But note - ADCs don’t easily integrate onto microcontrollers,
mainly because there is the risk of massive digital interference, both radiated, and through
shared earth and supply lines.
A partial solution is to separate the ADC earth and supply from that of the microcontroller,
and to minimise interference during conversion - by synchronising conversion to internal
clock transitions, and minimising all other switching at this time.
Ultimately, you will only find ADCs of limited resolution (generally 8- or 10-bit)
integrated onto a microcontroller.
7
The Analog to Digital Converter (ADC) characteristics
- The ADC accepts an input voltage (within the valid input range of ADC) that is infinitely variable, and converts
this to one of a fixed number of output values. The input range is set by high and low voltage references.
- An example ADC conversion characteristic is shown, where the input voltage is represented on the horizontal
axis, and digital output on the vertical.
- The term quantization refers to subdividing a range into small but measurable increments.
- For an n-bit ADC, the maximum output value will be (2 n – 1). For example, for an 8-bit ADC, the maximum value
will be (28 – 1), or (256 – 1), i.e. 255 decimal or 11111111 binary.
Digital
Output
(2n - 1)
(2n - 2)
100
011
010
...001
0
0 Vmax Analogue 8
Input
Input Range
Operation of Successive Approximation analog-to-digital converter (SAR ADC)
The successive approximation converter performs a conversion on one bit at a time, beginning with the most
significant bit (MSB) and ending with the least significant bit (LSB) as shown in figure below.
The value of the most significant bit is determined by whether the input signal is in the upper or lower half of the
valid input range. The next most significant bit is determined by whether the input is in the upper or lower half of
the remaining range, and so on, until the least significant bit is determined.
The most significant bit will be converted as a 1, because the input is in the upper half of the range. The next bit
would be converted as a 0, because the test range for this bit is between 1/2 and 1, and the input is less than 3/4,
which is the mid-point of the test range. The next bit is also converted as a 0, because the test range is between 1/2
and ¾ and the input is below 5/8 which places it in the lower half of the test range. The following bit will be
converted as a 1 because it is above 9/16 placing it in the upper half of the test range.
This process is repeated until all the bits are determined. Each bit requires one analog-to-digital converter clock
period for conversion.
9
The 16F873A ADC
The 16F873A has a versatile 10-bit ADC module, shown below. This provides a subset of the overall data acquisition
system. The particular ADC design used incorporates the function of Sample and Hold. The input multiplexer, seen to
the right, has 5 channels for the 16F873A or 8 channels for the 16F874A. The inputs are shared with five of the six
Port A bits. Port A bit four is not used, as it already shares with the Timer 0 input. Port bits can be allocated in a
flexible way to analog or digital input.
External input for
Input select voltage reference
bits
Input
Multiplexer
An external voltage reference
can be used for applications
requiring reasonable
accuracy. Provision of the
negative connection means
that the reference does not
have to be referred to system
ground, or it can at least be
connected to a “clean”
ground. For lower cost, lower
accuracy conversions, the
power supply voltage can be
used as reference. The input
10
range is equal to whatever
voltage reference is chosen.
The ADCON0
Register
The ADC is controlled by
two SFRs, ADCON0 and
ADCON1. The result of the
conversion is placed in two
further SFRs, ADRESH and
ADRESL. These four
registers can all be seen in
the SFR Memory Map. Any
bits used for analog input
must also be set as inputs in
TRISA.
11
The ADCON1
Register
12
The ADC Conversion Clock
Operation of the ADC is governed by the ADC clock, which has a period TAD. TAD is defined as
A/D conversion time per bit. Afull 10-bit conversion takes around 12 TAD cycles, depending
slightly on which clock source is chosen. The user can select the clock frequency from a number
of options. Although one generally wants a conversion to take place as quickly as possible, there
is an upper limit to the clock frequency. For the 16F87XA the minimum clock period for correct
operation is specified as a period of 1.6ms, or a frequency of 625 kHz (from data sheet). This
implies a fastest conversion time of 19.2 us.
A slow ADC, with a high conversion time, will only be able to convert low-frequency signals
At the other extreme, if conversion is too slow, charge leaks from the storage capacitance, and
the conversion becomes inaccurate. Best practice is therefore to set the ADC clock frequency
such that it has a period equal to or just more than 1.6ms.
Selection of the ADC clock source is controlled by bits ADCS2 in ADCON1, and ADCS1 and
ADCS0 in ADCON0. The RC oscillator has a typical period of 4ms, but may range from 2 to
6ms.
If the system clock is fast, it is usually appropriate to use it to derive the clock source. If the
system clock is slow however, it is better to use the RC oscillator.
13
Completion of conversion may therefore be detected by testing either of the bits GO=DONE or
ADIF
14
Typical Timing Requirement of one A to D Conversion
Read Data
Step 1: Configure i/o pins
banksel TRISA ; assembler directive to select bank
movlw b’11111111’
movwf TRISA ; set all PORTA pins as inputs
18