Está en la página 1de 41

INTERFACING OF ADC, DAC & SENSOR

WITH PIC18F MICROCONTROLLER


Basics of A/D Conversion
Can convert only electrical voltages to
digital values.
A transducer is needed to convert a non-
electric quantity into an electrical voltage.
Different names of transducers are used
for different physical quantities.
A data acquisition system is used to
referred to those systems that perform A/D
conversions.
Characteristics of ADC
Resolution
Conversion time
Vref
Digital data output
Dout = Vin/step size
Parallel VS Serial ADC

8 bit & 16 bit o/p line


Speed is fast

Parallel in serial
out shift register
Speed is slow
The PIC18f A/D Converter

-The PIC18 has a 10-bit A/D


converter.
-The number of analog inputs varies
among difference PIC18 devices.
-The contents of these registers
vary with the PIC18 members.
-Early PIC18 (PIC18FXX2) members
have only ADCON0 and ADCON1
registers.
A/D Registers

-The A/D converter has the following


registers:
A/D Result High Register
(ADRESH)
A/D Result Low Register (ADRESL)
A/D Control Register 0 (ADCON0)
A/D Control Register 1 (ADCON1)
Three control registers are
used to:
Set up the I/O pins for analog signals from ports
A, B, and E that are used as inputs for A/D
conversion.RA5
Select a channel: AN4
Set up pins RA2 and RA3 to connect external
VREF + and VREF - if specified in the control register
ADCON1.
Select an oscillator frequency divider through the
control register ADCON1.
Select an acquisition time through the control
register ADCON2.
A/D Control Register 0
(ADCON0)

Primary function of the


ADCON0 register:
Select a channel for input analog
signal
Start a conversion
Indicate the end of the
conversion
Bit2 is set to start the
conversion, and at the end of
the conversion this bit is reset.
A/D Control Register 1
(ADCON1)

ADCON1 is primarily used to set up


the I/O pins either for analog signal
or for digital signals and select VREF
voltages.
An input to be converted must be an
analog input.
The ADFM bit of the ADCON1 is used
for making it Right-justified or Left-
ADFM bit
Alignment to the left the eight MSB
bits are stored in the ADRESH, and the two
LSB bits are stored in ADRESL. In this case,
the remaining six bits appear as - "0".

Alignment to the right the eight LSB


bits are stored in ADRESL, and two MSB bits
are stored in the ADRESH. In this case six
highest bits appear as - "0".
A/D Acquisition
Requirements
The A/D converter has a sample-and-hold
circuit for analog input.
The sample-and-hold circuit keeps the voltage
stable when it is converted.
The sample-and-hold circuit is shown in Figure.
Automatic Acquisition Time

For earlier PIC18 members, when the


GO/DONE bit is set, sampling is stopped
and conversion begins.
The user is responsible for making sure
enough acquisition time is provided.
For newer PIC18 members, the A/D
module will continue to sample after the
GO/DONE bit is set for the selected
acquisition time.
The automatic acquisition time makes
A/D programming a little easier.
Selecting the A/D Conversion Clock

The per bit A/D conversion time is


defined as TAD.
Each 10-bit A/D conversion takes 12
TAD to complete.
For some devices, the options for TAD
are defined in ADCON0. For others, the
options for TAD are defined in ADCON2.
The length of TAD must be at least 1.6 .
EXAMPLE
Procedure for Performing A/D
Conversion

Configure the A/D module


