0% found this document useful (0 votes)
66 views

MP Lab Report # 5

The objectives of the lab were: 1. To introduce analog to digital conversion (ADC) using a PIC microcontroller 2. To write code for ADC using the MikroC library and without using the library 3. To demonstrate ADC by reading an analog input and displaying the digital output on LEDs The lab tasks involved writing code to read an analog input channel and output the digital value on LEDs using the built-in ADC library. Then repeating the task without using the library. The conclusion was that the analog to digital conversion was successfully demonstrated with the digital output displayed on an LED bar graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

MP Lab Report # 5

The objectives of the lab were: 1. To introduce analog to digital conversion (ADC) using a PIC microcontroller 2. To write code for ADC using the MikroC library and without using the library 3. To demonstrate ADC by reading an analog input and displaying the digital output on LEDs The lab tasks involved writing code to read an analog input channel and output the digital value on LEDs using the built-in ADC library. Then repeating the task without using the library. The conclusion was that the analog to digital conversion was successfully demonstrated with the digital output displayed on an LED bar graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Objectives:

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER


ENGINEERING
EXPERIMENT: 01

Lab Title: . Analog to Digital converter (ACD) for PIC


Student Name: ABDUL MOEED, HASSAN ZEB, UMAIR-UL-HASSAN

Reg. No:190378, 190570, 190538

Objective: To recognize the working of Mikro-C and SmartPro 500u burner.

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:

L
a Lab 5
Analaog to Digital converter
(ADC) in PIC18F452

Objectives:
 Introduction to ADC
 Using library of ADC in MikroC
 Write a code for ADC

Introduction:

Pin Direction (TRIS):


The pins which are to be used as analog input, must be configured as INPUT (Corresponding bit
in TRIS register must be set).
All analog inputs have built-in 10 bit ADC
 Digital output is of 10bits

This is a 10bit ADC If Vref   3V then Step size


So Resolution 3/1023=2.93mv
210 1 =1023 For 2.93mv LSB will be 1 only
4 Special function registers are associated with A/D modules
1. ADRESH
 A/D Result High Register
2. ADRESL
 A/D Result Low Register
3. ADCON0
 A/D Control Register 0
4. ADCON1
 A/D Control Register 1
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”.

While using software mikroC a library of “ADC” is included to use ADC


comfortably.

Command Syntax Description


ADC=ADC_read(X); ADC=ADC_read(1); Input is analogue and output will be 10bit digital value
Procedure:
Open MikroC, make new project and perform the given tasks

Lab Task#1:
Write a code which takes analogue input and converts it into digital then sends its digital output
on LED’s.

CODE:
void main() {
unsigned int ADC;
Trisa=0b11011011; //RA0,RA1,RA3,RA4 marked as input RA2,RA5 marked as output on

Trisb=0; //Define PortB output Port

ADCON1=0b00000101; //Explained below

while(1){
ADC=ADC_read(1); //”1” is used for channel 1 (you can use 2,3,4,5,6,7 for channel 2,3,4,5,6,7)

Latb=ADC&255; //ADC is 10 bit (from bit0-bit9) value and LATB is 8 bit(bit0-bit7)

lata2_bit=(ADC>>8)&1; //8th bit is needed here see example

lata5_bit=(ADC>>9)&1; //9th bit is needed here which is MSB see example

}}

In above code ADCON1=0b00000101


1 1 0 0 0 1 0 1
AN7 AN6 AN5 AN4 AN3 AN2 AN1 AN0 Vref+ Vref-
0 0 Unimplemented D D D D Vref+ D A A AN3 Vss
Not necessary to use while Bit3 ------------------------------------------------------------- Bit0
Using built in Library

A=Analogue D=Digital
EXAMPLE: If ADC in above code has value “1111001011”
Then LatB=ADC&255=1111001011&0011111111 (this is bit by bit and so)
LatB=11001011 (8 least significant bits of ADC)
Now Lata2_bit= (ADC>>8) &1= 0000000011&0000000001
Lata2_bit=1 (8th bit)
Now Lata2_bit= (ADC>>9) &1= 0000000001&0000000001
Lata5_bit=1 (9th bit)

Schematic:

ADC is mostly used with sensors so if you want to use a sensor you can connect with Pic18F452
using simple circuitry. If you have a sensor like thermistor or LDR which will vary its resistance
according to environment then it can be connected in place of RV1.
Hardware:

Lab Task#2:
Perform Task#1 again but without using built in ADC Library

Proteus:
Hardware:

Conclusion:
In this lab we experienced the code and hardware of the conversion of analogue signal to digital
signal through the P18F452, we set the oscillation frequency so that TAD will always greater than
1.6us. First, we gave the Vpp the voltage of 5V and then we gave the analogue pin the signal of 3V,
and attached the led bar graph with the digital pins. We clearly see the perfext results of the
conversion on the LED bar, as it recueves 1 it turns on, while when it receives the 0 signal turns off.

You might also like