Download presentation
Presentation is loading. Please wait.
Published byBrianna Webb Modified over 8 years ago
1
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages
2
Example Product: Signal Generator Mark Neil - Microprocessor Course 2 A Signal Generator should be programmable. A user can use the the LCD display and the keyboard to change the: Frequency scale Amplitude scale Offset on/off etc. Waveform shape (Square, Sinusoidal, Triangle..) Analog control given by potentiometer Analog signal output by using a Digital to Analog Converter (DAC)
3
ADC on the ATMega128 Mark Neil - Microprocessor Course 3 The ATMega128 has a built in Analog to Digital Converter 10 bits of data for each sample Signals can be digitized from up to 8 inputs 1 input can be digitized at a time There is a multiplexer to select which input should be converted
4
Analog to Digital Converters Mark Neil - Microprocessor Course 4 An ANALOG to DIGITAL CONVERTER (ADC) is a device that measures analog signals and convert them to digital (binary) numbers: 10-bit ADC output 10-bit Number sequence output 10-bit Number sequence Higher Voltage Ref. Lower Voltage Ref. Input Signal Input Signal Input D9 D0
5
Mark Neil - Microprocessor Course 5 ADCCSR – ADC Control and Status Register ADCMUX –Register Select Channel ADCMUX –Register Select Channel Multiplexer to select which channel to digitize 8 ADC Input Channels ADCL – Bits 0-7 ADCH – Bits 8-9 ADCL – Bits 0-7 ADCH – Bits 8-9 ADC: 10 bit Analog to Digital Conversion
6
The ADC Registers I Mark Neil - Microprocessor Course 6 The 10-bit ADC on Atmega128 receives its inputs from PORTF. The Reference voltage is controlled by a potentiometer. The device can be controlled by 4 on board registers: ADCSR : ADC Status Register ADMUX : Multiplexer Control ADCH : Data Register for D9,D8 ADCL : Data Register for D0-D7
7
The ADCCSR Mark Neil - Microprocessor Course 7 ADEN : ADC Enable - turns on the ADC clock ADSC : Start conversion ADIF : Interrupt flag (gets set during a conversion and gets cleared if you write ‘ 1 ’ to it AFTER you have read BOTH data registers) ADIE : Interrupt enable (in the software we do not used interrupts yet so keep it ‘ 0 ’ ) ADPS0-2 : Three bits that determine the ADC clock prescale (e.q. 3 = 1/8)
8
The ADMUX Register Mark Neil - Microprocessor Course 8 The ADC Multiplexer Register ADMUX is used to select a channel to digitise (3 bits for Channel 0-7) :
9
The ADCH/ADCL Registers Mark Neil - Microprocessor Course 9 The ADC Data Register ADCL is used for the 8 lower data bits (D7 - D0) : The ADC Data Register ADCH is used for the two highest data bits (D9,D8) : ADCL ADCH
10
Task Plan Mark Neil - Microprocessor Course 10 Design and construct a Digital Voltmeter: The Atmega128 on-chip ADCs should be used to digitise the input analog voltages. The LCD should be used to display the voltmeter readings. Switches or a keyboard can be used to tell the Voltmeter to capture data Connect your Voltmeter to the potentiometer and measure the voltage. Calibrate it against a Voltmeter in the Lab. Demonstrate that your device works !!!! Connect your Voltmeter to the potentiometer and measure the voltage. Calibrate it against a Voltmeter in the Lab. Demonstrate that your device works !!!!
11
Conceptual Design Mark Neil - Microprocessor Course 11 We want to construct : ATmega128 Board ATmega128 Board Voltage to be measured Voltage to be measured Connector LCD DISPLAY HITACHI LM032XMBL LCD DISPLAY HITACHI LM032XMBL LCD INTERFACE PORTD Buttons Analog Use ADC0 +5 Volts 10K
12
Some Important points : Mark Neil - Microprocessor Course 12 The Voltage you are trying to measure must be between 0 – 2.5 Volts The reference voltage of the ADC should not be lower than the voltage you are trying to measure! First you should set the reference voltage at its highest value (4.5 V) using the potentiometer and by measuring it at the Ref. pin of PORTF
13
Software Design of the Voltmeter Mark Neil - Microprocessor Course 13 First ? Display a message on the LCD saying that the Voltmeter is ready to make a Measurement and ask the user if he wants to measure a voltage (capture data) Display a message on the LCD saying that the Voltmeter is ready to make a Measurement and ask the user if he wants to measure a voltage (capture data) Read in Input from PORTD or the Keyboard Read in Input from PORTD or the Keyboard Yes No Start Display the voltage on to the LCD Display the voltage on to the LCD Initialize LCD Initialize the ADC Initialize LCD Initialize the ADC Decode the Input and if it is ‘ YES ’ then digitise a Voltage Decode the Input and if it is ‘ YES ’ then digitise a Voltage
14
Getting Started Mark Neil - Microprocessor Course 14 Use the user interface you created with the LCD display and the keyboard or the PORTD switches. Read about using the on-board ADC in the ATmega128 manual. Use the routines in the ADC1.inc program on the web page as a starting point, adding the relevant parts to your own code
15
ADC Driver routines Mark Neil - Microprocessor Course 15.def TempReg = r16.def ADCChannel = r18.def ADCDL = r19.def ADCDH = r20 ADCInit:; ******* ADC Setup Code **** ldi TempReg, $83; ADC Interrupt Disabled, ADC Enable out ADCSR, TempReg; ADC Free Run Mode, Prescaler:CK/8 ret ADCsel: out ADMUX, ADCChannel; Channel Selection ret DCATrig: SBI ADCSR, 6; Cause a Conversion ADCCLR:SBIS ADCSR, 4; Wait till the Interrupt flag RJMP ADCCLR; is cleared SBI ADCSR, 4; Reset ADIF IN ADCDL, ADCL; Read in Low Byte IN ADCDH, ADCH; Read in High Byte RET
16
Some gotchas! Mark Neil - Microprocessor Course 16 You really want to be able to display something meaningful on the LCD The voltage in units of Volts Scaling your binary value to the correct level will require some arithmetic Multiply operands are available on the ATmega128 Divide is not Convert binary values to decimal for display See “extra-examples” file for some ideas on how to do this Or set your voltage levels to make the calculation easier…
17
Binary to Dec conversion using multiply Mark Neil - Microprocessor Course 17 Set Vref so 1V reads as $100=256 Read ADC output as VH:VL VH: units of 1V Multiply VL by 10, result to VH:VL VH: units of 0.1V Multiply VL by 10, result to VH:VL VH: units of 0.01V mul r16, r17 ; Unsigned multiply of r16 by r17 ; 16-bit result stored in R1:R0
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.