You are on page 1of 6

[EMBEDDED SYSTEM APPLICATIONS ] DEC5052

PRACTICAL SKILL ASSESSMENT


COURSE : EC501
EXPERIMENT NO. : 6
EXPERIMENT TITLE : Analog to Digital Converter (ADC)

Lecturers name: 1. __________________________________________


2. __________________________________________
3. __________________________________________
4. __________________________________________

Group Registration No. Student Name Class

A. WRITE PROGRAM (each program 25% )


Excellent Good Average Weak
Able to connect circuit Able to connect Able to connect circuit Has great difficulty to
& write program in C circuit & write & write program in C connect circuit & write
Language accurately program in C Language accurately program in C Language
without any assistance Language accurately with some assistance despite the assistance
from lecturer. with minimum from lecturer. given by the lecturer.
assistance from
lecturer.

Program 6 25 20 16 12

TOTAL (25%)
Able to write program Able to write program Able to write program Has great difficulty to
in C Language using in C Language using in C Language using write program in C
MPLAB IDE accurately MPLAB IDE accurately MPLAB IDE accurately Language using MPLAB
without any assistance with minimum with some assistance IDE despite the
from lecturer. assistance from from lecturer. assistance given by the
lecturer. lecturer.

B. RESULT (40%) 40 30 20 10 /40

C. QUESTIONS (10%) 10 8 5 3 /10

D. DISCUSSION (20%) 20 15 10 5 /20

E. REFLECTION (5%) 5 4 3 2 /5

TOTAL (100%)

45
[EMBEDDED SYSTEM APPLICATIONS ] DEC5052

EXPERIMENT : 6

TITLE : Analog to Digital Converter (ADC)

COURSE LEARNING OUTCOME (CLO):


At the end of this experiment, the students should be able to :
i. Interface a ADC chip to the microcontroller.
ii. Calculate the equivalent voltage value from the ADC result.
iii. Write ADC programming in C language.

EQUIPMENTS:
Before operating your PIC experiment, please ensure that you have the following items:

(1) Personal Computer (PC)


(2) MPLAB IDE Software
(3) PTK40A PIC Training Kit

THEORY:
The internal ADC of the microcontroller has eight channels of analogue input and gives 10-bit digital
output. The ADC converts an analog input voltage into a digital number. Since I/O of PIC is multiplex with
other function, we must make correct initialization and configuration before particular pin can be used as
analog input.

ADCON0
CHS3 CHS2 CHS1 CHS0 GO/DONE AD0N

CHS3 CHS0 : Select the input channel


GO/DONE : ADC status bit (0=busy converting, 1 = done)
ADON : ADC on bit (0=disable, 1 = enable)

First, is to configure ADC pin as input which is controlled by TRISX register, in this case is TRISA. Follow
by ADCON0 and ADCON1. ADCON0 register controls the operation of ADC module. ADCON1 register
determines whether the Port A pins function as either digital or analog inputs.

In this experiment, the reference voltage to the ADC is the same as the supply voltage to the
microcontroller, i.e., 5V.

The resolution of the ADC can be calculated as follows:


Resolution = Vref
(1024 - 1)
= 5/1023
= 4.887 mV
(as it is a 10 bit ADC)

It means that for 4.887mV change in the analogue input, the ADC output changes by binary 1 with a
reference voltage of 5V.

46
[EMBEDDED SYSTEM APPLICATIONS ] DEC5052

The formula of analogue to digital conversion (10bit),

VD = Vout x (1024+1)
5
Where VD is needed convert to binary base.

Analog Input
Analog input is designed to read analog voltage from potential meter, temperature sensor or external
analog input. Only 1 analog input can be used at the same time. Use mini jumper at JP14 to select analog
input used. JP12 is provided to connect others analog input besides temperature sensor and
potentiometer.

Figure 6.1

PROCEDURES:
1. Create a new project using PIC 16F877A as the microcontroller.
2. Write the program 6 in your editor and build the project:
3. Compile and build the source code.
4. Download the hex into the controller board.
5. Run and observe the result on the LED board.
6. Record the output data in the Table 6.1.
7. Obtain and compare the results (using formula given).
8. Try with different analog inputs by adjusting potentiometer VR2.
9. Measure the output voltage (pin PA0 and GND).

47
[EMBEDDED SYSTEM APPLICATIONS ] DEC5052

Program 6: ADC

//--------------------------------------------------------------------------------
// Author : Mr Suhaimi Bin Saharone
// Project : Analog to Digital Converter (ADC) OK
// Date : 10 Mac 2015
//--------------------------------------------------------------------------------

//-------------------- INCLUDE ---------------------------


#include<pic.h>

//-------------------- CONFIGURATION ------------------------


__CONFIG (0x3F32);

//-------------------- DEFINE THE I/O PIN -------------------

//-------------------- FUNCTION PROTOTYPE -------------------


void delay(unsigned short i);

//-------------------- MAIN FUNCTION -----------------------

void main(void)
{
ADRESH=0; //clear A/D result
ADRESL=0; //clear A/D result

TRISAbits.TRISA0=1; //set RA0 as analog input


TRISD=0b00000000; //configure PORTD as output
TRISE=0;

ADCON0 = 0x81;
ADCON1 = 0xCE; //right justified, Fosc/64 AN0=analog
PORTA=0;
PORTD=0;
PORTE=0;

while(1)
{
delay(100);
ADCON0bits.GO=1; //start converting
while(ADCON0bits.GO ==1);

PORTD=ADRESL;
PORTE=ADRESH;
delay(250);
}
}

//---------------------- SUBROUTINE ---------------------


void delay(unsigned short i)
{
for(;i>0;i--);
}

48
[EMBEDDED SYSTEM APPLICATIONS ] DEC5052

RESULT:
Experiment output :

Program 6 : ______________________________________________________________________________________________

______________________________________________________________________________________________

Input Output Output


Voltage Hex Hex
(by observation) (by calculation)
(Vin)
D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
0.5v
1.0v
1.5v
2.0v
2.5v
3.0v
3.5v
4.0v
4.5v
5.0v

Table 6.1

QUESTION:

1. For an 8 bit ADC, given Vref = 2.56V. Calculate the D0-D7 output if the analog input is:
i. 1.7V ii. 2.1V

49
[EMBEDDED SYSTEM APPLICATIONS ] DEC5052

2. With Vref+ = 2.56 V and Vref- = Gnd, find the Vin for the following output:
i. D7-D0 = 1111 1111 ii. D7-D0 = 1000 0000

DISCUSSION:
1. Discuss the major characteristics of the ADC as below:
i. Resolution

______________________________________________________________________________________________________

______________________________________________________________________________________________________

______________________________________________________________________________________________________

ii. Vref

______________________________________________________________________________________________________

______________________________________________________________________________________________________

______________________________________________________________________________________________________

iii. Conversion time

______________________________________________________________________________________________________

______________________________________________________________________________________________________

______________________________________________________________________________________________________

REFLECTION:
Through this experiment, I have learned

_________________________________________________________________________________________________________________________

_________________________________________________________________________________________________________________________

_________________________________________________________________________________________________________________________

_________________________________________________________________________________________________________________________
50

You might also like