Professional Documents
Culture Documents
Objectives
Upon completion of this chapter, you will be able
to:
– Explain the ADC programming in C
– Explain the DAC interfacing, Sensor and Actuator
interfacing.
– Discuss and apply the sensor and actuator system
interfacing.
ADC-to-DAC
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
• Analog-to-Digital Converter (ADC)
• Widely used in data acquisition (DAQ
• Sensor: To convert physical quantity to electrical
signal (in current or voltage)
– i.e. Temperature, pressure, humidity, velocity, sound,
etc.
1. LCD
2. 7-Segments
3. LEDs
ADC Resolution
n-bit No. of steps Step size (mV)
8 28 = 256 5/256 = 19.53mV
Assuming VREF = 5V
• The time it’s take the ADC to convert the analog input
to digital. The time is dictated by the clock source
connected to the ADC in addition to the method used
for data conversion and fabrication technology e.g.
MOS or TTL technology.
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 (D0-D7), 10-bit (D0-D9)
Vref (V) Vin (V) Step size (mV)
5.00 0 to 5 5/1024 = 4.88
4.096 0 to 4.096 4.096/1024 = 4
3.0 0 to 3 3/1024 = 2.93
2.56 0 to 2.56 2.56/1024 = 2.5
2.048 0 to 2.048 2.048/1024 = 2
ADC Digital Data Output
void main ( )
{
unsigned char x;
TRISB =0;
While (1)
{
for(x=0;x=12;x++
PORTB = WAVEVALUE(x);
}
}
ADC Sensor Interfacing
Characteristic:
1) Precision integrated-circuit
2) Output voltage is linearly proportional to the Celcius
3) Requires no external calibration (Internally calibration)
4) Output: 10mV for each degree
10mV = 1 degree (Minimum)
20mV = 2 degree
30mV = 3 degree
.
.
How to set
Vref ??
Step Size Vin (max)
5V
= 4.8mV = 5V
Which
one
suitable?
Vref = ??? 1.024 Step Size Vin (max)
= 1mV = 1.024V
Vref To overcome any fluctuations in power supply.
Temp (C°) Vin (mV) #of Step Binary
(Decimal) Vout(b9-b0)
5 50 20 0000010100
15 150 60 0000111100
25 250 100 0001100100
30 300 120 0001111000
50 500 200 0011001000
70 700 280 0100011000
100 1000 400 0110010000
void main ( )
{
unsigned char L_Byte, H_Byte, Bin_Temp;
TRISD =0; //make PD output port
TRISAbits.TRISA0=1; //RA0 = INPUT for analog input
TRISAbits.TRISA2=1; //RA2 = INPUT for vref input
ADCON0=0x81; //Fosc/64, channel 0, A/D is on
ADCON1=0xC5; //right justified, Fosc/64
//AN0 = analog, AN3 = vref+
while(1)
{
MSDelay (1); //give A/D channel time to sample
ADCON0bits.GO = 1; //start converting
While(ADCON0bits.DONE == 1; //wait for EOC
L_Byte=ADRESL; //save the low byte
H_Byte=ADRESH; //save the high byte
L_Byte >>=2; //shift right
L_Byte &=0x3F //mask the upper two byte
H_Byte <<=6; //shift right 6 times
H_Byte&=0xC0; //mask the lower 6 bits
Bin_Temp= L_Byte|H_Byte
PORTD=Bin_Temp;
}
}