Explain the introduction to ADC ADC characteristics Programming































- Slides: 31
Explain the introduction to ADC, ADC characteristics, Programming ADC using PIC 18, Introduction to DAC and DAC interfacing with PIC 18. ADC and DAC Data Converter
Objectives Discuss the ADC of the PIC 18 Explain the process of data acquisition using ADC Program the PIC 18’s ADC in assembly Describe the basic operation of DAC Interface a DAC chip to the PIC 18
Introduction to ADC Digital Computer: Binary (discrete) values Physical World: Analog (continuous) values Example: Temperature, Humidity, Pressure Output: Voltage or Current Microcontroller? -----> Digital Therefore, ADC is needed to translate (convert) the analog signals to digital numbers
Introduction to ADC (Cont’d) Microcontroller Connection to Sensor via ADC
ADC Resolution n-bit No. of steps Step size (m. V) 8 28 = 256 5/256 = 19. 53 10 210 = 1024 5/1024 = 4. 88 12 212 = 4096 5/4096 = 1. 2 Assuming VREF = 5 V * Step Size (Resolution): is the smallest change that can be discerned by an ADC
ADC Reference Voltage (Vref) Vref: Input voltage used for the reference voltage The voltage connected to this pin , with the resolution of the ADC chip, dictate the step size Example: If we need the analog input to be 0 to 4 volts, Vref is connected to 4 volts Digital data output: 8 -bit (D 0 -D 7), 10 -bit (D 0 D 9)
ADC Reference Voltage (Vref) (Cont’d) Vref (V) Vin (V) Step size (m. V) 5. 00 4. 096 0 to 5 0 to 4. 096 5/1024 = 4. 88 4. 096/1024 = 4 3. 0 2. 56 2. 048 0 to 3 0 to 2. 56 0 to 2. 048 3/1024 = 2. 93 2. 56/1024 = 2. 5 2. 048/1024 = 2 Vref Relation to Vin Range for an 10 -bit ADC
ADC Digital Data Output Dout = Vin / Step Size Analog Input Voltage Digital data output (in decimal): 8 -bit (D 0 -D 7)= 256 10 -bit (D 0 -D 9) = 1024 Example: Vref = 2. 56, Vin = 1. 7 V. Calculate the Do-D 9 output? Solution: Step Size = 2. 56/1024 = 2. 5 m. V Dout = 1. 7/2. 5 m. V = 680 (Decimal) D 0 -D 9 = 101000
Parallel versus Serial ADC
PIC 18 F 4580 ADC Features
PIC 18 F 4580 ADC Features (cont’d) It has 11 analog input channels (AN 0 – AN 10) 10 -bit ADC Converted values are stored in ADRESH: ADRESL registers
ADC: Important Registers A/D Control Register 0 (ADCON 0) Controls the operation of the A/D module A/D Control Register 1 (ADCON 1) Configures the functions of the port pins A/D Control Register 2 (ADCON 2) Configures the A/D clock source, programmed acquisition time and justification
A/D Control Register 0 (ADCON 0) Example: Different from the Book! ADCON 0 = 00101001
A/D Control Register 1 (ADCON 1) * Different from the Book!
ADC PCFGs Example: ADCON 1 = 00001110 * Different from the Book!
A/D Control Register 2 (ADCON 2) Example: ADCON 2 = 10000110 * Different from the Book!
ADC ADFM Bit and ADRESx Registers
Example 1 For a PIC 18 -based system, we have Vref = Vdd = 5 V. Find a) The step size and b) The ADCON 1 value if we need 3 channels. a) The step size = 5/1024 = 4, 8 m. V b) ADCON 1 = 00001100
ADC Conversion Time Define in term of Tad (Conversion time per bit) To calculate: FOSC/2, FOSC/4, FOSC/8, FOSC/16, FOSC/32 or FOSC/64
Steps in Programming the ADC using Pooling TURN ON the ADC module (BSF ADCON 0, ADON) Make the ADC channel pin as input pin Select voltage reference and ADC channel Select the conversion speed Wait for the required acquisition time Activate the start conversion bit of GO/DONE Wait for the conversion to be completed by pooling the end-of-conversion GO/DONE bit After the GO/DONE bit has gone LOW, read the ADRESL and ADRESH register
Example 2 ORG CLRF BSF MOVLW MOVWF 0000 H TRISC TRISD TRISA, 0 0 x 00 ADCON 0 0 x 0 E ADCON 1 0 x. BE ADCON 2 OV ER CALL BSF BACK BTFS BRA MOVFF CALL BRA END DELAY ADCON 0, GONE BACK ADRESL, PORTC ADRESH, PORTD QSEC_DELAY OVER
Programming ADC using Interrupts Interrupt Flag Bit ADIF (ADC) ADIF Register Enable Bit Register PIR 1 ADIE PIE 1 ADC Interrupt Flag Bits and Associated Registers * Please see Program 13 -2 page 514
Introduction to DAC Covert digital pulses to analog pulses DAC 0808 chip: Use R/2 R method, 8 -bit DAC Block Diagram
DAC Application
DAC 0808 The digital inputs are converted to current (Iout) Connecting a resistor to the Iout pin, we convert the result to voltage This will course inaccuracy because the Resistance will affect the reading Iout = Iref (D 7/2 + D 6/4 + D 5/8 + D 4/16 + D 3/32 + D 2/64 + D 1/128 + D 0/256) Iref = Generally set to 2. 0 m. A
PIC 18 Connection to DAC 0808 and Op-Amp Example: Binary input: 1001 Iout = 2 m. A (153/256) = 1. 195 m. A and Vout = 1. 195 m. A x 5 K = 5. 975 V
ADC Sensor Interfacing Gas Sensor Temperature Sensor Sonar Sensor Humidity Sensor
ADC Sensor Interfacing (Cont’d) Characteristic: 1) 2) 3) 4) Precision integrated-circuit Output voltage is linearly proportional to the Celcius Requires no external calibration (Internally calibration) Output: 10 m. V for each degree
ADC Sensor Interfacing (Cont’d) 10 m. V = 1 degree (Minimum) 20 m. V = 2 degree 30 m. V = 3 degree. . 1000 m. V = 100 degree (Maximum) How to set Vref? ? 5 V Step Size = 4. 8 m. V Vin (max) = 5 V 1. 024 Step Size = 1 m. V Vin (max) = 1. 024 V Vref = ? ? ? Which one suitable?
ADC Sensor Interfacing (Cont’d) To overcome any fluctuations in power supply. * Please see Program 13 -4 page 524
“Things are only impossible until they're not” End of Chapter