ee 109 appendix a
play

EE 109 Appendix A Analog-to-Digital Conversion ANALOG TO DIGITAL - PowerPoint PPT Presentation

A.1 A.2 EE 109 Appendix A Analog-to-Digital Conversion ANALOG TO DIGITAL CONVERSION A.3 A.4 Electric Signals Electronic Information Information is Digital Camera Color Filters represented CCDs (Charge-Coupled CCDs


  1. A.1 A.2 EE 109 Appendix A Analog-to-Digital Conversion ANALOG TO DIGITAL CONVERSION A.3 A.4 Electric Signals Electronic Information • Information is • Digital Camera Color Filters represented – CCD’s (Charge-Coupled CCD’s electronically as a time- Devices) output a voltage proportional to varying voltage the intensity of light – Each voltage level may hitting it represent a unique value – 3 CCD’s filtered for – Frequencies may measuring Red, Green, represent unique values and Blue light produce 1 (e.g. sound) color pixel Sound converted to electronic signal (voltage vs. time) More info: http://www.science.ca/scientists/scientistprofile.php?pID=129 http://www.microscopy.fsu.edu/primer/digitalimaging/concepts/ccdanatomy.html

  2. A.5 A.6 Signal Types Analog to Digital Conversion • Analog signal • 1 Analog signal can be converted to a set of – Continuous time signal where each voltage level has a unique meaning digital signals (0’s and 1’s) – Most information types are inherently analog • Digital signal • 3 Step Process – Continuous signal where voltage levels are mapped into 2 ranges – Sample meaning 0 or 1 – Quantize (Measure) – Possible to convert a single analog signal to a set of digital signals – Digitize 11000 volts volts 1 1 volts 0 1 1 Analog to 0 Threshold 1 Digital 0 1 Converter 0 0 0 0 1 0 time time time time Analog Digital Analog Digital A.7 A.8 Sampling Quantization • Voltage scale is divided into a set of finite numbers (e.g. 256 values: 0 – 255) • Measure (take samples) of the signals voltage at a • Each sample is rounded to the nearest number on the scale regular time interval • Quantization converts continuous voltage scale to a discrete • Sampling converts the continuous time scale into (finite) set of numbers discrete time samples 255 177 000 ∆ t ∆ t Original Analog Signal Sampled Signal Sampled Signal Each sample is quantized

  3. A.9 A.10 Digitization Error • Error is introduced because the discrete time and • The measured number from each sample is quantized samples only approximate the original converted to a set of 1’s and 0’s analog signal Measurement Scale 255 Sample 177 = 10110001 177 000 Original Analog Signal Sampled Signal Each sample is quantized Quantized value is converted to bits A.11 A.12 Digital Sound Sampling Rates and Quantization Levels • Higher sampling rates and quantization levels • CD Quality Sound produce more accurate digital representations – 44.1 Kilo-samples per second – 65,536 quantization levels (16-bits per sample) – 44.1KSamples * 16- bits/sample = 705 Kbps • MP3 files compress that information to 128Kbps – ∆ t Lower sampling rate and Higher sampling rate and 320 Kbps quantization levels more quantization levels

  4. A.13 A.14 ADC Module • Your Atmel micro has an A-to-D Converter (ADC) built in • The ADC module can be used to convert an analog voltage signal into 10 bit digital numbers. Converting voltages to digital numbers ADC MODULE • Not fast enough for video or audio. • Controlled by a set of six registers which you must program appropriately A.15 A.16 Note ADC Registers • ADC is primarily controlled by two registers • Microcontroller modules often come with whose bits control various aspects of the ADC many adjustable features and settings to make – ADMUX – ADC Multiplexor Selection Register it useful to a wide variety of applications – ADCSRA – ADC Control and Status Register A • In EE 109 we may not want to use all that • We will see what these bits means as we functionality so we have to enable or disable continue through our slides… those features or alter certain settings 7 6 5 4 3 2 1 0 • How do we do this? By setting bits in specific ADMUX REFS1 REFS0 ADLAR MUX3 MUX2 MUX1 MUX0 registers 7 6 5 4 3 2 1 0 – The values we program into the registers control ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 how the hardware works!

  5. A.17 A.18 ADC Voltage Reference • The ADC can only measure voltages in the range of V hi to V low – If the voltage is higher than Vhi it just converts to 1023=0x3ff – If the voltage is lower than Vlow it just converts to 0 – Voltages between the limits are converted linearly to digital values. • Samples will be taken either at regular intervals or just when you tell it to take a sample Input Voltage Only need to perform once before you start using the ADC ADC INITIALIZATION PROCESS V hi 0x3FF (1023 dec.) 915 1023 0x3ff = 862 1023 Input 0x1ff = 511 Digitized voltage number from ADC 230 V low 0x000 A.19 A.20 ADC Voltage Reference ADC Input Selection • The low reference is fixed at • The ADC has six input ground = 0V. channels/pins that can be connected to the one built-in • High reference is selectable converter – AVCC (connected to VCC) • Only one channel can be • Usually the one we want! – AREF converted at any one time – Internal 1.1V reference (i.e. is internally muxed) • Reference selection controlled • Channel selection controlled by bits in a register by bits in a register • ADC Init Step 1 : Set REF bits to • ADC Init Step 2: Set MUX bits choose AVCC to give analog in ADMUX register to desired Use Pin A0 = 0 0 0 0 Use Pin A1 = 0 0 0 1 …. range of 0-5V channel number 0 0 = AREF Use Pin A5 = 0 1 0 1 0 1 = AVCC 1 1 = Int 1.1V – Set ADMUX register bit REF REF AD MUX MUX MUX MUX – If we want channel A3, set mux S1 S0 LAR REF REF AD MUX MUX MUX MUX 3 2 1 0 S1 S0 LAR • REFS1 to a 0 3 2 1 0 bits to 0011 ADMUX Register ADMUX Register • REFS0 to a 1

  6. A.21 A.22 Scale ADC Clock Generation • Documentation requirement : The ADC • Analogy: Some scales give your weight to the nearest needs a clock in the range 50kHz to pound (137) while others are accurate to the tenth of 200kHz in order to operate. pound (137.6) • Clock generated for the Arduino's – It's nice to have accuracy but for most of us we are processor is 16Mhz content with the accuracy just at the nearest pound • Prescalar (a.k.a. divider) reduces the • Our ADC can provide readings up to 10-bits accuracy clock to a lower frequency by dividing (on a scale from 1023)… its frequency • …but it can also drop the lower 2 bits to provide • Divide by 2, 4, 8, 16, 32, 64, or 128 readings of 8-bit accuracy (on a scale from 256) ��� ����� ���� 1023 255 ��� ���� � – ��������� • The question is simply do we need 10-bit accuracy or 209 836 – If Precalar=64 then ADC Freq = 16MHz / is 8-bit accuracy sufficient 64 = 250KHz (still too fast) • ADC Init Step 3 : Set prescalar to • In EE109 we'll always use 8-bit readings Prescalar: 2 = 0 0 1 128 by turning on (setting) ADPS2, Prescalar: 4 = 0 1 0 • ADC Init Step 4: Set ADLAR bit to 1 in the ADMUX …. Prescalar: 64 = 1 1 0 ADPS1, ADPS0 bits in ADCSRA register (1 = 8-bit results, 0 = 1024 bit results) Prescalar: 128 = 1 1 1 register ADEN ADSC AD ADIF ADIE AD AD AD ATE PS2 PS1 PS0 REF REF AD MUX MUX MUX MUX S1 S0 LAR 0 0 ADCSRA Register 3 2 1 0 Sample ADMUX Register Voltage A.23 A.24 Enable the ADC ADC Register Review • ADMUX – ADC Multiplexor Selection Register • The ADC module has an 'enable' bit which – REFS - Voltage reference selection (bits 7-6) effectively acts as an on/off switch (turn off to • 01 to select AVCC, connected to VCC (+5V) on µC save power) – ADLAR - Left adjust results (bit 5) • ADC Init Step 5: Set ADEN bit to 1 • 0 = "right adjust" for 10-bit result • 1 = "left adjust" for 8-bit result – MUX - Input channel selection (bits 3-0) • Use values 0000 to 0101 to select pins A0 to A5 7 6 5 4 3 2 1 0 ADMUX 1 = Enable REFS1 REFS0 ADLAR MUX3 MUX2 MUX1 MUX0 0 = Disable ADEN ADSC AD ADIF ADIE AD AD AD ATE PS2 PS1 PS0 ADCSRA Register

Recommend


More recommend