You are on page 1of 79

Interfacing Input

Minggu Ke-14
Sistem Mikroprosesor
DISPLAY INTERFACING
7 Segment - Display
• There are two important types of
7-segment LED display.
• Common cathode display
– the cathodes of all the LEDs are
joined together and the individual
segments are illuminated by HIGH
voltages.
• Common anode display
– the anodes of all the LEDs are
joined together and the individual
segments are illuminated by
connecting to a LOW voltage.
Basic LED Operations
• To Turn an LED ON
• The ANODE must be at a higher
voltage potential (up to 3V) than
the CATHODE.
• The amount of current flowing
through the LED will determine
the brightness of the LED.
• The amount of current is
controlled by a series resistor.
LED

• When an electron meets a hole, it falls into a


lower energy level, and releases energy in the
form of a photon.
7 Segment Construction
Calculating Resistor (Limiter)
• LTS-4801JR Common Anode
Seven-Segment Display
Luminous Intensity vs.
Forward Current Graph
• Pick a luminous intensity of
1.5 (not too bright, not too
dim).
• From the graph, we need a
current of 15mA.
• The voltage across the LED
(when on) is 1.5 volts.
• Using Ohm’s Law :

5 − 1.5
R= = 233.33 → R = 220
15mA
Connections

Can a microcontroller supply or sink enough current?


BCD to 7 Segment Decoder

Reduces the number of ports on microcontroller to drive a 7 segment.


Higher current drives
• At most a port pin can
sink 20mA.
• It is even less for
sourcing.
Higher current drives
• A better design
• Calculate R using βdc
• 16 mA is enough to lit
an LED
Multiple 7 Segments - Multiplexing

• A timer interrupt could be used to switch from one display to the next. For
example, timer zero could be set to interrupt once every five milliseconds. The
operation of the timer zero ISR would be:
– Turn off all displays by setting the display enable port pins.
– Send data for next display to the data port.
– Turn on next display (if current display is 4, next display is 1) by clearing the appropriate
enable port pin.
Example
http://embedded-lab.com/blog/lab-11-multiplexing-seven-segment-led-displays/
SENSORS - TEMPERATURE
Temperature Sensing
• Thermoresistive : resistance changes with
temperature
• Thermoelectric : voltage changes with
temperature
• Semiconductor junction : using semiconductor
property that changes with temperature
• Thermoswitches : expansion of two different
metal
Resistance Temperature Detector
(RTD)
• Resistance is a function of temperature
• α is temperature coefficient
– Nickel 0.0067
– Platinum 0.0039 Rnew = Rold (1 +  (Tnew − Told ) )
– Copper 0.0038
• Example
• A nickel RTD has a resistance of 200Ω at 100°C. Calculate
the resistance at 150°C.
– R = 200*(1 + 0.0067*(150 - 100)) = 267 Ω
• A nickel RTD has a resistance of 140Ω at 25°C. Calculate the
resistance at -10°C.
– R = 140*(1 + 0.0038*(-10 - 25)) = 121.38 Ω
RTD construction
• The advantages of platinum
resistance thermometers
include:
– High accuracy
– Low drift
– Wide operating range
– Suitability for precision
applications
• Standard platinum Resistance
Thermometers (SPRTs)
– 0.385 ohm/°C
– -200°C to 1000°C
– approximately accurate to
±0.001°C
RTD interface
• Two wire RTD
RTD interface
• Three wire RTD

• Needs a Differential Amplifier to interface -> instrumentation


amplifier
• Be aware of self-heating
– Power (I2R) is dissipated in the RTD
– Keep current to minimum
• Calibration :
– we want Vout=0V at 0°C.
– Looking at RTD data, 0°C is at 100Ω so Rcal = 100Ω assuming R1=R2
Thermistor
• Another type of thermoresistive device
Thermistors differ from RTD in
that the material used in a
thermistor is generally a
ceramic or polymer, while
RTDs use pure metals.

Thermistors typically achieve a higher precision within a limited


