Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter.

Similar presentations


Presentation on theme: "Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter."— Presentation transcript:

1 Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter

2 Analog to Digital Converters Mark Neil - Microprocessor Course 2 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 Pulse Input Pulse Input D9 D0

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 The ADC Registers I Mark Neil - Microprocessor Course 4 The 10-bit ADC on Atmega103 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

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 ADCCSR Mark Neil - Microprocessor Course 6 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)

7 The ADMUX Register Mark Neil - Microprocessor Course 7 The ADC Multiplexer Register ADMUX is used to select a channel to digitise (3 bits for Channel 0-7) :

8 The ADCH/ADCL Registers Mark Neil - Microprocessor Course 8 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

9 Task Plan Mark Neil - Microprocessor Course 9 Design and construct a Digital Voltmeter: The Atmega103 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 !!!!

10 Conceptual Design Mark Neil - Microprocessor Course 10 We want to construct : ATmega103 Board ATmega103 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

11 Some Important points : Mark Neil - Microprocessor Course 11 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

12 Software Design of the Voltmeter Mark Neil - Microprocessor Course 12 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

13 Getting Started Mark Neil - Microprocessor Course 13 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

14 ADC Driver routines Mark Neil - Microprocessor Course 14.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 rcall DEL600mus IN ADCDL, ADCL; Read in Low Byte IN ADCDH, ADCH; Read in High Byte ADCCLR:SBI ADCSR, 4; Reset ADIF IN TempReg,ADCSR; Read in Status SBIC ADCSR, 4; Wait till the Interrupt flag RJMP ADCCLR; is cleared RET


Download ppt "Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter."

Similar presentations


Ads by Google