0% found this document useful (0 votes)
9 views17 pages

Lecture15 EELE 1232

This document is a lecture on programming the Analog-to-Digital Converter (ADC) in the PIC18 microcontroller. It covers the configuration steps for the A/D module, including setting up pins, enabling interrupts, and starting conversions. Additionally, it provides examples of measuring voltage and temperature using the ADC, as well as generating signals with a Digital-to-Analog Converter (DAC).

Uploaded by

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

Lecture15 EELE 1232

This document is a lecture on programming the Analog-to-Digital Converter (ADC) in the PIC18 microcontroller. It covers the configuration steps for the A/D module, including setting up pins, enabling interrupts, and starting conversions. Additionally, it provides examples of measuring voltage and temperature using the ADC, as well as generating signals with a Digital-to-Analog Converter (DAC).

Uploaded by

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

Introduction to

Microcontrollers
Lecture 15: PIC18 ADC
Programming
Ehsan Atoofian
[email protected]
ADC
• Sensor: converts physical quantity to electrical signal

2
ADC
• Resolution
• Higher is better

Vref
Step _ Size  n
2

Bn-1

B2
B1
B0

3
Analog-to-Digital Conversion

Ref
Analog
R Input 2N -1 Comparators
-
+
R
-
+ Digital
R D1 Outputs
Priority
-
+ Encoder
R D0

4
ADC in PIC18F87J11

ADRESH
ADRESL

5
ADCON0 in PIC18F87J11

6
ADCON1 in PIC18F87J11

7
ADFM in ADCON1

8
9
ANCON0 & ANCON1 in PIC18F87J11

10
Shared Address SFRs

WDTCON

Lab2 bsf WDTCON,ADSHR


setf ANCON0
bcf WDTCON,ADSHR

11
Interrupt for ADC

PIE1

PIR1

12
Programming ADC in PIC18
• 1 )Configure the A/D module:
• Configure the required A/D pins as analog pins using ANCON0, ANCON1
• Configure ADC channel as input using TRISA.x
• Configure ADCON0 & ADCON1
• Turn on A/D module (ADCON0)
• 2) Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set GIE bit
• 3) Start conversion:
• Set GO/DONE bit (ADCON0<1>)
• 4) Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
• OR
• Waiting for the A/D interrupt
• 5) Read A/D Result registers (ADRESH:ADRESL);
• clear bit, ADIF, if required.
• 6) For next conversion, go to Step 1 or Step 2, as required.
13
Example
• Write an assembly program to measure voltage of channel 0 in the
range of 0v to 5v, and send the result in decimal digits: one integer
part and one fractional part. Assume that Vdd=1023*5/255 in PIC18
(ADCS in ADCON1:001)

14
Example
• Assume a temperature sensor generates 20mv/Celsius.
Use ADC in PIC18 and send temperature to PORTB.
Assume Vdd=5-v. The sensor is connected to channel0.

15
DAC

The transfer function of the summing amplifier :


vo = -(v1/R1 + v2/R2 + … + vn/Rn)Rf

16
Example
• Write a program to generate a 3.5-v signal using a DAC.
Assume Vdd=10-v and DAC is 8-bit. .

17

You might also like