1 / 26

EE 319K Introduction to Microcontrollers

EE 319K Introduction to Microcontrollers. Lecture 12: A/D Conversion and Lab 8. Read Book Sections 10.2 and 11.4. A/D and D/A Conversion Basics. Digitization :Amplitude and time quantizing. Nyquist Theory.

landry
Télécharger la présentation

EE 319K Introduction to Microcontrollers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EE 319KIntroduction to Microcontrollers Lecture 12: A/D Conversion and Lab 8 Read Book Sections 10.2 and 11.4

  2. A/D and D/A Conversion Basics Digitization:Amplitude and time quantizing Ramesh Yerraballi

  3. Nyquist Theory • If a signal is sampled at fs then the digital samples only contain frequency components from 0 to (1/2)fs • Conversely, if the analog signal does contain frequency components larger than (1/2)fs, then there will be an aliasing error. • Aliasing is when the digital signal appears to have a different frequency than the original analog signal. • Say, V(t) = A sin(2πft + ) • Nyquist theory says that if fs is strictly greater than twice f, then one can determine A f and  from the digital samples. • But iffs is less than or equal to 2f, then the apparent frequency, as predicted by analyzing the digital samples, will be shifted to a frequency between 0 and (1/2)fs Ramesh Yerraballi

  4. .. Nyquist Theory Ramesh Yerraballi

  5. A/D and D/A Conversion Basics • Range of the system is the maximum minus the minimum values • Precision of the system defines the number of values from which the amplitude of the digital signal is selected. (Alternatives) • Resolution is the smallest change in value that is significant. Range = Precision x Resolution Ramesh Yerraballi

  6. A/D Converter Example Analog to digital Converter • Analog input 0 ≤ Vin ≤ +5 • Digital output 0 ≤ ATD0DR0 ≤ 255 • Digital Output is about 256*Vin/5 • Or Digital Output is about 255*Vin/5 D Analog 0.00 1.50cm Vin Analog 0 +5 255 0 Digital Ramesh Yerraballi

  7. 9S12 has 16 Analog Inputs AD1 AD0 One Control Register per ADC module: ATD0CTL2 and ATD1CTL2 Ramesh Yerraballi

  8. Port AD0 ATD0CTL2=$80 ; set bit 7 to 1 to enable ADC ATD0CTL3=$08 ; sequence length = 1 SRES8 ; 1 for 8-bit values, 0 for 10-bit values Ramesh Yerraballi

  9. ADC Clock • The ADC has an internal clock that controls how fast the ADC runs • Not how many samples it takes but how fast the conversion (A/D) works. • Speed controlled by 5-bit value in the lower 5-bits (PRS5-PRS1) of ATD0CTL4 • Say this value is m (e.g., 00100 => m=4) • The ATD internal clock speed is given by:(1/2)E/(m+1) where E is the E clock speed • Say we want this speed to be 1 MHz, So for: • E-clock speed of 4 MHz m is set to 1 • E-clock speed of 8 MHz m is set to 3 • E-clock speed of 24 MHz m is set to 11 • Internal clock speed can range from 500 kHz to 2 MHz Ramesh Yerraballi

  10. Other settings • ATD0CTL5write channel number (analog input) to start ADC • channel number $80 to $87(CC:CB:CA) • ATD0STATbit 7 SCF • cleared by write to ATD0CTL5(i.e., starting a new conversion) or just write 1 to it • set when ADC finished • ATD0DR0first 8/10-bit ADC result • precision 8/10-bit, 256/1024 alternatives • range 0 to +5V • resolution (5-0)/255  0.02 V ; (5-0)/1023  0.005 V 1.5/255  0.006 cm; 1.5/1023  0.0015 cm Ramesh Yerraballi

  11. 8-bit Conversion Example Digital o/p = 255 * Vin/5 Ex1: Vin = 1.50 => Dig out = Integer approx (255 * 1.50/5) = 76 = $4C = %01001100 Ex2: Vin = 3.75 => Dig out = Integer approx (255 * 3.75/5) = 191 = $BF = %10111111 Ramesh Yerraballi

  12. 10-bit Conversion Example Digital o/p = 1023 * Vin/5 Ex1: Vin = 0.005 => Dig out = Integer approx (1023 * 0.005/5) = 1 = $001 = %0000000001 Ex2: Vin = 3.750 => Dig out = Integer approx (1023 * 3.750/5) = 768 = $300 = %1100000000 Ramesh Yerraballi

  13. Tut3 in TExaS is an ADC example See ADC Driver ADC_Init Turns it on Sets it to 10-bit mode ADC_In write channel number to ATD0CTL5 wait for SCF flag in ATD0STAT read 10-bit result from ATD0DR0 SCI_OutDec Complete ADC Example Ramesh Yerraballi

  14. Lab 8: Design a Position Meter • Hardware • Transducer • Electronics • ADC • Software • ADC device driver • Timer routines • Output compare interrupts • LCD driver • Measurement system • How fast to update • Fixed-point number system • Algorithm to convert ADC into position Ramesh Yerraballi

  15. Lab8: Data Flow Graph 1.50 cm 255 255 1.50 Ramesh Yerraballi

  16. Lab8: Transducer • A transducer converts some observable phenomena (temperature, pressure, opening, position, speed etc. to a analog form that can then be digitized. • A potentiometer converts position to a resistance • Solder wires to pins 1,2,3 • Glue potentiometer to a solid base • Position metric ruler (for calibration and testing) • Create a hair-line cursor Ramesh Yerraballi

  17. Lab8: Circuit • What is R12 + R23 at all times? • What are R12 and R23 when cursor is at 1 cm? • What is Vinwhen cursor is at 1 cm? • What is ATD0DR0 when cursor is at 1 cm? • What do you want to display on the LCD when cursor is at 1 cm? Ramesh Yerraballi

  18. Lab8: Call Graph Ramesh Yerraballi

  19. Convert ADC data into integer part of fixed-point Three possibilities • The relationship between the ADC data and what it represents is expressible as an equation • The relationship is expressible as a partially complete table and we use interpolation to infer the missing • The relationship is expressible as a complete table and we perform explicit table lookup Ramesh Yerraballi

  20. Complex Equation let n be ADC (0 to 1023) V = 5.0*n/1023 (in volts) R = 18.31 + 5.312*V (in k) T = 1/(H0+H1ln(R)) -273.15 (in oC) (H0 = 0.002486844 , H1 = 0.000243014) I = 100*T (in 0.01 oC) Simple Equation I = 3971 – 1.9768*n Equation for Temperature Example Ramesh Yerraballi

  21. Muls and Divs Ramesh Yerraballi

  22. Unsigned 8 to 16-bit promotion ;to promote RegB into RegD clra ; to promote RegA into RegX tfr A,B clra tfr D,X Signed 8 to 16-bit promotion sex A,D (same as tfr A,D) sex B,D (same as tfr B,D) sex A,X (same as tfr A,X) sex B,X (same as tfr B,X) sex A,Y (same as tfr A,Y) sex B,Y (same as tfr B,Y) 16 to 8-bit demotion (signed or unsigned) tfr D,A tfr D,B tfr X,A tfr X,B tfr Y,A tfr Y,B Promotion/Demotion Ramesh Yerraballi

  23. Complex Equation let n be ADC (0 to 1023) V = 5.0*n/1023 (in volts) R = 18.31 + 5.312*V (in k) T = 1/(H0+H1ln(R)) -273.15 (in oC) (H0 = 0.002486844 , H1 = 0.000243014) I = 100*T (in 0.01 oC) Simple Equation I = 3971 – 1.9768*n Using fdiv, find m such that 65536/m = 1.9768 m = 65536/1.9768 = 33152.5698 ≈ 33153 * Reg D has ADC result, 0 to 1023 ldx #33153 fdiv pshx ; 1.9768*n ldd #3971 subd 2,SP+ std I ; 0.01 C Equation for Temperature Example Ramesh Yerraballi

  24. Simple Equation Ramesh Yerraballi

  25. Interpolation • We will look at examples in TExaS help system • 8-bit table access on the 6812 • 16-bit table access on the 6812 • Basic idea B YL - Y1 XL - X1 = Y2 - Y1 X2 - X1 The TBL Instruction does this YL = Y1 + B *(Y2 - Y1) Ramesh Yerraballi

  26. Back to Lab 8 • Sample ADC every 0.2s • Map (Data: 0 to 255) into (Position: 0000 to +1500) • Option A: Use a linear function • Position = 1500*(Sample)/255 (NOT THIS ONE) • Option B : Use a paired calibration table (S[i],P[i]) • S[i] are ADC samples measured at corresponding positions P[i] • Given sample, find i such that S[i]<=sample<S[i+1] • Use linear interpolation (look up etbl in TExaS help) • position = P[i]+((sample-S[i])*(P[i+1]-P[i]))/(S[i+1]-S[i]) • Option C : Create a 255-entry calibration table (P[ATD0DR0L]) • Fixed-Point output • 1234 is displayed as “1.234 cm” Ramesh Yerraballi

More Related