Professional Documents
Culture Documents
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.
E. REFLECTION (5%) 5 4 3 2 /5
TOTAL (100%)
45
[EMBEDDED SYSTEM APPLICATIONS ] DEC5052
EXPERIMENT : 6
EQUIPMENTS:
Before operating your PIC experiment, please ensure that you have the following items:
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
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.
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
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
//--------------------------------------------------------------------------------
void main(void)
{
ADRESH=0; //clear A/D result
ADRESL=0; //clear A/D result
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);
}
}
48
[EMBEDDED SYSTEM APPLICATIONS ] DEC5052
RESULT:
Experiment output :
Program 6 : ______________________________________________________________________________________________
______________________________________________________________________________________________
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
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
REFLECTION:
Through this experiment, I have learned
_________________________________________________________________________________________________________________________
_________________________________________________________________________________________________________________________
_________________________________________________________________________________________________________________________
_________________________________________________________________________________________________________________________
50