You are on page 1of 13

Introduction to PIC Microcontroller Programming & Interfacing

August 19-21, 2010


Franz Duran

21-Aug-10

Paranz

Analog-to-Digital Conversion
DAY 3 Morning Session August 21, 2010
21-Aug-10 Paranz 2

Analog-to-Digital Conversion Process of converting an analog signal to a proportional digital number Used in data acquisition system Analog-to-Digital Converter
ADC, A/D converter

21-Aug-10

Paranz

A/D CONVERSION
Basic 3-bit ADC

21-Aug-10

Paranz

A/D CONVERSION
Vin 0.0V < Vin < +0.625V +0.625V < Vin < +1.25V +1.25V < Vin < +1.875V +1.875V < Vin < +2.5V +2.5V < Vin < +3.125V +3.125V < Vin < +3.75V +3.75V < Vin < +4.375V +4.375V < Vin < +5.0V
21-Aug-10 Paranz

D2D1D0 000 001 010 011 100 101 110 111


5

A/D CONVERSION
Important ADC properties
Resolution
# of bits higher the # of bits, the better

Conversion time ADC Architecture

21-Aug-10

Paranz

A/D CONVERSION
Typical A/D converter architectures
Flash ADC Ramp ADC Successive Approximation ADC Integrating slope ADC

21-Aug-10

Paranz

A/D CONVERSION
Example ADC chip
National Semiconductor ADC0804
General purpose application 8-bit resolution Successive Approximation ADC 10 Ksamples/second (free-running mode) 0-5v input 20-pin DIP

21-Aug-10

Paranz

A/D CONVERSION
Basic ADC0804 circuit

21-Aug-10

Paranz

A/D CONVERSION
PIC16F84A with ADC0804

21-Aug-10

Paranz

10

PIC16F A/D MODULE


10-bit resolution Successive Approximation ADC 0-5V input range 50Ksamples/second

21-Aug-10

Paranz

11

PIC16F A/D MODULE


SFRs:
ADRESH ADRESL ADCON0 ADCON1 PIE1 PIR1 INTCON
21-Aug-10

(A/D Result Register High Byte) (A/D Result Register Low Byte) (A/D Control Register 0) (A/D Control Register 1)
(Peripheral Interrupt Enable Reg. 1) (Peripheral Interrupt Enable Reg. 1)

(Interrupt Control Register)


Paranz 12

PIC16F A/D MODULE

21-Aug-10

Paranz

13

PIC16F A/D MODULE

21-Aug-10

Paranz

14

PIC16F A/D MODULE

21-Aug-10

Paranz

15

PIC16F A/D MODULE

21-Aug-10

Paranz

16

PIC16F A/D MODULE

21-Aug-10

Paranz

17

PIC16F A/D MODULE

21-Aug-10

Paranz

18

PIC16F A/D MODULE

21-Aug-10

Paranz

19

PIC16F A/D MODULE

21-Aug-10

Paranz

20

PIC16F A/D MODULE

21-Aug-10

Paranz

21

PIC16F A/D MODULE


A/D module initialization
1. Select A/D Conversion Clock 2. Configure Analog Channels

21-Aug-10

Paranz

22

PIC16F A/D MODULE


void ADCInit(void) { ADCS0 = 0; ADCS1 = 1; ADCS2 = 0; PCFG3 = 1; PCFG2 = 1; PCFG1 = 1; PCFG0 = 0; TRISA0 = 1; CHS0 = 0; CHS1 = 0; CHS2 = 0; ADFM = 1; ...
21-Aug-10

//TAD = Fosc/32

//Only RA0/AN0 is analog input. //The rest of the analog pins are //digital IO //RA0/AN0 is input //Select channel 0

//Right justified.
Paranz 23

PIC16F A/D MODULE


... ... ADRESL = 0x00; ADRESH = 0x00; ADIE = 0; PEIE = 0; GIE = 0; ADON = 1; return; } //Clear A/D Result registers

//No interrupts

//Turn on ADC circuit

21-Aug-10

Paranz

24

PIC16F A/D MODULE


A/D read
1. Select Channel 2. Wait Acquisition Time 3. Start A/D Conversion

21-Aug-10

Paranz

25

PIC16F A/D MODULE


//Read the 10-bit A/D value unsigned int ADCRead(void) { unsigned int adc_temp; //Hold the 10-bit A/D value ADGO = 1; //Start A/D conversion. while(ADGO == 1); //Wait while conversion is // not finished. adc_temp = ADRESL; //Read the lower 8-bit, then adc_temp += (ADRESH << 8); //read the higher 8-bit, //and form the 10-bit A/D //value. return(adc_temp); //Return. }

21-Aug-10

Paranz

26

PIC16F A/D MODULE

Ex am ple

#1

21-Aug-10

Paranz

27

PIC16F A/D MODULE


EXERCISE:
Open Example#1

Ex am ple

#1

Build the project, program the microcontroller, and run the application

21-Aug-10

Paranz

28

PIC16F A/D MODULE

Ex am ple

#2

21-Aug-10

Paranz

29

21-Aug-10

Paranz

30

10

21-Aug-10

Paranz

31

Interfacing LM35 Sensor


LM35
National Semicon. Temp. sensor T0-92 package

21-Aug-10

Paranz

32

21-Aug-10

Paranz

33

11

21-Aug-10

Paranz

34

21-Aug-10

Paranz

35

21-Aug-10

Paranz

36

12

21-Aug-10

Paranz

37

21-Aug-10

Paranz

38

21-Aug-10

Paranz

39

13

You might also like