0% found this document useful (0 votes)
64 views11 pages

Experiment 10 - Lab Report

The document describes Experiment 10 on using an analog-to-digital converter (ADC) in a PIC18F452 microcontroller. It explains the basic concepts of ADC including the registers used, conversion steps, and clock selection. The experiment objectives are to familiarize students with the ADC in PIC18F452 and have them write code in MikroC to convert analog values from sensors to digital values for processing and display. Students are given two tasks - write code to read an analog input and display the digital output on an LCD, and design a digital thermometer that uses an LM35 temperature sensor with the ADC to read temperature and display the appropriate message on an LCD.

Uploaded by

Intahsar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views11 pages

Experiment 10 - Lab Report

The document describes Experiment 10 on using an analog-to-digital converter (ADC) in a PIC18F452 microcontroller. It explains the basic concepts of ADC including the registers used, conversion steps, and clock selection. The experiment objectives are to familiarize students with the ADC in PIC18F452 and have them write code in MikroC to convert analog values from sensors to digital values for processing and display. Students are given two tasks - write code to read an analog input and display the digital output on an LCD, and design a digital thermometer that uses an LM35 temperature sensor with the ADC to read temperature and display the appropriate message on an LCD.

Uploaded by

Intahsar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EXPERIMENT NO 10

Lab Title:
____________________________________________________________________
Student Name: ______________________________________ Reg. No:
_________________
Objective: ___________________________________________________________________
____________________________________________________________________________

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes (5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: __________________________ Obtained Marks: _________________________

LAB REPORT ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: _____________________ Obtained Marks: ______________________

Date: __________________________ Signature: _________________________


EXPERIMENT 10

Analog-to-Digital Converter (ADC) in PIC18F452

Objective:

 Familiarizing students with ADC in PIC18F452 and writing codes in MikroC to convert analog
values to digital values

Equipment:

 Hardware:
1. PIC18F452 microcontroller
2. 16x2 LCD
3. RIMS Trainer
4. DMM
 Software:
1. mikroC Pro
2. SmartPRO 5000U
3. Proteus

Introduction:

The Analog-to-Digital (A/D) converter module has five inputs for the PIC18F2X2 devices and eight for
the PIC18F4X2 devices. This module has the ADCON0 and ADCON1 register definitions that are
compatible with the mid-range A/D module. The A/D allows conversion of an analog input signal to a
corresponding 10-bit digital number.

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)

The ADCON0 register controls the operation of the A/D module. The ADCON1 register configures the
functions of the port pins.

ADCON0 Register:

The ADCON0 register with detail explanation of function of each bit is given below:
ADCON1 Register:

The ADCON1 register with detail explanation of function of each bit is given below:
where:

A = Analog input D = Digital I/O

C/R = # of analog input channels / # of A/D voltage references

The analog reference voltage is software selectable to either the device’s positive or negative supply
voltage (VDD and VSS), or the voltage level on the RA3/AN3/VREF+ pin and RA2/AN2/VREF- pin.
The A/D converter has a unique feature of being able to operate while the device is in SLEEP mode. To
operate in SLEEP, the A/D conversion clock must be derived from the A/D’s internal RC oscillator. A
device RESET forces all registers to their RESET state. This forces the A/D module to be turned off and
any conversion is aborted.

Each port pin associated with the A/D converter can be configured as an analog input (RA3 can also be a
voltage reference) or as a digital I/O. The ADRESH and ADRESL registers contain the result of the A/D
conversion. When the A/D conversion is complete, the result is loaded into the ADRESH/ADRESL
registers, the GO/DONE bit (ADCON0<2>) is cleared, and A/D interrupt flag bit, ADIF is set.

Steps for AD Conversion:

After the A/D module has been configured as desired, the selected channel must be acquired before the
conversion is started. The analog input channels must have their corresponding TRIS bits selected as an
input. The following steps should be followed for doing an A/D conversion:

1. Configure the A/D module:


 Configure analog pins, voltage reference and digital I/O (ADCON1)
 Select A/D input channel (ADCON0)
 Select A/D conversion clock (ADCON0)
 Turn on A/D module (ADCON0)