temperature range, typically −90 °C to 130 °C
Thermistor Basic Operations
ΔR= change in resistance
R = kT ΔT = change in temperature
K = first-order temperature coefficient of
resistance
• Thermistors can be classified into two types, depending
on the sign of k.
– k > 0 : the resistance increases with increasing
temperature
• positive temperature coefficient (PTC) thermistor, or posistor.
– k < 0 : the resistance decreases with increasing
temperature
• negative temperature coefficient (NTC) thermistor
• Instead of the temperature coefficient k, sometimes
the temperature coefficient of resistance αT is used
Thermistor Interface

• Uses bridge
configuration or non-
inverting amplifier
• Bridge is more precise
(does not depend on
voltage supply)
Thermoelectric Effect

• In 1821, the German–Estonian physicist Thomas Johann


Seebeck discovered that when any conductor is subjected
to a thermal gradient, it will generate a voltage.
• This is now known as the thermoelectric effect or Seebeck
effect
Thermocouple

Type J : Iron-Constantan : 50 mV
Type K : Chromel-Alumel : 56 mV
Type T : Copper-Constantan: 26 mV
Thermoelectric Interfacing
• Sensitive to Noise
Solution

RTD to measure reference junction


temperature

• Corrected voltage = Measured voltage + Reference Voltage


Semiconductor Junction devices
• Uses Diode property

(
i = IS ev /VT − 1 )
kT
VT =
q
VT
rd =
I
Reverse Bias (no current flow)
Temperature changes the resistance
Using Semiconductor Sensor

Linear output of 10 mV/̊C


Range -25 C to 85 C
Thermoswitches
• Bimetal expansion
• A material will expand and
contract as a function of
temperature
• ϒ is temperature coefficient
of linear expansion

Lnew = Lold (1 +  (Tnew − Told ) )


SENSORS - OPTICAL
Optical Sensing
• Two type of function
– Detect light
– Measure light intensity (CCD camera)
• We are interested more in detecting light type
rather than measuring light intesity
• Device to detect light
– Photoconductive
– Photodiodes
– Phototransistor
– Integrated optical sensor
Photoconductive
• Photoconductivity is an
optical and electrical
phenomenon in which a
material becomes more
electrically conductive
due to the absorption
of electromagnetic
radiation such as visible
light, ultraviolet light,
infrared light, or gamma
radiation
Photoresistor
• A photoresistor or light dependent
resistor (LDR) is a resistor whose
resistance decreases with increasing
incident light intensity
• Resistance range form several
hundred ohms in complete darkness
to a few hundred ohms in normal
room light
• Temperature range 0 to 50 C
• Take care of maximum current and
voltage rating
Interfacing
• Dark : 1MΩ and Light : 10KΩ
• Circuit A:
– Assume 12V supply and Rcal = 1MΩ
– V output when dark
• V = 1M/(1M+1M) * 12 = 6 V
– V output when bright
• V = 10K/(10K + 1M) * 12 = 11.88 V
• Circuit B
– Assume 1V input and Rcal = 100KΩ
– V output when dark
• V = (100K/1M + 1) * 1 = 1.1 V
– V output when bright
• V = (100K/10K + 1) * 1 = 11 V
Photovoltaic and Photodiode
• Direct conversion from light to voltage
• Photodiode
• Can operate as
photoconductive or
photovoltaic
• Photovoltaic
Photovoltaic Mode
• Light Photon strikes the P
material atoms and the
electron becomes free
• The free electron attracts
holes on the N layer
• The electron-hole pairs
creates a depletion region
(VD)
• As more photon strikes, the
depletion region grew larger
• VD depends on the light
intensity
Photodiode Mode

• By putting the diode in reverse bias, there is a


