AAAA
SEL–0629
Aplicação de
Microprocessadores I
Prática 3
Termômetro Digital
Prof. Marcelo Andrade da Costa Vieira
AA
Conv. A/D Display LCD e LM35
•
Objetivos:
•
Aprendizado do microcontrolador PIC18F45K22
•
Linguagem C
•
Estudo das bibliotecas do Mikro C
•
Uso do sensor de temperatura LM35, conversor A/D e
display de LCD
•
Prática:
•
Utilizar o conversor A/D para ler o valor de tensão em um
potenciômetro e mostrar no display de LCD.
•
Utilizar o conversor A/D para ler o valor de temperatura
AA
Conversor A/D
2010-2012 Microchip Technology Inc. DS41412F-page 297
PIC18(L)F2X/4XK22
17.0
ANALOG-TO-DIGITAL
CONVERTER (ADC) MODULE
The Analog-to-Digital Converter (ADC) allows conversion of an analog input signal to a 10-bit binary representation of that signal. This device uses analog inputs, which are multiplexed into a single sample and hold circuit. The output of the sample and hold is connected to the input of the converter. The converter generates a 10-bit binary result via successive approximation and stores the conversion result into the ADC result registers (ADRESL and ADRESH).
The ADC voltage reference is software selectable to either VDD or a voltage applied to the external reference pins.
The ADC can generate an interrupt upon completion of a conversion. This interrupt can be used to wake-up the device from Sleep.
Figure 17-1 shows the block diagram of the ADC.
FIGURE 17-1: ADC BLOCK DIAGRAM
Note: Additional ADC channels AN5-AN7 and AN20-AN27 are only available on PIC18(L)F4XK22 devices.
11111 11110 11101 11100 11011 FVR BUF2 DAC CTMU AN28(1) AN27(1) 00101 00100 AN5(1) AN4 00011 00010 AN3 AN2 00001 00000 AN1 AN0 5 CHS<4:0> 10-Bit ADC ADCMD ADON GO/DONE 10 0 = Left Justify 1 = Right Justify ADFM 10 ADRESH ADRESL 00 01 AVDD 10 11 FVR BUF2 Reserved VREF+/AN3 2 PVCFG<1:0> 00 01 AVSS 10 11 Reserved Reserved VREF-/AN2 2 NVCFG<1:0>
AA
Equações
AA
Modo 8 ou 10 bits
PIC18(L)F2X/4XK22
DS41412F-page 300 2010-2012 Microchip Technology Inc.
17.1.7
RESULT FORMATTING
The 10-bit A/D conversion result can be supplied in two
formats, left justified or right justified. The ADFM bit of
the ADCON2 register controls the output format.
Figure 17-2
shows the two output formats.
FIGURE 17-2:
10-BIT A/D CONVERSION RESULT FORMAT
ADRESH ADRESL (ADFM = 0) MSB LSB
bit 7 bit 0 bit 7 bit 0 10-bit A/D Result Unimplemented: Read as ‘0’
(ADFM = 1) MSB LSB
bit 7 bit 0 bit 7 bit 0 Unimplemented: Read as ‘0’ 10-bit A/D Result
AA
Parte 1:
Conversor A/D e Display de LCD
•
Programar em linguagem C e estudar as bibliotecas
disponíveis no Mikro C Pro (LCD e Conversor A/D).
•
Utilizar o conversor A/D do PIC18F45K22 para medir a tensão
de entrada nos pinos RA (0,1,2,3 ou 5) e RB (0,1,2,3 ou 4),
controlados por dois potenciômetros (trimpots);
•
Mostrar os valores lidos no display de LCD;
Linha 1 = AN0
Linha 2 = AN1
•
Utilizar três algarismos significativos com duas casas
AA
Parte 1:
Conversor A/D e Display de LCD
Digital signals have two discrete states, which are decoded
as high and low, and interpreted as logic 1 and logic 0.
Analog signals, on the other hand, are continuous, and can A/D converters are
specialized circuits which can convert analog signals (voltages) into a digital representation, usually in form of an integer
number. The value of this number is linearly dependent on
the input voltage value. Most microcontrollers nowadays internally have A/D converters connected to one or more input pins. Some of the most important parameters of A/D converters are conversion
time and resolution. Conversion time determines how fast can an
analog voltage be represented in form of a digital number. This is an important parameter if you need fast data acquisition. The other parameter is resolution. Resolution represents the number of discrete steps that supported voltage range can be divided into. It determines the sensitivity of the A/D converter. Resolution is represented in maximum number of bits that resulting number occupies. Most PIC® microcontrollers have 10-bit resolution, meaning that maximum value of conversion can be
represented with 10 bits, which converted to integer is 210=1024. This means that supported voltage range, for
example from 0-5V, can be divided into 1024 discrete steps of about 4.88mV.
EasyPIC™ v7 provides an interface in form of two potentiometers for simulating analog input voltages that can be routed to
any of the 10 supported analog input pins.
ADC inputs
P2 10K R64 220 P1 10K R63 220 J15 J16 VCC-MCU VCC-MCU RA2 RA1 RA0 RA3 RA5 RB2 RB1 RB0 RB3 RB4DATA BUS
Enabling ADC inputs
In order to connect the output of the potentiometer P1 to RA0, RA1, RA2,
RA3 or RA5 analog microcontroller inputs,
you have to place the jumper J15 in the desired position. If you want to connect potentiometer P2 to any of the RB0 – RB4 analog microcontroller inputs, place jumper
J16 in the desired position. By moving
the potentiometer knob, you can create voltages in range from GND to VCC. Figure 17-1: use J15 and J16 jumpers to connect analog input lines with potentiometers P1 and P2 page 30 Figure 17-2: Schematic of ADC input modules
Digital signals have two discrete states, which are decoded as high and low, and interpreted as logic 1 and logic 0. Analog signals, on the other hand, are continuous, and can A/D converters are specialized circuits which can convert analog signals (voltages) into a digital representation, usually in form of an integer number. The value of this number is linearly dependent on the input voltage value. Most microcontrollers nowadays internally have A/D converters connected to one or more input pins. Some of the most important parameters of A/D converters are conversion time and resolution. Conversion time determines how fast can an analog voltage be represented in form of a digital number. This is an important parameter if you need fast data acquisition. The other parameter is resolution. Resolution represents the number of discrete steps that supported voltage range can be divided into. It determines the sensitivity of the A/D converter. Resolution is represented in maximum number of bits that resulting number occupies. Most
PIC® microcontrollers have 10-bit resolution, meaning that maximum value of conversion can be
represented with 10 bits, which converted to integer is 210=1024. This means that supported voltage range, for
example from 0-5V, can be divided into 1024 discrete steps of about 4.88mV.
EasyPIC™ v7 provides an interface in form of two potentiometers for simulating analog input voltages that can be routed to
any of the 10 supported analog input pins.
ADC inputs
P2 10K R64 220 P1 10K R63 220 J15 J16 VCC-MCU VCC-MCU RA2 RA1 RA0 RA3 RA5 RB2 RB1 RB0 RB3 RB4DATA BUS
Enabling ADC inputs
In order to connect the output of the potentiometer P1 to RA0, RA1, RA2, RA3 or RA5 analog microcontroller inputs, you have to place the jumper J15 in the desired position. If you want to connect potentiometer P2 to any of the RB0 – RB4 analog microcontroller inputs, place jumper J16 in the desired position. By moving the potentiometer knob, you can create voltages in range from GND to VCC. Figure 17-1: use J15 and J16 jumpers to connect analog input lines with potentiometers P1 and P2 page 30 Figure 17-2: Schematic of ADC input
modules
AA
Parte 2:
Termômetro Digital com LM35
•
Programar em linguagem C e estudar as bibliotecas disponíveis
no Mikro C Pro
•
Utilizar o conversor A/D do PIC18F45K22 para medir a tensão
de entrada do LM35 (Porta RE1 ou RE2) em função da
temperatura.
•
Ajustar Vref + e Vref – para a faixa de tensão medida*.
•
Curva teórica que é 10mV/ºC
•
Calibrar o sistema utilizando um termômetro comercial.
•
Mostrar o valor lido no display de LCD utilizando três algarismos
significativos com uma casa decimal, na forma xx.x ºC.
AA
Parte 2:
Termômetro Digital com LM35
VO
UT
RE1
RE2
J25
D
A
T
A BUS
VOUT
GND
VCC
Figure 16-5: LM35 connected to RE1 pin The LM35 is a low-cost precisionintegrated-circuit temperature sensor, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to
obtain convenient Centigrade scaling. It has a linear +10.0 mV/°C scale factor
very low self-heating, less than 0.1°C
in still air. EasyPIC™ v7 enables you to
get analog readings from the LM35 sensor in restricted temperature range from +2ºC to +150ºC. Board provides a
separate socket (TS2) for the LM35 sensor in TO-92 plastic packaging. Readings are done with microcontroller using single analog input line, which is selected with jumper J25. Jumper connects the sensor with either RE2 or RE1 microcontroller pins.
EasyPIC™ v7 enables you to get analog readings from the LM35 sensor using
RE1 or RE2 microcontroller pins. The selection of either of those two lines is done using J25 jumper. When placing the sensor in the socket make sure that half-circle on the board’s silkscreen markings matches the rounded part of the LM35 sensor. If you accidentally connect the sensor the other way, it can be permanently damaged and you might need to replace it with another one. During the readings of the sensor, make sure that no other device uses the selected analog line, because it may interfere with the readings.
Figure 16-1: LM35 not connected Figure 16-2: LM35 placed in socket Figure 16-3: LM35 connected to RE1 pin Figure 16-4: LM35 connected to RE2 pin
Enabling LM35 Sensor
LM35 - Analog
Temperature Sensor
page 291
2
3
4
modules
VO
UT
RE1
RE2
J25
D
A
TA BUS
VOUT
GND
VCC
Figure 16-5: LM35 connected to RE1 pin The LM35 is a low-cost precisionintegrated-circuit temperature sensor, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to
obtain convenient Centigrade scaling. It has a linear +10.0 mV/°C scale factor
very low self-heating, less than 0.1°C
in still air. EasyPIC™ v7 enables you to
get analog readings from the LM35 sensor in restricted temperature range from +2ºC to +150ºC. Board provides a
separate socket (TS2) for the LM35 sensor in TO-92 plastic packaging. Readings are done with microcontroller using single analog input line, which is selected with jumper J25. Jumper connects the sensor with either RE2 or RE1 microcontroller pins.
EasyPIC™ v7 enables you to get analog readings from the LM35 sensor using
RE1 or RE2 microcontroller pins. The selection of either of those two lines is done using J25 jumper. When placing the sensor in the socket make sure that half-circle on the board’s silkscreen markings matches the rounded part of the LM35 sensor. If you accidentally connect the sensor the other way, it can be permanently damaged and you might need to replace it with another one. During the readings of the sensor, make sure that no other device uses the selected analog line, because it may interfere with the readings.
Figure 16-1: LM35 not connected Figure 16-2: LM35 placed in socket Figure 16-3: LM35 connected to RE1 pin Figure 16-4: LM35 connected to RE2 pin