2. Configure A/D interrupt (if desired):
 Clear ADIF bit
 Set ADIE bit
 Set GIE bit
 Set PEIE bit
3. Wait the required acquisition time.
4. Start conversion:
 Set GO/DONE bit (ADCON0)
5. Wait for A/D conversion to complete, by either:
 Polling for the GO/DONE bit to be cleared (interrupts disabled)
OR
 Waiting for the A/D interrupt
6. Read A/D Result registers (ADRESH/ADRESL); clear bit ADIF if required.
7. For next conversion, go to step 1 or step 2 as required.

Selecting A/D Conversion Clock:

The A/D conversion time per bit is defined as TAD. The A/D conversion requires 12 TAD per 10-bit
conversion. The source of the A/D conversion clock is software selectable.

Configuring Analog Port Pins:

The ADCON1, TRISA and TRISE registers control the operation of the A/D port pins. The port pins that
are desired as analog inputs, must have their corresponding TRIS bits set (input). If the TRIS bit is
cleared (output), the digital output level (VOH or VOL) will be converted. The A/D operation is
independent of the state of the CHS2:CHS0 bits and the TRIS bits.

Note that:
 When reading the port register, all pins configured as analog input channels will read as cleared
(a low level). Pins configured as digital inputs will convert an analog input. Analog levels on a
digitally configured input will not affect the conversion accuracy.
 Analog levels on any pin that is defined as a digital input (including the AN4:AN0 pins) may
cause the input buffer to consume current that is out of the device’s specification.

Clearing the GO/DONE bit during a conversion will abort the current conversion. The A/D result register
pair will NOT be updated with the partially completed A/D conversion sample. That is, the
ADRESH:ADRESL registers will continue to contain the value of the last completed conversion (or the
last value written to the ADRESH:ADRESL registers). After the A/D conversion is aborted, a 2 TAD
wait is required before the next acquisition is started. After this 2 TAD wait, acquisition on the selected
channel is automatically started. The GO/DONE bit can then be set to start the conversion.

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. This register pair is 16-bits wide. The A/D module gives the flexibility
to left or right justify the 10-bit result in the 16-bit result register. The A/D Format Select bit (ADFM)
controls this justification. Figure below shows the operation of the A/D result justification. The extra bits
are loaded with ’0’s. When an A/D result will not overwrite these locations (A/D disable), these registers
may be used as two general purpose 8-bit registers.

Clock Selection:

 TAD is conversion time per bit


 10 bit A/D conversion time = 12 TAD
 After a conversion has completed, a 2 TAD delay must be provided before the acquisition starts
again
 Clock must be selected such that
“TAD ≥ 1.6 μs”
Example:
For Crystal of 10 MHz, what should be the clock source?
Rule: Select clock such that clock cycle time ≥ 1.6 μs
FOR 10 MHz Xtal if Clock Source “Fosc/2” is used then TAD=2/10Mhz=0.2us<1.6us so this cannot be
used. If Clock Source “Fosc/4” is used then TAD=4/10Mhz=0.4us<1.6us so this cannot be used also. If
Clock Source “Fosc/8” is used then TAD=2/10Mhz=0.8us<1.6us so this cannot be used as well. If Clock
Source “Fosc/16” is used then TAD=16/10Mhz=1.6us≥1.6us so clock source must be less than or equal
to “Fosc/16”.
A/D Conversion Example:
The resolution of a 10-bit ADC and step size is:

This is a 10bit ADC


If
V ref + = 5V then step size
So, Resolution is: is:
10
2 −1 =1023 5/1023=4.88mV
4.88mV*Analog Input =
Digital Output.
Lab Task 1:
Write a code which takes analog input and converts it into digital data then sends its digital
output on an LCD. Verify the results on Proteus.
Lab Task 2:
Design a Digital Thermometer using PIC microcontroller and LM35 Temperature Sensor. In this
task, you will sense the temperature using LM35 and display it on a 16x2 LCD. You may use
built-in ADC libraries. Display your temperature on the LCD followed by a comment:

Temperature Message
Below 10 degrees Celsius Bit Chilly!
Between 10 – 30 degrees Celsius Nice Weather!
Greater than 30 degrees Celsius Im Boiling!

Verify the results on Proteus.


Conclusion:

You might also like