Lab 6
Lab 6
- 10-bit Resolution: The ADC can convert an analog signal into a 10-bit digital value, providing 1024
discrete levels.
- Multiple Channels: The ADC has multiple input channels (8 channels in PIC18F452) allowing you to
interface several analog sensors simultaneously.
- Selectable Voltage Reference: The module allows the selection of different voltage references for
accurate ADC conversions.
- Programmable Acquisition Time: The ADC module can be programmed to allow a specific
acquisition time for the analog input signal before conversion begins.
- Interrupt Capability: The ADC module can generate an interrupt after completing an analog-to-digital
conversion, allowing the microcontroller to perform other tasks while waiting for the ADC result.
HOW ADC WORKS IN PIC18F452
• The ADC in PIC18F452 operates by sampling the input analog signal and converting it into a 10-bit
digital value. The conversion process involves several steps:
• 1. Sampling: The analog signal is sampled at the input channel, and the sample is held on an internal
capacitor.
• 2. Conversion: The sampled voltage is converted into a 10-bit digital value using a successive
approximation register (SAR).
• 3. Result: The digital result is stored in two 8-bit registers (ADRESH and ADRESL) which can be read by
the user.
PIC18F452/458 ADC REGISTERS
• The A/D module has four registers. These registers are:
• To use the ADC module in PIC18F452, several registers must be configured. The key registers involved are:
1. ADCON0: This register controls the ADC module, including the selection of the input channel, starting the
conversion, and checking the conversion status.
– ADON: ADC Enable bit. Set to 1 to enable the ADC module.
– GO/DONE: ADC conversion status bit. Set to 1 to start the conversion, and it is cleared automatically when the
conversion is complete.
– CHS3:CHS0: Selects the analog input channel.
CONFIGURING THE ADC IN PIC18F452
A/D RESULT REGISTERS
• The ADRESH:ADRESL register pair is the location where the 10-bit A/D result
is loaded at the completion of the A/D conversion.
CONFIGURING THE ADC IN PIC18F452
1. ADCON1: This register configures the voltage reference and analog/digital configuration of the pins.
– PCFG3:PCFG0: Configures the analog and digital functionality of PORTA and other pins.
– VCFG1:VCFG0: Selects the voltage reference sources.
– ADFM: A/D Result Format Select bit
– 1 = Right justified. Six (6) Most Significant bits of ADRESH are read as ’0’.
– 0 = Left justified. Six (6) Least Significant bits of ADRESL are read as ’0’.
• Hardware Setup
• Connect one end of the potentiometer to 5V, the other end to GND.
• Connect the middle terminal (wiper) to (AN5) of the PIC18.
EXAMPLE: TEMPERATURE MEASUREMENT
USING LM35
• Let’s implement a simple example where we read the value of
a LM35 temperature sensor connected to the AN6 pin and
display it via LCD
• Hardware Setup (Continued)
• Connections:
– VCC of the LM35 to the 5V pin of the PIC18.
– GND of the LM35 to the GND pin of the PIC18.
– The output pin of the LM35 to the AN6 of the PIC18.
• The LM35 outputs an analog voltage that is linearly proportional to the temperature. The
output is typically 10 mV/°C, meaning that at 25°C, the output voltage will be 250 mV.
EXAMPLE: LIGHT LEVEL MEASUREMENT USING
LDR
• Now, let s look at an example where we measure ambient light levels using an LDR
(Light Dependent Resistor) and the ADC.
• Hardware Setup
• Connections:
– One end of the LDR is connected to 5V.
– The other end is connected to AN7of the PIC18 and, through a pull-down
resistor (e.g., 10 kΩ), to GND.
• This forms a voltage divider where the voltage at the ADC pin changes with the
light level. As the light intensity increases, the resistance of the LDR decreases,
resulting in a higher voltage at the ADC pin.