Professional Documents
Culture Documents
PIC18 ADC and DAC Data Converter
PIC18 ADC and DAC Data Converter
PIC18 ADC and DAC Data Converter
with PIC18.
Discuss the ADC of the PIC18 Explain the process of data acquisition using ADC Program the PIC18s ADC in assembly Describe the basic operation of DAC Interface a DAC chip to the PIC18
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
n-bit 8 10 12
Assuming VREF = 5V
* Step Size (Resolution): is the smallest change that can be discerned by an ADC
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 (D0-D7), 10-bit (D0D9)
Vin (V) 0 to 5
It has 11 analog input channels (AN0 AN10) 10-bit ADC Converted values are stored in ADRESH:ADRESL registers
Example:
Different from the Book!
ADCON0 = 00101001
Example:
ADCON2 = 10000110
For a PIC18-based system, we have Vref = Vdd = 5V. Find a) The step size and b) The ADCON1 value if we need 3 channels.
a) The step size = 5/1024 = 4,8mV b) ADCON1 = 00001100
Define in term of Tad (Conversion time per bit) To calculate: FOSC/2, FOSC/4, FOSC/8, FOSC/16, FOSC/32 or FOSC/64
TURN ON the ADC module (BSF ADCON0, 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
ORG CLRF CLRF BSF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF
0000H TRISC TRISD TRISA, 0 0x00 ADCON0 0x0E ADCON1 0xBE ADCON2
OV ER CALL BSF BACK BTFS BRA MOVFF MOVFF CALL BRA END
DELAY ADCON0, GO ADCON0, GONE BACK ADRESL, PORTC ADRESH, PORTD QSEC_DELAY OVER
Interrupt
Flag Bit
Register PIR1
Register PIE1
Covert digital pulses to analog pulses DAC0808 chip: Use R/2R method, 8-bit
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 (D7/2 + D6/4 + D5/8 + D4/16 + D3/32 + D2/64 + D1/128 + D0/256)
Iref = Generally set to 2.0mA
Example:
Binary input: 10011001 Iout = 2mA (153/256) = 1.195mA and Vout = 1.195mA x 5K = 5.975V
Gas Sensor
Sonar Sensor
Temperature Sensor
Humidity Sensor
Characteristic: 1) 2) 3) 4) Precision integrated-circuit Output voltage is linearly proportional to the Celcius Requires no external calibration (Internally calibration) Output: 10mV for each degree
10mV = 1 degree (Minimum) 20mV = 2 degree 30mV = 3 degree . . . . 1000mV = 100 degree (Maximum)
5V
Vref = ???
Vin (max) = 5V
Vin (max) = 1.024V
1.024