Sunteți pe pagina 1din 50

ADC / DAC

ECET 209 – Lecture 19


Introduction to Microcontrollers
Overview

• Introduce Analog and Digital Converters

ECET 209 Purdue University 2


Digital vs. Analog

• Digital is represented by two values


– A logic 1 or a logic 0

• Analog values are continuous


– Can take any value in a given range
– Exact value is significant

ECET 209 Purdue University 3


Digital vs. Analog

• Most values are analog in nature


– Temperature
– Speed
– Position
– Sound
– Etc

• Digital systems are used to process


information

ECET 209 Purdue University 4


Digital vs. Analog

• Digital systems are used to process info

– Somehow need to convert an analog value into


a digital value

– Perform digital operations on the data

– Somehow need to convert the digital results


back into an analog quantity
ECET 209 Purdue University 5
Digital vs. Analog

• Digital systems are used to process info


• A couple Major Examples

– CD’s
– MP3’s
– DVD’s

ECET 209 Purdue University 6


Digital vs. Analog

micro
ADC DAC

ECET 209 Purdue University 7


ADC & DAC

• ADC – Analog to Digital Converter


• DAC – Digital to Analog Converter

• ADC and DAC operations are required at


the input and output from a digital
processing system that deals with analog
quantities.

ECET 209 Purdue University 8


Analog/Digital Characteristics

• Performance Criteria
– Resolution
– Sampling Rate
– Speed
– Linearity

ECET 209 Purdue University 9


Analog/Digital Characteristics

• Resolution
– Smallest change in voltage represented by digital code
• Sampling Rate
– Number of times per second a conversion occurs
• Speed
– Determined by the time required to perform conversion
• Linearity
– Accuracy in the conversion throughout the range
ECET 209 Purdue University 10
Analog/Digital Characteristics
• Resolution
– Smallest change in voltage represented by digital code

ECET 209 Purdue University 11


Analog/Digital Characteristics
• Sampling Rate
– Number of times per second a conversion occurs

n?

ECET 209 Purdue University 12


1 second
Analog/Digital Characteristics
• Speed
– Determined by the time required to perform a conversion
• Conversion Time – time required to complete the measurement
• Access Time – time from start until the result is on the output
• Settling Time – time for the analog to settle after a digital change

ECET 209 Purdue University 13


Analog/Digital Characteristics
• Linearity
– Accuracy in the conversion through the range

ECET 209 Purdue University 14


Analog/Digital Characteristics
• Linearity
– Accuracy in the conversion through the range

ECET 209 Purdue University 15


Analog/Digital Devices
• There are numerous ADC’s and DAC’s
– Characteristics will determine which one to use
• Costs
• Resolution
• Speed
• Accuracy (Linearity)
• Interface ( serial interface or parallel )
• etc

– Application determines which one to pick


ECET 209 Purdue University 16
Analog to Digital Converter

• Resolution is a function of the maximum


voltage and the number of data bits in the
result

ECET 209 Purdue University 17


Analog to Digital Converter

• Resolution of the ADC is:

resolution = Vin_max / 2^n – 1

• Example ( Vin_max = 10 Volts with 8 bits)


resolution = 10 / 255 = 0.03921 => or
approximately 40mV per bit when using 8-bits
of accuracy
ECET 209 Purdue University 18
8-bits vs. 10-bits

• A system with 10-bits of data vs. a system


with only 8-bits of data is 4 times more
resolution.

• Remember, 2^power

• In this case, the power is 2 and therefore the


difference is a factor of 4.
ECET 209 Purdue University 19
Analog to Digital Converter

micro

ADC

Single wire
Analog input

ECET 209 Purdue University 20


Analog to Digital Converter
Single bit to start
a conversion

micro

ADC

ECET 209 Purdue University 21


Analog to Digital Converter
Single bit that signals when
valid data is available

micro

ADC

ECET 209 Purdue University 22


Timing Diagram for ADC

Convert

Data Ready

Data Bus Valid Data Valid Data

ECET 209 Purdue University 23


Analog to Digital Converter

micro

ADC

10-Bits of
ECET 209 digital data
Purdue University 24
Analog to Digital Converter

micro

ADC

ECET 209 Purdue University 25


Analog to Digital Converter

micro

ADC

Vin / resolution = digital output


ECET 209 Purdue University 26
Analog to Digital Converter

