You are on page 1of 36

ANALOG DIGITAL CONVERTER

CHAPTER 4

1
At the end of the class, you will be able:

to understand the function of ADC.

to describe the ADC system.

to understand the application of ADC.

2
ADC Module of PIC16F877A
• The A/D converter module has the following features:
• The converter generates a 10-bit binary result using the method of successive approximation
and stores the conversion results into the ADC registers (ADRESL and ADRESH);
• There are 8 analog inputs channel;
• The A/D converter converts an analog input signal into a 10-bit binary number;
• The minimum resolution or quality of conversion may be adjusted to various needs by
selecting voltage references Vref- and Vref+

3
ADC Module of PIC16F877A
• ADC block diagram as shown below.
AN0 – AN7
analog input
pin

Reference Voltage
Scheme

4
ADC Module (How to use?)
• In order to enable the A/D converter to run without problems as well as to avoid
unexpected results, it is necessary to consider the following:
• A/D converter does not differ between digital and analog signals. Pins should
be configured as analog inputs before the process of conversion starts.
• Bits used for this purpose are stored in the TRIS and ANSEL (ANSELH)
registers;
• When reading the port with analog inputs, the state of the corresponding bits
will be read as a logic zero (0)

5
ADC Module (How to use?)
 Voltage measurement in the converter is based on comparing input voltage with
internal scale which has 1024 marks (210 = 1024).
 The lowest scale mark stands for the Vref- voltage while highest mark stands for the
Vref+ voltage. Figure below shows selectable voltage references as well as their
minimum and maximum values.

6
Analog Digital Converter
• The A/D module has four registers. These registers are:
• A/D Result High Register (ADRESH)
• A/D Result Low Register (ADRESL)
• A/D Control Register 0 (ADCON0)
• A/D Control Register 1 (ADCON1)

7
ADRESH/ADRESL Register
• The result obtained after converting an analog value into digital is a10-bit number that is to be
stored in the ADRESH and ADRESL registers.
• There are two ways of handling it:
• left and right justification which simplifies its use to a great extent. The format of conversion result depends
on the ADFM bit of the ADCON1 register.
• In the event that the A/D converter is not used, these registers may be used as general-purpose registers.

8
ADCON0 Register

A/D Conversion Clock Select bits select clock frequency used for internal synchronization of A/D
converter. It also affects duration of conversion.

9
ADCON0 Register

Analog Channel Select bits select a pin or an analog channel for A/D conversion, i.e. voltage
measurement:

10
ADCON0 Register

ADON - A/D On bit enables A/D converter.

