0% found this document useful (0 votes)
1 views15 pages

Lab 6

Lab 6

Uploaded by

alhoripy5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
1 views15 pages

Lab 6

Lab 6

Uploaded by

alhoripy5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 15

LAB 6 ANALOG TO DIGITAL

CONVERTER (ADC) WITH PIC18F452


BY: ENG. MOHAMMED ABDALNASSER ALZAGHIR
771311599
INTRODUCTION TO ADC IN PIC18F452
• Analog-to-Digital Converters (ADCs) are critical components in embedded systems for interfacing analog sensors with
digital controllers. The PIC18F452 microcontroller, a popular choice among engineers, includes a 10-bit ADC module
that can convert analog signals into corresponding digital values. This ADC module is essential for applications
involving sensors that provide analog outputs, such as temperature sensors, light sensors, or any device that generates
a variable voltage output.
OVERVIEW OF PIC18F452 ADC MODULE
The PIC18F452 ADC module offers the following key features:

- 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:

• • A/D Result High Register (ADRESH)


• • A/D Result Low Register (ADRESL)
• • A/D Control Register 0 (ADCON0)

• • A/D Control Register 1 (ADCON1)


CONFIGURING THE ADC IN PIC18F452

• 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’.

– ADCS2: A/D Conversion Clock Select bi


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.
– 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’.

– ADCS2: A/D Conversion Clock Select bi


CONFIGURING THE ADC IN PIC18F452
PIC18F452/458 ADC FEATURES PROGRAMMING

• The following steps should be followed for doing an A/D conversion:


EXAMPLE: READING A POTENTIOMETER VALUE
• Let’s implement a simple example where we read the value of a potentiometer connected to the AN5 pin
and display it via LCD

• 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.

PIC Tutorial Three - LCD Modules (winpicprog.co.uk)

You might also like