Device Drivers Digital Voltmeter 1162022 Costas Foudas Imperial

  • Slides: 13
Download presentation
Device Drivers – Digital Voltmeter 1/16/2022 Costas Foudas, Imperial College, Rm: 508, x 47590

Device Drivers – Digital Voltmeter 1/16/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 1

Analog to Digital Converters The ANALOG to DIGITAL CONVERTERS (ADC) are devices that measure

Analog to Digital Converters The ANALOG to DIGITAL CONVERTERS (ADC) are devices that measure analog signals and convert them to numbers: Higher Voltage Ref. Input Pulse Lower Voltage Ref. 1/16/2022 D 9 Input 10 -bit ADC 10 -bit Number out D 0 Costas Foudas, Imperial College, Rm: 508, x 47590 2

The ATmega 103 ADC The Atmega 103 has one 10 -Bit ADC (on-chip) connected

The ATmega 103 ADC The Atmega 103 has one 10 -Bit ADC (on-chip) connected to an 8 to 1 analog multiplexer: Higher Voltage Ref. Potentiometer Adjustable 0 -4. 5 Volts (PORT F) EN_ADCH Input 8 -1 10 -bit Multiplexer ADC INPUT PORTF 1/16/2022 3 -bit MUX Control D 9 D 8 ADCH D 7 ADCL D 0 EN_ADCL Lower Voltage Ref. Fixed at 0 Volts CLK Costas Foudas, Imperial College, Rm: 508, x 47590 8 -bit ATmega 103 Bus 3

The ADC Registers I The 10 -bit ADC on Atmega 103 receives its inputs

The ADC Registers I The 10 -bit ADC on Atmega 103 receives its inputs from PORTF. The Reference voltage is controlled by a potentiometer. The device can be controlled by 4 on board registers: (1) ADCSR : ADC Status Register (2) ADMUX : Multiplexer Control (3) ADCH : Data Register for D 9, D 8 (4) ADCL : Data Register for D 0 -D 7 1/16/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 4

The ADC Registers II The ADC Status Register DCSR : D 7 D 6

The ADC Registers II The ADC Status Register DCSR : D 7 D 6 D 5 D 4 D 3 D 2 ADEN ADSC 0 ADIE ADPS 2 ADPS 1 ADIF D 1 D 0 ADPS 0 ADEN : It turns on the ADC clock (You must do it first) ADSC : Start conversion 0 : The data book says it should always be zero 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 I have not used interrupts so I have kept it ‘ 0’) ADPS 0 -2 : Three bits that determine the ADC clock prescale (e. q. 3 = 1/8) 1/16/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 5

The ADC Registers III The ADC Multiplexer Register ADMUX is used to select a

The ADC Registers III The ADC Multiplexer Register ADMUX is used to select a channel to digitize (3 bits for Channel 0 -7) : D 7 D 6 D 5 D 4 D 3 1/16/2022 D 1 D 0 MUX 2 MUX 1 MUX 0 Costas Foudas, Imperial College, Rm: 508, x 47590 6

The ADC Registers IV The ADC Data Register ADCL is used for the 8

The ADC Registers IV The ADC Data Register ADCL is used for the 8 lower data bits (D 7 - D 0) : D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 The ADC Data Register ADCH is used for the two highest data bits (D 9, D 8) : D 7 1/16/2022 D 6 D 5 D 4 D 3 D 2 Costas Foudas, Imperial College, Rm: 508, x 47590 D 1 D 0 D 9 D 8 7

Task Plan Design and construct a Digital Voltmeter: The Atmega 103 on-chip ADCs should

Task Plan Design and construct a Digital Voltmeter: The Atmega 103 on-chip ADCs should be used to digitize 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 !!!! 1/16/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 8

Conceptual Design l We want to construct : Connector LCD INTERFACE ATmega 103 Board

Conceptual Design l We want to construct : Connector LCD INTERFACE ATmega 103 Board Analog LCD DISPLAY HITACHI LM 032 XMBL +5 Volts Use ADC 0 10 K PORTD Buttons 1/16/2022 Voltage to be measured Costas Foudas, Imperial College, Rm: 508, x 47590 9

Some Important points : The Voltage you are trying to measure is obviously between

Some Important points : The Voltage you are trying to measure is obviously 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 1/16/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 10

Software Design of the Voltmeter Start First ? Yes Initialize LCD Initialize the ADC

Software Design of the Voltmeter Start First ? Yes Initialize LCD Initialize the ADC No 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 1/16/2022 Display the voltage on to the LCD Yes Decode the Input and if it is ‘YES’ then digitize a Voltage Costas Foudas, Imperial College, Rm: 508, x 47590 No 11

Getting Started (1) Use the user interface you created with the LCD display and

Getting Started (1) Use the user interface you created with the LCD display and the keyboard or the PORTD switches. (2) Read about using the on-board ADC in the ATmeag 103 manual. (3) Use the routines you will find in the ADC 1. inc program in the web page. (4) ADC 1. inc is a standalone program that works you may want to start from that. 1/16/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 12

ADC Driver routines. def Temp. Reg =r 16 ADCInit: ; ******* ADC Setup Code

ADC Driver routines. def Temp. Reg =r 16 ADCInit: ; ******* ADC Setup Code **** ldi Temp. Reg, $83 ; ADC Interrupt Disabled, ADC Enabled out ADCSR, Temp. Reg ; ADC Free Run Mode, Prescaler: CK/8 ret ADCsel: DCATrig: ADCCLR: 1/16/2022 out ADMUX, ADCChannel ret SBI ADCSR, 6 rcall DEL 600 mus IN ADCDL, ADCL IN ADCDH, ADCH SBI ADCSR, 4 IN Temp. Reg, ADCSR SBIC ADCSR, 4 RJMP ADCCLR RET ; Channel Selection ; Cause a Conversion ; Read in Low Byte ; Read in High Byte ; Reset ADIF ; Read in Status ; Wait till the Interrupt flag ; is cleared Costas Foudas, Imperial College, Rm: 508, x 47590 13