1. Configure analog pins, reference voltages
2. Select A/D input channel
3. Select A/D acquisition time (if available)
4. Select A/D conversion clock
5. Enable A/D module
Configure A/D interrupt
1. Clear ADIF flag
2. Set ADIE bit (if desired)
3. Set GIE bit (if desired)
Procedure contd..
Wait for the desired acquisition
time (if required)
Start conversion by setting the
GO/DONE bit
Wait for A/D conversion to
complete
Read the A/D result registers;
clear the ADIF flag
For next conversion, go to step 1
or step 2.
Programming PIC18F458
ADC
Programming using
interrupt
Digital to Analog (D/A, DAC, or
D-to-A) Conversion
Converting discrete signals into
discrete analog values that
represent the magnitude of the
input signal compared to a
standard or reference voltage
The output of the DAC is discrete
analog steps.
By increasing the resolution (number
of bits), the step size is reduced, and
the output approximates a
continuous analog signal.
Digital-to-Analog Conversion
2 Basic Approaches
Weighted Summing Amplifier
R-2R Network Approach
Weighted Sum DAC
One way to achieve D/A
conversion is to use a summing
amplifier.
This approach is not satisfactory
for a large number of bits
because it requires too much
precision in the summing
resistors.
This problem is overcome in the
R-2R network DAC.
R-2R Ladder DAC
The summing amplifier with the R-2R
ladder of resistances shown produces
the output where the D's take the value
0 or 1.
The digital inputs could be TTL voltages
which close the switches on a logical 1
and leave it grounded for a logical 0.
This is illustrated for 4 bits, but can be
extended to any number with just the
resistance values R and 2R.
Example
What will be the analog
equivalent of 1001 0001?
DAC0808 interfacing with
PIC18
8 bit DAC, provides 256 discrete
voltage levels.
Converting Iout to Voltage in
DAC0808
In the MC0808 the digital inputs
are converted to current and to
convert it to voltage Iout is
connected to a resistor.
As the resistance affect the
output voltage so current output
is isolated by connecting it to an
op-amp.
Generating a sine wave
To generate a sine wave we first
need a table whose values represent
the magnitude of sine of angle b/w 0
and 360 degrees.
Sin varies from -1 to +1.
This method ensures that only
integer numbers are output to the
DAC by PIC18.
Assume full-scale voltage of 10 V.
Vout = 5V + (5*sinQ)
Vout of DAC for various angles
Program for generating sine
wave

Full scale Vout = 10V


256steps/ 10V = 25.6 steps per volt
Output sine wave
Sensor interfacing
Sensor is a device which detects or
measures a physical property and
records, indicates, or otherwise
responds to it.
Transducer is a device that converts
variations in a physical quantity,
such as pressure or brightness, into
an electrical signal, or vice versa.
We are considering only
temperature sensor.
Temperature Sensor

Transducer that converts temperature into an


analog electrical signal.
Many are available as integrated circuits, and
their outputs (voltage or current) are, in
general, linearly proportional to the
temperature.
However, output voltage ranges of these
transducers may not be ideally suited to
reference voltages of A/D converters.
Therefore, it is necessary to scale the output
of a transducer to range of the reference
voltages of an A/D converter.
Scaling may require amplification or shifting of
voltages at a different level.
Interfacing LM34/LM35 with
PIC18
The sensor of LM34 series are
precision integrated-circuit
temperature sensors.
Output voltage is linearly
proportional to fahrenheit
temperature.
Outputs 10mV for each degree of
fahrenhiet temperature.
In LM35 output voltage is linearly
proportional to celsius
LM34 sensors

LM35 sensors
Interfacing LM35 with PIC18
Temperature calculations
A/D converter has 10-bit resolution
For temperature range 0F to +300F, the digital
output should be divided into 1024 steps (0 to
3FFH).
Therefore, the digital value per degrees
Fahrenheit is 10.24 (1024/100 = 10.2410).
This 10.24 V is exceeding the permissible max.
value i.e 3V.
If step size is taken 2.5 mV then max Vout will
be 2.56 V.
Final value is calculated by dividing output by 4.
Interfacing LM35 with PIC18

LM35 is
connected to
channel
0(RA0 pin).
The channel
AN3(RA3
pin) is
connected to
the Vref of
2.56 V.
Program for reading and displaying
temperature

También podría gustarte