large depletion region around the PN junction.
• Large depletion means high resistance (so high ->
no current)
• When photon strikes the resistance is lowered.
Interface
• Dark current : 10 nA
• Light current : 10 μA
• Circuit A
– Assume 1 MΩ Rf
– V in darkness
• V = - (10 n)(1 M) = -0.01 V
– V in bright light
• V = - (10 μ)(1 M) = -10 V
Phototransistor
• Photodiode mode
• Plus an amplifier
• Produces much more
current than photodiode
• Slower than photodiodes
Integrated Optical Sensor
• Contains light source
and detector
• A : photo interrupter
• B : photo reflector
• Works the same as
photodiode or
phototransistor
• Light source outside
visible range
Interfacing
• Put a current
limiting resistor
• Can also add a
signal conditioner
• When used as an
interuptor, the
output is a pulse
Application
• Detect speed
(RPM)
• Detect speed and
angular position
• Detect speed and
linear position
SENSOR - POSITION
Resistive Sensor

• Position sensing
• Resolution depends on
the number of wire
turn
– % resolution = 100/N
• If a resistor has 2000
turns
– % resolution is
100/2000 = 0.2%
Interfacing

• Problem of loading
• If the sensor is at the middle, Vout = 6 V
• Let say that we connect the sensor to a signal
conditioning circuit that has a load of 5 KΩ.
– Vout = (5K || 5K)/(5K + (5K || 5K))*12 V = 4 V
• Need an opamp with unity gain so that the load
resistance is very large
Capacitive sensor
 o KA 1
C= →C 
d d
ε0 is the permittivity of free space constant
K is the dielectric constant of the material
A is the area of the plates
d is the distance between the plates

• There are two general types of capacitive displacement


sensing systems.
– One type is used to measure thicknesses of conductive
materials.
– The other type measures thicknesses of non conductive
materials or the level a fluid.
Position sensing
1
XC =
2 f C

• Need an AC
supply with
constant
frequency f
Interfacing
Rectifier Filter

V sensor +
with
constant f
Vout
(DC)
-

• Rectifier convert AC signal into DC signal


• Filter : filters AC component
• Vout is the Average AC signal
Interfacing
R

+ +

V RL Vpeak
sensor (DC)
with
constant f
-

• Peak detector (positive peaks) T


CRD 
• T : Period of input waveform 10
CRL  10T
Applications
• Precision positioning
– One of the more common
– Capacitive displacement sensors can be used to measure the position
of objects down to the nanometer level.
– This type of precise positioning is used in the semiconductor industry
where silicon wafers need to be positioned for exposure.
– Capacitive sensors are also used to pre-focus the electron microscopes
used in testing and examining the wafers.
• Disc drive industry
– Capacitive displacement sensors are used to measure the runout (a
measure of how much the axis of rotation deviates from an ideal fixed
line) of disc drive spindles.
– By knowing the exact runout of these spindles, disc drive
manufacturers are able to determine the maximum amount of data
that can be placed onto the drives.
– Capacitive sensors are also used to ensure that disc drive platters are
orthogonal to the spindle before data is written to them.
Inductive Sensor

( rN )
2

L= r
9r + 10l

• L inductance in μH
• r radius
• N number of turns
• l is effective length
• μr is the relative permeability
– Air 1
– Iron 7000, etc
Position sensing

X L = 2 f L
• Needs an AC voltage source with constant
frequency
• Interfacing is the same as capacitive sensors
More accurate position sensing
• Linear variable differential transformer (LVDT)

• Like a bridge
• Vout = 0 when core is in the middle position
More accurate position sensing
• Linear variable differential transformer (LVDT)
SENSOR - PROXIMITY
Proximity Sensor
• Capacitive sensor

• Works with conductive or non-conductive materials


• A particular sensor only works on certain materials
Proximity sensing

• Produce magnetic field


• When a metallic object enters the magnetic field
– An eddy current is produced in the object
– The eddy current produces a magnetic field that opposes
the original magnetic field
• The net effect reduces the voltage is the coil
• The decrease of voltage is proportional to the
magnitude of the eddy currents (eddy current probes)
Magnetic Sensor
• Reed switch
Hall Effect devices

• Hall effect : current is affected by


