Lecture37interfacing Issues
Lecture37interfacing Issues
The
The microprocessor
microprocessor cannot
cannot measure
measure current
current directly.
directly. AA small
small resistance
resistance R R is
is inserted
inserted inin series
series with
with the
the
ground
ground conductor
conductor andand the
the voltage
voltage onon this
this resistor
resistor isis measured
measured by by the
the microprocessor
microprocessor usingusing it’s
it’s A/D
A/D
converter
converter (Fig.
(Fig. 12.8).
12.8). The
The converter
converter cancan resolve
resolve down
down to to 5V/2
5V/2 == 1.22
12
12
1.22 mV.
mV. That
That means
means thatthat to
to sense
sense up up to
to
500 mA in increments of 10 mA we need 50 increments of 1.22 mV. That is,
500 mA in increments of 10 mA we need 50 increments of 1.22 mV. That is, the maximum voltage drop the maximum voltage drop
across
across the
the sensing
sensing resistor
resistor isis 50*1.22
50*1.22 == 61
61 mV.
mV. The
The resistor
resistor is
is RR == 0.061/0.5 0.122 .
0.061/0.5 == 0.122 .
In
In Range
Range B, B, we
we must
must be be able
able toto measure
measure 500/0.5
500/0.5 == 1,000
1,000 increments
increments of of 1.22
1.22 mV mV each.
each. That
That means
means the the
voltage
voltage across
across the
the sensing
sensing resistor
resistor must
must bebe 1.22
1.22 VV and
and the
the resistance
resistance must must bebe R 2.44 .
R == 2.44 .
The
The resistance
resistance inin range
range A A is
is acceptable,
acceptable, that
that for
for Range
Range B B is
is not.
not.
Instead,
Instead, the
the resistor
resistor is
is selected
selected as as R 0.122
R == 0.122 and
and aa non-inverting
non-inverting operational
operational amplifier
amplifier with
with aa gain
gain of
of 20
20
is
is added
added asas shown
shown inin Fig.
Fig. 12.8b.
12.8b. This
This boosts
boosts thethe maximum
maximum voltage
voltage at at the
the microprocessor’s
microprocessor’s input input to
to
0.061*20 = 1.22 V. Using the configuration in Fig. 12.8b, the gain is
0.061*20 = 1.22 V. Using the configuration in Fig. 12.8b, the gain is (see Eq. 11.7): (see Eq. 11.7):
Fig. 12.8
Response and frequency
Most sensors are slow devices
Can be interfaced directly
No concern for response and frequency range
Some sensors are part of oscillators
Frequencies may be quite high
Need to worry about proper sampling by the microprocessor
Example: 10 mHz P, cycle time of 0.4 s. (most processor divide
the clock frequency by a factor - 4 in this case)
Any operation such as reading an input requires n cycles, say n=5
Effective frequency: 0.5 MHz
Sampling cannot be done at rates higher than about 250 kHz
Any sensor producing a signal above this frequency will be read
erroneously
Response and frequency
Some solutions:
Divide the sensor’s frequency
Reduces sensitivity
Must be done externally to the P
F-V converter
Introduces conversion errors
Must be done externally
External frequency counter at input
Use output of the counter as input to P.
Expensive
Faster microprocessors
Example
Quartz crystal microbalance:: Consider
Consider aa microbalance
microbalance resonating
resonating at
at 18
18 MHz
MHz with
with aa sensitivity
sensitivity of
of
55 ng/Hz/cm
ng/Hz/cm22.. The
The sensor
sensor is is used
used to
to sense
sense the
the mass
mass of
of substances
substances coated
coated on
on the
the electrode.
electrode. With
With an
an
electrode
electrode area
area of
of 1.5
1.5 cm
cm ,, the
22
the sensor
sensor is
is used
used to
to measure
measure mass
mass up
up to 100 g.
to 100 g. (see
(see Section
Section 8.7).
8.7).
There
There are
are two
two options
options that
that can
can be
be pursued.
pursued. One
One is
is to
to measure
measure the
the absolute
absolute frequency,
frequency, the
the other
other to
to
measure
measure onlyonly the
the change
change inin frequency.
frequency.
The
The first
first option
option isis not
not practical
practical with
with aa microprocessor.
microprocessor. The
The base
base frequency
frequency (zero
(zero mass)
mass) is
is 18
18 MHz
MHz which
which
corresponds
corresponds to to aa cycle
cycle of
of 55.55
55.55 ns.
ns. To
To measure
measure this
this frequency
frequency directly
directly would
would require
require aa clock
clock cycle
cycle much
much
shorter
shorter than
than this
this and
and such
such microprocessors
microprocessors do do not
not exist.
exist. Further,
Further, the
the change
change inin frequency
frequency for
for the
the largest
largest
mass
mass measured
measured is is only:
only:
An
An alternative
alternative is is shown
shown in in Fig.
Fig. 12.10.
12.10. Two
Two identical
identical crystals
crystals are
are set
set into
into oscillations
oscillations and
and the
the frequency
frequency of of
the 2 nd is subtracted from the 1 st
nd st. The result is a zero frequency. Now one sensor is used as the sensing
the 2 is subtracted from the 1 . The result is a zero frequency. Now one sensor is used as the sensing
sensor,
sensor, saysay the
the 11stst.. The
The output
output will
will change
change from
from zero
zero toto 13,333
13,333 Hz
Hz for
for change
change inin mass
mass from
from zero
zero to 100 g.
to 100 g.
The
The shortest
shortest time
time thatthat needs
needs to
to be
be measured
measured is is that
that of
of one
one cycle
cycle or 75 s
or 75 s (1/13,333
(1/13,333 == 75x10
75x10 ).-6
-6
). A
A 1010 MHz
MHz
clock
clock cycle (0.1 s/cycle)
cycle (0.1 s/cycle) wouldwould allow
allow accurate
accurate determination
determination of of the
the cycle
cycle time
time of
of the
the input
input frequency.
frequency. The The
time
time is
is measured
measured using using thethe process
process outlined
outlined in
in Example
Example 12.3.
12.3. Sensitivity
Sensitivity is
is 133.33
133.33 Hz/g
Hz/g and
and is is linear.
linear. The
The
microprocessor
microprocessor can of course display the output in the proper units by scaling the time measured using, for
can of course display the output in the proper units by scaling the time measured using, for
example
example aa lookup
lookup table table stored
stored in
in EEPROM.
EEPROM.
Fig. 12.10
Input signal conditioning
Offset
Primarily for DC levels
Can be offset up or down
Usually done to remove the DC level
Sometimes needed to remove negative polarity.
AC signals may sometimes be coupled through capacitors to
eliminate DC levels
Example
Thermistor: 500 at 20ºC
Varies from 400 to 900 for temperatvures between 0 ºC and 100ºC
Fig. 12.11
Offset
At 20ºC
V = (12/1500)*500 = 4 V
At 0ºC
V = (12/1400)*400 = 3.428 V
At 100ºC
V = (12/1900)*900 = 5.684 V
V varies between 3.428V and 5.684V
5.684V is above the 5V operati ng voltage of the microprocessor
Some solutions
Remove 3.428V through an inverting amplifier
Reduce the source voltage from 12V to, say 6V. This will change the
range to 1.714V to 2.842V
Increase the resistor from 1000 to, say, 1500. This will reduce the
output and will vary from 2.526V to 4.5V
Offset - other solutions
For AC signals
Use of capacitors
Only appropriate if signal is unipolar
Bi-polar signals produce negative signals
Rectification
Bridge connection
Battery must be floating
Output: 0V at 0ºC to 2.3V at 100ºC.
Offset of arbitrary value can be added
Done by changing the value of lower-left resistor
For example, a 1V offset is added to the output by reducing
the lower left resistor to 285.7
Example
Adding DC offset to a sensor signal: AA high
high temperature
temperature programmable
programmable thermostat
thermostat is
is built
built
around
around aa microprocessor
microprocessor using
using aa platinum
platinum RTD.
RTD. The
The resistance
resistance ofof the
the RTD
RTD is 240
is 240 at
at 20
20 ºC
ºC and
and has
has aa
temperature
temperature coefficient
coefficient of
of resistance
resistance of
of 0.003926
0.003926 /ºC
/ºC at
at 00 ºC.
ºC. The
The thermostat
thermostat isis required
required to
to switch
switch off
off at
at 350
350 ºC
ºC
and switch on at a temperature lower than the switch off temperature. The microprocessor operates
and switch on at a temperature lower than the switch off temperature. The microprocessor operates at 5 V and at 5 V and
uses
uses the
the internal
internal comparator
comparator andand internal
internal reference
reference voltage
voltage toto accomplish
accomplish the
the necessary
necessary function.
function. We
We assume
assume
the
the microprocessor
microprocessor hashas aa fixed
fixed reference
reference voltage.
voltage.
A
A possible
possible implementation
implementation is is shown
shown inin Figure
Figure 12.14a
12.14a (next
(next slide)
slide) A
A bridge
bridge is
is used
used as
as itit allows
allows adjustment
adjustment of
of
the
the voltage
voltage at at the
the positive
positive comparator
comparator pin.
pin. The
The negative
negative pin
pin is
is connected
connected internally
internally to
to the
the reference
reference voltage.
voltage.
We
We need to set the reference voltage so that the comparator switches from off to on at 350 ºC. To do so
need to set the reference voltage so that the comparator switches from off to on at 350 ºC. To do so we
we
must first calculate the resistance of the RTD at 350 ºC. From Eq.
must first calculate the resistance of the RTD at 350 ºC. From Eq. (3.4): (3.4):
The
The voltage
voltage at
at point
point A
A at
at 350ºC
350ºC is:
is:
The
The voltage
voltage at at point
point B
B is
is 2.5
2.5 VV because
because R R11 and
and R R22 are
are both
both equal
equal to 240 .
to 240 . The
The difference,
difference, 3.4315
3.4315 –– 2.5
2.5 ==
0.9315
0.9315 V is the voltage at the positive input pin of the comparator. The internal reference must be set to
V is the voltage at the positive input pin of the comparator. The internal reference must be set to this
this
value.
value. But,
But, the
the possible
possible values
values for
for reference
reference at at the
the negative
negative input
input to
to the
the comparator
comparator cancan only
only be
be set
set in
in
increments
increments of of 5/16
5/16 == 0.3125
0.3125 V. V. The
The closest
closest value
value isis 3*0.3125
3*0.3125 == 0.9375.
0.9375. This
This may
may be
be close
close but
but not
not close
close
enough
enough – the thermostat will not operate at the required temperature. We set the reference at 3*0.3125 ==
– the thermostat will not operate at the required temperature. We set the reference at 3*0.3125
0.9375
0.9375 V V and
and thethe offset
offset at
at 0.9375
0.9375 –– 0.9315
0.9315 == 0.006
0.006 V. V.
This
This is
is done
done by by reducing
reducing the
the voltage
voltage atat point
point BB by
by the
the offset
offset value
value to
to 2.5
2.5 –– 0.006
0.006 == 2.494
2.494 V.
V.
Example (cont.)
To
To do
do so
so we
we write:
write:
By
By selecting
selecting one
one resistance,
resistance, say
say R =300 ,
R11=300 , we
we get
get R 298.56 .
R22 == 298.56 . A
A more
more practical
practical solution
solution is
is to
to use
use aa
variable
variable resistor
resistor (potentiometer),
(potentiometer), say 500
say aa 500 potentiometer
potentiometer andand adjust
adjust itit so
so that
that the
the voltage
voltage atat point
point BB
(center
(center tap tap of
of the
the potentiometer)
potentiometer) isis 2.494
2.494 V.
V.
IfIf the
the temperature
temperature goesgoes down,
down, we we want
want the
the thermostat
thermostat to to switch
switch back
back at
at aa lower
lower temperature.
temperature. ThisThis isis done
done
by lowering the reference voltage one step, that is to 0.9375 – 0.3125 = 0.625 V (in software)
by lowering the reference voltage one step, that is to 0.9375 – 0.3125 = 0.625 V (in software) and allowing and allowing
the
the comparator
comparator to to switch
switch to
to low
low when
when that
that reference
reference voltage
voltage is
is reached.
reached. Since
Since point
point BB is
is at
at aa voltage
voltage of of
2.494
2.494 V, V, and
and switching
switching will
will occur
occur at
at 0.625
0.625 V,
V, the
the voltage
voltage atat point
point AA must
must be be 2.494
2.494 ++ 0.625
0.625 == 3.119
3.119 V. V. The
The
RTD
RTD resistance
resistance therefore
therefore must
must be:
be:
Using
Using now
now Eq.
Eq. (3.4)
(3.4) with
with T
T as
as unknown:
unknown:
That
That is,
is, the
the electronic
electronic thermostat
thermostat will
will switch
switch off
off at
at 350
350 ºC
ºC and
and on
on at
at 203.63
203.63 ºC.
ºC. The
The flowchart
flowchart in
in Fig.
Fig. 12.14b
12.14b
shows
shows how
how this
this can
can be
be achieved
achieved in
in software.
software.
Fig. 12.14
Scaling
Scaling the input to a microprocessor pin can be achieved:
By amplification
Operational amplifiers
By attenuation
Operational amplifiers
Resistance dividers
Transformers (for AC)
Amplifiers are preferable
Dividers introduce errors
Transformers are noisy and big
Example: voltage divider
The thermistor is fed from a 12V source with a 1000 resistor in series to produce the
desired current in the thermistor.
The voltage on the thermistor when its resistance is 900 is 5.68V
The voltage divider shown, reduces the output to 1.5V to 2.298V for the range of
resistances of the thermistor but:
Reduces sensitivity and changes the current in the thermistor
Another option is to increase the 1000 resistor to, say, 1500 .
Signal isolation
Isolation
Isolation between
between sensors
sensors or
or actuators
actuators and
and the
the microprocessor
microprocessor isis sometimes
sometimes need
need
When
Whenthey
theyoperate
operateat
atdifferent
differentvoltage
voltagelevels
levels
For
Forsafety
safetyreasons
reasons(such
(suchas ascontrol
controlof
ofhigh
highvoltages
voltagesto
toan
anactuator)
actuator)
When
When the microprocessor, the sensor orthe
the microprocessor, the sensor or theactuator
actuatorcannot
cannotshare
sharethe
thesame
sameground
ground
Two
Two basic
basic methods
methods
Transformers
Transformers
Usually
Usuallyavoided
avoided––transformers
transformersare
arebig,
big,heavy
heavyand
andexpensive
expensive
Limited in frequency – transformers do not work well at low frequencies
Limited in frequency – transformers do not work well at low frequenciesor
orat
athigh
highfrequencies
frequencies––must
mustbe
bedesigned
designedfor
forthe
thefrequency
frequencyrange
rangeof
ofthe
theapplication
application
Optical
Optical isolation
isolation (to
(to sensors
sensors or or actuators)
actuators)
The
The common
common choice
choice forfor signals
signals
The
The signal
signal modulates
modulates the the light
light intensity
intensity of
of the
the LED
LED
The
The phototransistor
phototransistor reconstructs
reconstructs the the signal
signal
Can be used at low and high frequencies
Can be used at low and high frequencies
High
High isolation
isolation (at
(at least
least aa few
few kV)
kV)
Simple
Simple and
and inexpensive
inexpensive components
components