Maplin auto electronics projects
Trang 3• memory; usually ROM to contain the c o n t r o l
pro-g r a m p l u s RAM t o h o l d v a r i a b l e s d u r i n pro-g p r o pro-g r a m execution,
• I/O and on-chip peripherals; t h e s e allow the MCU
to c o m m u n i c a t e with the hardware of the real world plication that it is controlling T h e s e peripherals range from simple digital input/output (I/O) ports to c o m p l e x analogue-to-digital (A-to-D) and digital-to-analogue (D-to-A) c o n v e r t e r s and timer s y s t e m s T a b l e 3.1 lists s o m e of
ap-t h e peripherals ap-t h a ap-t a r e a v a i l a b l e on c u r r e n ap-t
m i c r o c o n t r o l l e r families
M i c r o c o n t r o l l e r s are available in a range of
complexi-t i e s and p o w e r ( a n d complexi-t h e r e f o r e p r i c e ) , m a k i n g complexi-t h e m suitable for a very wide range of applications where they can r e p l a c e standard logic or m o r e c o m p l e x m i c r o p r o c -
e s s o r b a s e d solutions T h e advantages of the MCU over
t h e s e t r a d i t i o n a l s o l u t i o n s a r e , r e d u c e d c h i p c o u n t ,
w h i c h b r i n g s c o s t ; r e l i a b i l i t y and size b o n u s e s ; and greater flexibility for the designer — allowing e a s y modi-fications to the functionality of the application via the software T h e s e advantages coupled with the d e v i c e s ' relatively low c o s t (typically from SO.75 in high volume)
h a v e led t o m i c r o c o n t r o l l e r s b e i n g u s e d in a g r e a t breadth of applications With a few e x c e p t i o n s such as industrial control, t h e s e MCU applications can be split into two groups; automotive and c o n s u m e r
T a b l e 3.2 gives a non-exhaustive list of m i c r o c o n t r o l l e r applications in t h e s e two a r e a s T h e intention of this
c h a p t e r is to give the reader s o m e more insight into a few of t h e a u t o m o t i v e a p p l i c a t i o n s t h a t d e p e n d on
m i c r o c o n t r o l l e r s , and to highlight the properties of ticular MCUs that make them suitable for e a c h d i s c u s s e d application
par-74
Trang 4MCU peripheral Function
Digital I/O port
Special high voltage output port for driving vacuum fluorescent displays
Special low voltage output port for driving LCD displays Usually includes multiplexing for large displays
Analogue-to-digital converter used to read a variety of sensors, etc
A pulse width modulated output that can be filtered to produce a programmable analogue voltage, thus acting as a digital-to-analogue converter
A special type of timer that guards against CPU errors and resulting software runaway
Re-programmable memory that can be used for calibration purposes or for a non-volatile data store Phase locked loop Used in tuner applications such as
Dual-tone multi-frequency generator, used in tone
dialling telephone applications
On screen display A character generator for showing messages on a TV screen
Table 3.1 Commonly available on-chip microcontroller
peripherals
Trang 576
T h e automotive industry is widely r e c o g n i s e d by
semi-c o n d u semi-c t o r m a n u f a semi-c t u r e r s as b e i n g t h e p e r f o r m a n semi-c e driver of the m i c r o c o n t r o l l e r market Originally using
m i c r o c o n t r o l l e r s with 4 and 8-bit b u s e s , the automotive designer's quest for m o r e p r o c e s s i n g power for s o m e applications, s u c h its engine management, h a s pushed the semiconductor industry into designing first 16-bit and now 32-bit MCUs S o m e c a r s being designed today have more p r o c e s s i n g power under the bonnet than an aver-age PC!
A well r e c o g n i s e d trend in the automotive industry is to introduce new features on up-market c a r s and then mi-grate t h e m down o n t o t h e i r m a s s market v e h i c l e s as reliability and user a c c e p t a n c e are proven, and c o s t s
c o m e down This explains why many of the features able on today's c a r s ( s u c h as e l e c t r i c windows) were
avail-y e s t e r d a avail-y onlavail-y available on e x p e n s i v e luxuravail-y models However, in many c a s e s t h e s e s y s t e m s are using yester-
day's dumb t e c h n o l o g y and many of the m i c r o c o n t r o l l e r
a p p l i c a t i o n s of T a b l e 3.2 a r e still t h e domain of market v e h i c l e s As the t e c h n o l o g y migration trend and
up-green legislation continue, this situation will change and
w i t h i n a few y e a r s all c a r s will c o n t a i n m o r e
m i c r o c o n t r o l l e r s than wheels! S e e Figure 3.2
Interfacing MCUs in the automotive
environment
T h e r e is a f u n d a m e n t a l p r o b l e m with u s i n g m i c r o
-c o n t r o l l e r s , or digital logi-c in general, in an automobile; the v e h i c l e e l e c t r i c a l s y s t e m is invariably 12 V and logi-cal devices work at around 5 V, and would b e s e v e r e l y
Trang 6Fridges and freezers Alarm system Radio
Compact disc player Satellite receiver
Table 3.2 Typical microcontroller applications
suspension
Figure 3.2 Soon an average car will contain more
microcontrollers than wheels!
Trang 7damaged if c o n n e c t e d directly to a 12 V s y s t e m This means that a supply for the MCU must be derived from the 12 V supply using a regulator circuit, and that all inputs to the device must be buffered from the 12 V world around it T h e MCU is also i n c a p a b l e of directly driving automotive loads, s o that external drive circuits must
be employed to interface the logic outputs to the 12 V loads T h e situation is actually even w o r s e than this ini-tial statement implies; the automotive environment is one
of the h a r s h e s t known, with e x t r e m e s of temperature and the s y s t e m voltage varying c o n s i d e r a b l y depending on the condition of the b a t t e r y and w h e t h e r the v e h i c l e engine is being cranked (when the voltage drops consid-
e r a b l y ) T h e biggest problem however, is the ignition circuit When the ignition coil s w i t c h e s , large voltage impulses ( 5 0 to 100 V) can be generated on both rails of the entire e l e c t r i c a l system Although of s h o r t duration,
t h e s e pulses would spell d i s a s t e r for a logic circuit put For this r e a s o n great c a r e must b e taken when designing protection circuits for the e l e c t r o n i c hardware
in-in c a r s Despite t h e s e problems and the a s s o c i a t e d c o s t s
to c o u n t e r them, the outlay is justified due to the efits brought by e l e c t r o n i c s and m i c r o c o n t r o l l e r s , in particular to the automobile In the following discussions and examples, the p r o t e c t i o n and drive circuits may not always be shown for simplicity, but the reader should
ben-be aware that t h e s e p r e c a u t i o n s have to ben-be taken in all automotive m i c r o c o n t r o l l e r applications
Electric windows
This is one of the most c o m m o n electrical goodies to be
fitted to many c a r s Figure 3.3 shows the traditional dumb
78
Trang 8Door frame
ι ι
Figure 3.3 Conventional electric window c i r c u i t (duplicated for other doors)
e l e c t r i c window circuit that is in c o m m o n use today T h e
s w i t c h e s directly c o n t r o l t h e supply current to the tors, thus propelling the window in the desired direction When the window r e a c h e s the end of its travel t h e r e is
mo-no cut out, instead the m o t o r simply stalls and t h e rent is limited to a value that does not damage the m o t o r windings You can o b s e r v e this by trying to raise both
cur-c l o s e d windows in a cur-c a r when the engine is idling the engine r.p.m will drop appreciably due to the heavy load-ing on the alternator Although this s y s t e m works quite well, it does have a couple of p r o b l e m s T h e first of t h e s e
is quite a major safety c o n c e r n and s t e m s from the fact that to deal with icy windows or a dirty m e c h a n i s m a powerful m o t o r is deployed T h e problem is that if an
o b s t r u c t i o n is placed in the way of a closing window the
m o t o r will e x e r t a great deal of force before it stalls; that
o b s t r u c t i o n could be a child's neck T h e s e c o n d lem is m o r e of an a n n o y a n c e than a real problem and it
prob-c o n prob-c e r n s the amount of time that the driver must keep his finger on a small button to fully open or c l o s e the window
Trang 9Central locking
That great innovation for the wet British climate, tral locking, has traditionally been o p e r a t e d via a switch
cen-in the lock m e c h a n i s m of the front doors, but cen-in r e c e n t
y e a r s a new development has made this feature even
80
Both t h e s e p r o b l e m s are solved by the intelligent MCU
based system, shown in Figure 3.4 Here the switches and
s e n s o r s are c o n n e c t e d to inputs of the MCU and it in turn
c o n t r o l s the m o t o r s via output ports that switch nal drivers T h e s e n s o r s inform the m i c r o c o n t r o l l e r that the window has reached the end of its travel and the MCU can stop the m o t o r s This positional feedback along with the current s e n s e means that the MCU can immediately
exter-d e t e c t when an o b s t r u c t i o n o t h e r than the enexter-d-stop has
c a u s e d the m o t o r to slow or stall instead In t h e s e c a s e s the MCU can now take evasive action by stopping and reversing the direction of the window for a couple of inches thus releasing the o b s t r u c t i o n T h e MCU also al-lows the option of one-touch open or c l o s e , either via an additional button, or by counting how long the normal button is held for — e.g if the button is p r e s s e d for more than 2 s e c o n d s then the MCU a s s u m e s a full motion of the window is required Although t h e s e features could
be implemented using logic control, the integration and very low c o s t of a simple MCU such as the MC68HC05J1 from Motorola make it the ideal c h o i c e This device is supplied in a small 20-pin package and has only 1 Κ of ROM o n b o a r d to s t o r e the program, along with the CPU and a simple timer (Figure 3 1 ) However, t h e s e limited features linked with low c o s t make it the ideal device for displacing clumsy logic solutions
Trang 11more d e s i r a b l e — r e m o t e c e n t r a l locking In this set-up
a r e m o t e key uses a t r a n s m i s s i o n by radio, or more monly infra-red (IR), to a c t i v a t e the c e n t r a l locking from
com-a wide com-angle com-and c o n s i d e r com-a b l e d i s t com-a n c e from the cle — Figure 3.5 shows the s c h e m a t i c of such a s y s t e m
vehi-T h e t r a n s m i t t e r uses either a very b a s i c m i c r o c o n t r o l l e r
or, more commonly, a dedicated logic device such as the MC145026 IC Instead of using a keypad to d e t e r m i n e which c o d e to transmit, the device has its inputs fixed
in the factory, into a certain c o m b i n a t i o n of logic levels,
so that it will always transmit the same c o d e T h e number
of inputs allow a large number of different c o d e s to be configured — just like the number of levers in a padlock Although m a t c h e d pairs of t r a n s m i t t e r s / r e c e i v e r s could
be employed in this application, the logistics of keeping
t r a c k of which key belongs to which c a r during
produc-tion are obviously difficult, never mind how you would handle an owner losing his key and requesting a replace-ment! For t h e s e r e a s o n s , intelligence is employed in the
r e c e i v e r to allow it to be c u s t o m i s e d after production
T h e m i c r o c o n t r o l l e r c h o s e n for the j o b will include s o m e
on board p r o g r a m m a b l e non-volatile m e m o r y (EPROM
or EEPROM) that can be used to s t o r e the c o d e s of ing transmitters This customising of the receiver is often performed by the dealer, just before the new owner gets his car T h e m e m o r y size of the MCU allows for several key c o d e s , s o that multiple keys can be used by different family m e m b e r s S e c u r e software can be employed to prevent s o m e o n e from trying to c y c l e through all the valid c o d e s for the transmitter type until the c o r r e c t one
match-is found In its simplest form thmatch-is could just involve noring incoming IR c o d e s , for a couple of s e c o n d s , after
ig-an invalid c o d e has been r e c e i v e d — with so mig-any c o d e s
8 2
Trang 13to c y c l e through, this would make the j o b overly time consuming for the potential intruder
Since the r e c e i v e r must remain powered up at all times, low power consumption is of vital i m p o r t a n c e For this reason the MCU will invariably be a CMOS device, with a
special low power sleep or stop mode, where the power
consumption will be in the order of m i c r o a m p s Any coming signal will wake the MCU, via the interrupt pin, and it will r e c e i v e t h e c o d e and o p e r a t e t h e locking
in-m e c h a n i s in-m ( e i t h e r s o l e n o i d or in-m o t o r d r i v e n ) , if it
m a t c h e s one of the valid c o d e s s t o r e d in its memory A
s u i t a b l e d e v i c e for t h i s a p p l i c a t i o n w o u l d b e t h e MC68HC05P8, which is a c l o s e family m e m b e r to the pre-viously discussed J l device Its distinguishing feature for
com-8 4
Trang 14Figure 3.6 s h o w s t h e four s t a g e s of a c o m p l e t e c y c l e of a
f o u r - s t r o k e i n t e r n a l c o m b u s t i o n e n g i n e In t h e first
s t r o k e , t h e piston is travelling downwards with t h e inlet valve open, thus drawing in t h e air/fuel mixture from t h e inlet manifold In the s e c o n d s t r o k e , the piston r i s e s with
b o t h valves c l o s e d , t h e r e b y c o m p r e s s i n g the mixture
As t h e piston r e a c h e s t h e top of its travel (top dead
cen-t r e or cen-t d c ) , cen-t h e spark plug is fired cen-to ignicen-te cen-t h e mixcen-ture
T h e third s t r o k e is t h e c o m b u s t i o n / p o w e r s t r o k e , when
t h e cylinder delivers its power; t h e rapidly c o m b u s t i n g mixture b e c o m e s v e r y hot and t h e resulting rapid in-
c r e a s e in p r e s s u r e drives the piston down t h e cylinder
In the final stroke, the piston travels upwards again, with
t h e e x h a u s t valve open, t h u s expelling t h e remaining burnt g a s e s T h e piston is then ready to start its next downward intake s t r o k e , and s o initiate a n o t h e r four
s t r o k e c y c l e
T h e problem for t h e automotive designer is that to imise the power and fuel consumption of an engine (while minimising its pollutants), the timing of the ignition spark and the ratio of t h e air/fuel mixture must vary a c c o r d i n g
max-O p e n C l o s e d C l o s e d C l o s e d C l o s e d C l o s e d C l o s e d max-O p e n
1: I n t a k e 2 : C o m p r e s s i o n 3 : C o m b u s t i o n / 4 : E x h a u s t
P o w e r Figure 3.6 The four strokes of the internal combustion engine