a magnetic field
• Requires a strong magnetic field
Hall effect sensor application
• Hall sensor is combined with circuitry that allows the
device to act in a digital (on/off) mode, and may be called a
switch in this configuration.
• Commonly seen in industrial applications such as the
pictured pneumatic cylinder, they are also used in
consumer equipment;
– for example some computer printers use them to detect
missing paper and open covers.
– When high reliability is required, they are used in keyboards.
• Hall sensors are commonly used to time the speed of
wheels and shafts, such as for internal combustion engine
ignition timing, tachometers and anti-lock braking systems.
• They are used in brushless DC electric motors to detect the
position of the permanent magnet.
SENSOR - FORCE
Force Sensing
• Compressed Strain
• Tensile Strain
• Shear Strain
• Most sensor just measure compressed and
tensile strain (Strain gages)
L
Strain =
L
Resistive
R = 2Rold  Strain
L
Strain =
L

GF is gage factor (sensitivity)

R
GF = R
Strain
Interfacing
 R2 Rcal 
Vout = −  Vin
 R1 + R2 Rg + Rcal 

• If the bridge is balanced Vout = 0 for unstrained condition


• If not balance, not a problem since we can measure the
unstrained condition voltage.
 Vout   Vout  −4Vr
Vr =   −  Strain =
V V
 in  unstrained  in  strained GF (1 + 2Vr )
Other Strain gage

• Semiconductor strain gage


– Small size
– Extreme sensitivity
• Piezo Electric Strain Gage
– Produce voltage proportional
to force
– Only produces voltage on
dynamic forces
Load Cell
• Integrated Strain gage to measure weight
INPUT KEYPAD
Matrix Keypad
• Keypads are a part of HMI or Human Machine Interface
and play really important role in a small embedded
system where human interaction or human input is
needed.
Scanning a Matrix Keypad
• In order to detect which key is pressed from the
matrix, we make column lines low one by one and
read the rows. Lets say we first make C1 low, then
read the rows.
If any of the key in C1 is
pressed will make the
corresponding row as low i.e.
if second key is pressed in C1,
then R2 will give low
Scanning a Matrix Keypad
• The rows R0 to R3 are connected to Input lines of
Microcontroller. The i/o pins where they are
connected are made as Input (DDRx).
The column C0 to C3 are also
connected to MCUs i/o line.
These are kept at Hi-Z State,
these pins are neither HIGH or
LOW they are in TRISTATE.
Set Portx=0, when DDRx=1
then the output becomes low.
Scanning a Matrix Keypad
Z L Z Z

Read
Value
• Why we make other Columns High Impedance
while one column is made LOW?
H L H H

Short Circuit !!
Hardware connections
PA0 PA1 PA2 PA3 • Using PortA
• PA0-3 as output
PA4 • PA4-7 as input
PA5

PA6
PA7
Remember Port I/O
• To set Hi-Z on PA0-3
– DDRA = 0x00
– PortA = 0x00
• To set Low on PA0-3
– DDRA = 0x0F
– PortA = 0x00
• To set Input and Pull-
Up on PA4-7
– DDRA = 0x00
– PortA = 0xF0
Scanning Keypad
• Step 1 : make all column Hi-Z (also PA4-7 as input with
pull-up)
– DDRA = 0x00 and PortA=0xF0
• Turn on (make low) C1
– DDRA = 0x01
• Read Rows (R1-R4) (PA4-7)
– Key = PINA & 0xF0
– If any key on C1 is pressed, then the value should be low,
i.e key = 0x70 (R4-C1 is pressed)
– If no key is pressed the continue to C2, otherwise exit
• Turn on C2
– DDRA = 0x02
• Continue scanning….
Scanning Keypad
unsigned char GetKeyPressed()
{
unsigned char c;

for(c=1;c<=0x04;c=c<<1)
{
DDRA = c;
k = PINA & 0xF0;
if(k != 0xF0)
{
DDRA=0x00; // back to Hi-Z
return (k^0xF0 + c); // return key location (r,c)
}
}
return(0);//Indicate No key pressed
}

int main(void)
{
unsigned char key;
DDRA = 0x00;
PORTA = 0xF0; // Set PA for keypad scan, Hi-Z and Pull-ups
key = GetKeyPressed;
}

You might also like