What if, we only


wanted 8-Bits of micro
digital data ?
ADC

ECET 209 Purdue University 27


Analog to Digital Converter

micro

ADC

Use only upper 8-Bits of digital data


ECET 209 Purdue University 28
Reading the ADC
Only using the
upper 8-Bits *Assuming
ADC is
micro connected to
PORTA
ADC

analog = PINA;

ECET 209 Purdue University 29


Reading the ADC
Using all 10-Bits
*Assuming
upper 8-bits
micro of the ADC
is connected
ADC to PORTA &
the lower 2-
Bits are
connected to
PORTB bits
analog must 0&1
be an int
analog = PINA;
analog = (analog << 2) | (PINB & 0x03);
ECET 209 Purdue University 30
Digital to Analog Converter

micro
DAC

ECET 209 Purdue University 31


Digital to Analog Converter

micro
DAC

8-Bits of Digital
Data => Entire
Port
ECET 209 Purdue University 32
Digital to Analog Converter

micro
DAC

Single wire with


an analog voltage

ECET 209 Purdue University 33


Digital to Analog Converter

micro
DAC

Digital value x resolution = Analog Out

ECET 209 Purdue University 34


Analog and Digital Converter
Input and Output Requirements
12-Bits for the ADC
& 8-Bits for the DAC
=> 20 total Bits
micro

ADC DAC

2 1/2 PORTS
ECET 209 Purdue University of total I/O
35
Serial Analog to Digital Converter

micro
ADC

Open for ???

ECET 209 Purdue University 36


Serial Digital to Analog Converter

micro
DAC

Open for ???

ECET 209 Purdue University 37


Internal Analog to Digital
Converter
ATmega16 microcontroller

ADC

ECET 209 Purdue University 38


Digital-to-Analog &
Analog-to-Digital Part 2

ECET 209 – Lecture 20


Introduction to Microcontrollers
How Does a DAC Work?

2R
2R
MSB 23 -
+
VOUT
Digital Circuitry
R
2R
22

R
2R
21

R
2R
LSB 20

2R

ECET 209 Purdue University 40


DAC Equivalent Circuit

V3 2R
MSB 23
Digital Circuitry

2R
V2 4R
22
-
8R +
VOUT
V1
21

V0 16R
LSB 2 0

⎛ V3 V V V ⎞ V V V
−V = 2R ⎜ + 2 + 1 + 0 ⎟ =V + 2 + 1+ 0
OUT ⎜ 2R 4R 8R 16R ⎟ 3 2 4 8
⎝ ⎠

ECET 209 Purdue University 41


How Does an ADC Work?
Vin +

AREF 10-Bit DAC

ADC Clock
Signal
ADC Conversion Logic

ECET 209 Purdue University 42


ATmega16 Internal ADC
ADC0
ADC1

Channel Selection
ADC2

Multiplexer
ADC3
ADC4
ADC5
ADC6
ADC7

MUX0
+
MUX1
MUX2
-

ADLAR

REFS0
REFS1

AVCC

Internal 2.56V
Reference

AREF 10-Bit DAC

System Clock / 2
7-Bit ADC Prescaler

System Clock / 4
System Clock / 8 ADC Clock
System Clock System Clock / 16 Signal

System Clock / 32 ADC Conversion Logic


System Clock / 64
System Clock / 128

ADPS0 ADIF
ADPS1
ADPS2 ADCH/ADCL

ADEN

ADSC

ECET 209 Purdue University 43


Analog Input

ADC0
ADC1

Channel Selection
ADC2

Multiplexer
ADC3
To ADC Input
ADC4
ADC5
ADC6
ADC7

MUX0
MUX1
MUX2

ECET 209 Purdue University 44


Analog Reference Voltage

ECET 209 Purdue University 45


ADC Clock Selection

System Clock / 2
7-Bit ADC System Clock / 4
Prescaler System Clock / 8
System Clock System Clock / 16 ADC Clock Signal

System Clock / 32
System Clock / 64
System Clock / 128

ADPS0
ADPS1
ADPS2

ECET 209 Purdue University 46


ADC Conversion Result

10-Bit DAC

ECET 209 Purdue University 47


Conversion Logic

ECET 209 Purdue University 48


Solution Steps

ECET 209 Purdue University 49


Lab Next Week

ECET 209 Purdue University 50

S-ar putea să vă placă și