11
ADCON1 Register
• For PIC16F877A, ADCON1register only have 6 functional bits:
• Bit 0 – Bit 3 (A/D Port Configuration Control bits)
• Bit 6(A/D Conversion Clock Select bit (ADCON1 bits in shaded area and in
bold)
• Bit 7- A/D Result Format Select bit

12
ADCON1 Register
 Bit 0 – Bit 3 (A/D Port Configuration Control bits)

How to determine bit 0


to bit 3 logic?

13
ADCON1 Register
 Bit 6(A/D Conversion Clock Select bit (ADCON1 bits in shaded area and in bold)

ADCS2 bit work closely with


ADCS1:ADCS0 bits (ADCON0)
in order to select clock
frequency used for internal
synchronization of A/D
converter

14
ADCON1 Register
 Bit 7- A/D Result Format Select bit
 This bit determine the format of conversion (ADRESH or ADRESL)

15
A/D Conversion Clock
• The A/D conversion time per bit is defined as TAD. The A/D conversion
requires a minimum 12TAD per 10-bit conversion. The source of the A/D
conversion clock is software selected. The seven possible options for TAD
are:
• 2 TOSC
• 4 TOSC
• 8 TOSC
• 16 TOSC
• 32 TOSC
• 64 TOSC
• Internal A/D module RC oscillator (2-6 us)
• For correct A/D conversions, the A/D conversion clock (TAD) must be
selected to ensure a minimum TAD time of 1.6 us.

16
Analog Comparator
• In addition to A/D converter, there is another module, which so called analog electronics.
• Two high quality comparators, along with additional electronics, are integrated into the
microcontroller and connected to its pins.

The comparator module contains two analog


comparators.

The inputs to the comparators are multiplexed


with I/O port pins RA0 through RA3, while the
outputs are multiplexed to pins RA4 and RA5

17
Analog Comparator Module
• Analog Comparator module with:
• Two analog comparators
• Programmable on-chip voltage reference (VREF) module
• Programmable input multiplexing from device inputs and internal voltage
reference
• Comparator outputs are externally accessible

18
Analog Comparator Register
• The CMCON register controls the comparator input and output multiplexers. A
block diagram of the various comparator configurations is shown in datasheet

Comparator output bit


Comparator mode bits
Comparator output
inversion bit

Comparator input
switch bit

19
Analog Comparator Configuration
• Refer to PIC16F87XA datasheet, there are 8 possible ways to configure analog comparator module
which is <CM2:CM0>:
• Comparators Reset <000>
• One Independent Comparator with Output<001>
• Two Independent Comparators<010>
• Two Independent Comparators with Outputs<011>
• Two Common Reference Comparators<100>
• Two Common Reference Comparators with Outputs<101>
• Four Inputs Multiplexed to Two Comparators<110>
• Comparators Off (POR Default Value)<111>

20
Analog Comparator
• How comparator works?
• The analog comparator is an amplifier which compares the magnitude of voltages at two
inputs. It has two inputs and one output. Depending on which input has a higher voltage
(analog value), a logic zero (0) or logic one (1) (digital values) will appear on its output:
• When the analog voltage at Vin- is higher than that at Vin+, the output of the
comparator is a digital low level.
• When the analog voltage at Vin+ is higher than that at Vin-, the output of the
comparator is a digital high level

21
ADC Device(Interfacing with real world)

• A sensor (such as transducer) is a device that converts one form of


energy to another

Source(i.e. sensor) Converter (ADC or DAC or Processing Method(i.e. MCU)


comparator)
22
Converting Analog to Digital

23
Converting Analog to Digital

1 Bit ADC 2 Bit ADC

3 Bit ADC

24
Converting Analog to Digital
• Example: IR Sensors
• IR LED emits infrared radiation
• Depending on reflectivity of the surface, amount of light reflected varies.
• As intensity of incident rays varies, voltage across resistor will vary
accordingly.

25
Resolution
• The resolution of a n-bit analog-to-digital Converter (ADC) is a function of how many parts the
maximum signal can be divided into.
• The resolution determines the magnitude of the quantization error and therefore determines the
maximum possible average signal to noise ratio for an ideal ADC without the use of oversampling.
• The values are usually stored electronically in binary form, so the resolution is usually expressed
in bits

Step = 2n
26
Resolution

• Vref: Input voltage for the reference voltage

27
Resolution
• The resolution Q of the ADC is equal to the Least Significant Bit (LSB) voltage. The voltage
resolution of an ADC is equal to its overall voltage measurement range divided by the number of
discrete values
• Let say, for 8-bit ADC with,
• VREF+ = 1 – 5 V
• VREF- = 0 V

28
Resolution

Another way to think of resolution is by considering your television screen. The


higher the resolution of the screen, the more pixels you have to show the picture,
so you get a better picture.
29
Digital Data Output
• In an 8-bit ADC, we have the digital data output: D0 – D7
• In an 10-bit ADC, we have the digital data output: D0 – D9

30
Digital Data Output
• For an 8-bit ADC, and VREF = 2.56 V. Calculate the D0– D7 output if analog input is:
• 1.7 V
• Solution?
• Step size = 2.56/256= 10mV, so Do = 1.7/10 mV = 170 in decimal
• Which give us 10101010 in binary for D7-D0
• 2.1 V
• Solution?
• Exercise!!!

31
Sensor Interfacing
• Sensor convert physical data to electric signal.
• Depending on the sensor, the output can be in the form of voltage, current,
resistance, or capacitance.
• These relationship can either be linear or nonlinear.

32
Signal Conditioning
• To convert sensors output to voltage for ADC
• Signal conditioning can either be current-to voltage converter or signal
amplification

33
Application of ADC (IR Sensor)
LINE FOLLOWING SENSOR
• IR LED emits infrared radiation
• Depending on reflectivity of the surface, amount of light reflected varies.
• As intensity of incident rays varies, voltage across resistor will vary accordingly.

34
Exercise
PIC16F877A analog digital converter (ADC) module has four register which is ADRESH, ADRESL, ADCON0 and
ADCON1. The value of register ADCON0 and ADCON1 as shown below.
ADC Register Value
ADCON0 100001x1
ADCON1 11xx1110

 The resolution in 10 bit ADC and what does 1 bit in 10 bit ADC mean?
• Calculate the digital data output if the Vin equal to 2.5V.
• If the PIC16F877A connected to 20MHz oscillator, calculate the conversion time.
• Find the new value of ADCON0 and ADCON1 register for the following option; 6 channel analog input, Vref+
and Vref- equal to VDD and VSS, clock conversion is FOSC/32, A/D result is left justified and A/D module is
turn ON.

35
THANK YOU
36

You might also like