tkt-3500 microcontroller · pdf filetkt-3500 microcontroller systems lec 7 –hardware...
TRANSCRIPT
TKT-3500
Microcontroller
systems
Lec 7 – Hardware design part 1
Ville Kaseva
Department of Computer Systems
Tampere University of Technology
Fall 2010
#2/42
Sources
Original slides by Erno Salminen
Robert Reese, Microprocessors: From Assembly
to C with the PIC18Fxx2, Charles River Media,
2005
Northwestern University mechatronics design wiki
http://hades.mech.northwestern.edu/wiki/index.php/Mai
n_Page
Wikipedia
#3/42
Contents
Basic electronics
Current, voltage, power
Ohm’s law, Kirchoff’s law
Resistor, capacitance, inductance
Semiconductors: diode, transistor, IC
Others: fuse, regulator, op. amp.
Meters: multimeter, oscillator, signal analyzer
Packages and assembly
#4/42
Purpose
Not knowing exactly the background of the
attendants, here’s a brief reminder of basic
electronics
#5/42
Current I
Current measures how many charge carriers
(electrons) flow through a conductor
Conductor is material that can conduct electrical current,
usually some metal such as aluminum or copper
Symbol I; unit Ampere, A
microcontroller systems operate with e.g. 10 mA – 500 mA
Current may flow only in a closed circuit
from positive voltage to negative
Direct current (DC) flows always in one direction
whereas alternating current (AC) varies
The origin of current is also called source whereas
the destination is called sink or drain
#6/42
Voltage U/V
Voltage means electrical potential –
difference in amount electrical charge –
between two points of a circuit
Symbol U (sometimes V); unit Volt, V
microcontrollers use e.g. 2-5 V
Voltage source Vs is a device that provides
current with (ideally) fixed voltage level
single AA battery provides 1.5 V, car battery 12 V
wall outlet 230V, 50Hz alternating current (AC)
In practice, large current causes voltage drop
#7/42
Ohm’s law
The relation between voltage and current
U = R * I
Current I that flows through resistance R, causes
a voltage difference V
Or R = U/I, or I = U/R
Current causes voltage drop
Voltage difference causes current
VR
I
+
-Vs
RVs = VR = R * I
I = Vs / R
#8/42
Power P and energy E
Power measures the amount of work done in unit time Rate of energy consumption
Symbol P; unit Watt, W
Product of voltage and current: P = U * I = U * (U/R)
PIC uses <1 W of power
Energy E means the total work Symbol E; unit Joule, J
E = P * t = (U*I) *t, where t denotes time
Sometimes given in Watt-hours, Wh or volt-Ampere-hours VAh
Battery stores some amount of energy E that is spent at certain rate P One AA battery contains 1000-3000 mAh
#9/42
Kirchoff’s law
Electrical current
1. cannot disappear anywhere
2. cannot originate out of nowhere
More formally, sum of currents flowing into a
circuit node equals the sum of leaving
currents
Σ Ii = Σ Io
Current flows also in the ground wire
although its voltage is (almost) zero
so called ground loop
I1I2
Is= I1+ I2
Basic passive
components
#11/42
Resistance R
Property of a conductor defining the how much is
prevents the current from flowing
Symbol R; unit Ohm, Ω
1 Ω = 1V / 1A
Ideal conductor has R= 0 Ω
Ideal insulator has R= ∞ Ω
Passive component (does not need supply voltage to
operate)
Unpolarized – no matter which way you connect it
Basic microcontroller system utilizes resistors e.g. in
the range 50Ω -500 kΩ
Drawing symbols:
#12/42
Resistances in series
Current flows through all resistors – large
resistance
Rtot = Σ Ri
Voltage division so that sum of voltages
across resistors equals the source voltage
Vs = VR1 + VR2
Vs = I * Rtot
Vs = I * (R1 + R2)
VR2 = R2/Rtot * Vs
VR2
I
+
-Vs
R2
R1
VR1
#13/42
Resistances in parallel
Current has more paths – low resistance
Same voltage across all Ri
VR1 = VR2 = Vs
Rtot =
Is= Vs / Rtot
Current divider:
I1 = (R2 / Rtot) * Is
I2 = (R1 / Rtot) * Is
I1 I2
Is= I1+ I2
+
-Vs
VR1
1
+1 1R1 R2
VR2R2R1
Is
#14/42
Fuse
A fuse is just a thin wire, enclosed in a
casing, that plugs into the circuit so that all
charge flows through the fuse wire
If the current climbs too high, it burns up the
wire
Protects the circuit against excess current
due to, for example, a short-circuit
Fuse must be of right size
Does not burn accidentally
Will be burn before other circuitry
Size measured in tolerated amperes
#15/42
Capacitance C
Symbol C; unit Farad, F
Component is called capacitor (’kondensaattori’)
Commonly used capacitors are in picofarad range
Stores electrical charge into electrical field
Two metal plates very close to each other with
insulator in between
”Resists the change in voltage”
used for filtering and as a temporary voltage
source
Drawing symbols:
Basic, unpolarized Polarized
+
#16/42
Capacitance C (2)
Capacitors in parallel Ctot = Σ Ci
Capacitors in series Ctot = 1 / (Σ 1/Ci)
Current depends on the change in voltage
Does not conduct if voltage is stable
Voltage across the capacitor is integral of
current
i.e. how much charge have flown into the capcitor
i(t) = C dvdt
v(t) = i dt1
C
#17/42
Charging/discharging a capacitor
Large, abrupt voltage difference
when switch opens/closes
Large current immediately after
that
Current decays as C gets
charged/discharged
i(t)+
-Vs
R1
vC(t) vC(t)
t1a
Vs
CR2
t2at1b
switch1
switch2
0) both
switches
open
1) close
switch1
2) open
switch1
3) close
switch2
Charge C ”Hold” Discharge
i(t)
R1 > R2
time
time
#18/42
Capacitor for filtering
+
-vs
R1
vC(t)
C
switch1 v(t)
vs
time
vc
+
-vs
vo(t)
C
switch1 v(t)vs
time
vc
RC circuit filters high frequencies (sharp edges)
Capacitor does not conduct when voltage is
constant, i.e. it does not pass DC component
through. Hence, vo has Only the AC component.
#19/42
Inductance L
Symbol L; unit Henry, H
Commonly used inductors are in mH range
”Resists the change in current”
Coils are used for filtering
Stores electrical charge into magnetic field
Even when current is turned off, magnetic field
induces a current
This may create voltage spikes that cause noise
problems and may break other components
Inductors in series/parallel act like resistors
Drawing symbols:
#20/42
Inductance and magnetic field
Current flowing through
wire creates a magnetic
field around it
”Right-hand rule” gives
the direction of field
Magnetic fields sum
together in the ”core” of
the coil
Antennas are based on
induction phenomena
current
direction of
magnetic field
#21/42
Impedance
How much an electrical entity impedes (slows down) the flow of current
Symbol Z; unit Ohm, Ω
Same unit with resistance
Sum of resistance and reactance
Reactance is frequency-dependent part Applies to capacitors and coils
ZC = 1 /ωC = 1 / (2 * π * f * C)
ZL = ωL = 2 * π * f * L
On high frequency, impedance of C is low whereas impedance of L is high
#22/42
Input and output impedance
When voltage is applied to circuit’s inputs, a current will flow Input impedance defines its magnitude
In many cases, input resistance is accurate anough
When output circuit is closed, a current will flow Output voltage is not constant, Vout, loaded < Vout, open-circuit
Small load takes large current
Creating a short-circuit to outputs, defines the maximum Iand, hence, the circuits’ output resistance
Ideally, Zin=∞Ω and Rout = 0 Ω
circuit
internal
structur
e
Vin Vout
circuit
VinZin
Rout
Vout
Iin
Example circuit Equivalent circuit
Zload
Iout
VOC
#23/42
Basic passive filters
vo(t)
C
vi(t)
vo(t)Cvi(t)
Gain = Vout/Vin
freqeuncy
Gain = Vout/Vin
freqeuncy
1.0
1.0
f0
f0
Low-pass filter
In both cases f0 = 1 / ( 2 * π * RC)
High-pass filter
Exam
ple
uasge: push b
utton
#24/42
Basic passive filters (2)
vo(t)C Lvi(t)
vo(t)
C
Lvi(t)
Gain = Vout/Vin
frequency
Gain = Vout/Vin
frequency
1.0
1.0
f0
f0
Band-pass filter, at f0 the impedance Z → 0
In both cases f0 = 1 / ( 2 * π * LC)
Band-pass filter, at f0 the impedance Z → ∞
#25/42
Suodattajat
Yhden tuttavani tilatoverit ovat oudossa työssä. He suodattavat signaalia Nokialla. Tämä on totta, enkä edes valehtele! Niillä on siellä Nokiallaan FIR-suodattimia ja mediaanisuodattimia ja ties mitä astraalikotkotuksia ja aamulla ne alkavat suodattaa sitä signaalia ja kaiketi pelata sököä, (tai rakentaa Taj Mahalia tulitikuista) odottaessaan, että suodattimeen kertyisi jotain, töhkää kaiketi. Välillä joku ketterämpi veli käy kapistamassa suodattimesta lavuaariin kaiken roskan, mitä siihen on tarttunut, ja keittää kahvia ja sitten taas peli jatkuu (tai Taj Mahal rakentuu). Illalla signaali viedään haponkestävään holviin ja suodattimet pestään ja pannaan astiakaappiin. Suodattaminen jatkuu taas seuraavana päivänä, ellei ole viikonloppu tai pyhä. (Niiden työehtosopimuksen mukaan viikonloppuina ja pyhinä ei tarvitse suodattaa signaalia yhtään, mutta saa silti palkan aivan kuin suodattaisi.) Tyhmä luulisi, ettei työnantajaa voi kauan pettää ja suodattaa aina vaan samaa signaalia, mutta viisas arvaa, että kun näytteenottoa tarkennetaan, kohina jotenkin vaan lisääntyy ja voit suodattaa sitä samaa signaalia aina vaan, vaikka sata vuotta, eikä työnantaja älyä mitään filunkia!
Markus Kajo, Kettusen kolmas
Some semiconductor
devices
#27/42
Semiconductor devices
Semiconductor – material which conducts
varying electrical current depending on the
conditions, e.g. voltage or light
Diode
simplest semiconductor device, two terminals
conducts in one direction
Transistor
three-terminal devices
conductivity is controlled with one of the terminals
Integrated circuits
#28/42
Diode
Conducts current in one
direction only
Conducts only when forward
biased
Vanode - Vcathode > Vthreshold
Usually Vthreshold = 0.7 V
Often used for protecting other
circuitry
Also used for rectifying (AC to
DC)
symbol:
real component:
#29/42
Diode (2)
When voltage in forward direction rises above
threshold, the diodes R approaches zero
Current is limited by other circuitry
Diode causes constant
voltage drop, usually 0.7V
Voltage in backwards
direction, prevents
conduction
Unless diode breaks with
large voltage...
+
-Vs
Vd
Vd
I
#30/42
Some diode types
1. basic – most comon
2. light-emitting diode (LED) – produces light (infrared-visible-ultraviolet) relative to current laser diode – used e.g. optical
communication
3. photodiodes – conductivity depends on the luminance
4. Schottky – hysteresis prevents spurious changes of diode output
5. zener (and avalanche)– conduct backwards (see voltage regulators)
6. And many more...
symbol:
real component:
#31/42
#32/42
Diode usage for clamping
Clamping limits voltage into desired range
Useful when we need to protect circuits from high
voltages at their inputs
We specify the maximum and minimum voltage we
want by applying voltages across a diode.
If Vin > Vmax, diode D1 becomes forward biased and conducts, thus forcing Vout to stay at Vmax.
If Vin < Vmin, diode D2 conducts and prevents the Vout from dropping any lower
Often Vmax = Vdd, Vmin = GND
#33/42
Rectifying circuits
ACin
ACin
DC out
DC out
time
time
Direction of
current when
AC in is positive
Half-wave (above) and full-wave (right) rectifiers
loadCfilt
#34/42
Transistor
Amplifies or switches electronic signals
Sometimes considered as ”the greatest
invention of 20th century”
Three terminals
current in
current out
control terminal
The last defines the conductivity between the
two others
#35/42
Transistor (2)
Many different flavors Controlling quantity (current vs. voltage)
Control polarity: positive/negative
+ Depletion/enhancement type FETs
The polarity of terminals: doped with n-type or p-type
The main categories 1. bipolar junction transistor (BJT): current-controlled
2. field-effect transistor (FET): voltage-controlled
we won’t go into details...
gate
drain
source
base
collector
emitter
Slightly different
symbols and naming of
terminals
VGS
BJTFET
IB
II
drain = nielu
gate = hila
source = lähde
IB ≈0
0.7V
#36/42
Transistor (3)
a) Transistor off – not conducting – when
control voltage (or current) is zero
b) Transistor on – starts conducting – when
control voltage increases
1. Conductivity increases with control
2. When control increases enough, transistor
becomes saturated – it cannot conduct more
current
When conducting, base-emitter voltage (or
gate-source) is constant
Similar p-n junction as in diode
#37/42
Field effect transistor
Vdrain
VGS
Idrain
MOSFET (metal-oxide semiconductorFET), N-
type i.e. channel is n-type semiconductor, aka.
NMOS
Voltage between gate and source controls the
conductivity of the channel.
2. source
1. drain
3. gate
channel
No drain current flows via NMOS for VGS less
than certain positive value known as threshold
voltage Vth.
Practically no current flows ”into” gate IB≈0 A.
VGS
Idrain
Vthreshold
ideal switch
n-channel
FET
#38/42
Field effect transistor (2)
Vdrain
VGS
Idrain
MOSFET (metal-oxide
semiconductorFET), N-type i.e. channel
is n-type semiconductor, aka. NMOS
2. source
1. drain
3. gate
channel
Linear region
(’Ohmic region’)
0 V, ’cut-off’
In p-channel FET, PMOS, the direction of drain
current is reversed and the polarity of VGS is
opposite.
Combinination NMOS and PMOS can be used
for implementinc complementary MOS (CMOS)
logic gates.
#39/42
Example usages of
transistor
1. As a switch
FET closes the electrical circuit and let’s the current flow
Practically zero current goes from PIC to FET
Specific power-FETs can handle large currents
2. As inverting AC amplifier
This BJT has DC current gain hFE = β = 100
IB = (Vcc- 0.7V)/RB = 10.2 uA
IC = β * IB = 1.02 mA
quiescent Vo = Vcc – IC * RC = 5.2V
Vin > 0, increases IB and Vout will drop
With few additional R, the gain can be controlled regardless of β
g
d
sVGS
I
Device that takes
larger current than
available from PIC
Vdd
PIC
GPIO
IB
IC
0.7V
Vin
Vcc = 10V
Rb= 910 kΩ
b
c
e Vout
Rc= 4.7 kΩ
0V
C
#40/42
Integrated circuits
An integrated circuit (IC) combines many
components into single chip
Example ICs
microprocessor
memory
Ethernet controller
operational amplifier
74xx series, e.g. 8 * 2AND gates
Require larger package with more pins than
previously introduced components
Using ICs reduces the number of components on the
circuit board and increase their performance
#41/42
Operational amplifier
High-gain voltage amplifier
Very popular active component
Needs power supply and ground
Amplifies the difference between the two
input terminalsAn op-amp in a DIP
package
+
-
Vs+
Vs-
V+
V-.
Vout.
For any input voltages the ideal op-amp has infinite open-loop gain (i.e.
without feedback)
infinite bandwidth and slew rate
infinite input impedances (resulting in zero input currents),
zero offset voltage,output impedance, and noise
Circuit symbol of an op. amp.
#42/42
Operational amplifier (2)
Usually utilizes negative feedback (Fraction of) Vout is connected to input V-
Input signal is fed to input V+
Consequently, op.amp drives the output so that there is no voltage difference between V- and V+
Does not load Vinput (practically no current) but high current available at output
+
-R1
R2
VinputVout
Vout * R2/(R1+R2) = Vinput
Note! 0 V
Vout = Vinput * (R1+R2)/R2negative
feedback
I ≈ 0 A
Amplification is controlled with external resistors R1 and R2!