EXPERIMENT 9: Interfacing ADC With Sensors: Objectives
EXPERIMENT 9: Interfacing ADC With Sensors: Objectives
Objectives
To interface ADC module of PIC microcontroller with Sensors.
Components
Software: MPLAB X IDE (latest version)
Software: XC8 C Compiler (latest version)
IC type: PIC16F877A microcontroller
LEDs: Red
Crystal: 8MHz
Capacitors: 22pF
Resistors: 470Ω ±5%
Potentiometer: 10KΩ
Light Sensor: GL5528
Introduction
Every physical quantity found in nature like temperature, humidity, pressure, force is
analog. These analog quantities need to be converted to digital to process it using a digital
computer or a microcontroller. This is done by using Analog to Digital Converters. An Analog
to Digital Converter or ADC is a device which converts continuous analog quantity (here:
voltage) to corresponding discrete digital values.
PIC 16F877A microcontroller has eight ADC inputs and it will convert analog inputs to a
corresponding 10-bit digital number. For example, assuming the ADC Lower Reference is 0V
and Higher Reference is 5V.
𝑉𝑟𝑒𝑓− = 0𝑉
𝑉𝑟𝑒𝑓+ = 5𝑉
𝑛 = 10 𝑏𝑖𝑡𝑠
(𝑉𝑟𝑒𝑓+ − 𝑉𝑟𝑒𝑓− ) 5
𝑅𝑒𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛 = 𝑛
= = 0.0048876𝑉 = 4.8876𝑚𝑉
2 −1 1023
Therefore, ADC resolution is 4.8876mV, which is the minimum required voltage to change a
bit.
Table 9-1.
Digital Output
Analog Input
Binary Hexadecimal Decimal
0.000000V 0b0000000000 0x000 0
0.004887V 0b0000000001 0x001 1
0.009774V 0b0000000010 0x002 2
0.014661V 0b0000000011 0x003 3
4.999401V 0b1111111111 0x3FF 1023
Questions
1. List the registers used in the ADC module of PIC16F877A microcontroller.
2. What is the minimum required acquisition time?
3. Provide the comment for Line 1 to Line 8.
4. What is the purpose of Line 16 and Line 17?
5. Explain the function of unsigned int ADC_Read(unsigned char channel) from
Line 20 to Line 31.
6. Describe how the 10-bit data is being stored and processed.