Maplin auto electronics projects
Auto electronics projects ROM-1024 bytes Self check ROM-240 bytes RAM-64 bytes RST CPU control Arithmetic logic unit (ALU) M68HC05 CPU CPU registers Accumulator Index register 0000011 Stack pointer 0 0 0 Program counter Cond codes 111HINZC Oscillator Divide by 2 Watchdog and illegal address detect POWER Figure 3.1 MC68HC05J1 MCU block diagram, showing the basic functional blocks common to all microcontrollers 72 Microcontrollers it σ I Q PA7 PA6 PA5 PA4 Ρ A3 PA2 PA1 PAO ö Q PB5 PB4 PB3 PB2 PB1 PBO 1 5 Stage multifunction timer system Figure 3.1 Continued 73 Auto electronics projects • memory; usually ROM to contain the control pro- gram plus RAM to hold variables during program execution, • I/O and on-chip peripherals; these allow the MCU to communicate with the hardware of the real world ap- plication that it is controlling. These peripherals range from simple digital input/output (I/O) ports to complex analogue-to-digital (A-to-D) and digital-to-analogue (D-to- A) converters and timer systems. Table 3.1 lists some of the peripherals that are available on current microcontroller families. Microcontrollers are available in a range of complexi- ties and power (and therefore price), making them suitable for a very wide range of applications where they can replace standard logic or more complex microproc- essor based solutions. The advantages of the MCU over these traditional solutions are, reduced chip count, which brings cost; reliability and size bonuses; and greater flexibility for the designer — allowing easy modi- fications to the functionality of the application via the software. These advantages coupled with the devices' relatively low cost (typically from SO.75 in high volume) have led to microcontrollers being used in a great breadth of applications. With a few exceptions such as industrial control, these MCU applications can be split into two groups; automotive and consumer. Table 3.2 gives a non-exhaustive list of microcontroller applications in these two areas. The intention of this chapter is to give the reader some more insight into a few of the automotive applications that depend on microcontrollers, and to highlight the properties of par- ticular MCUs that make them suitable for each discussed application. 74 Microcontrollers MCU peripheral Function Digital I/O port Timer Serial port VFD port LCD port A-to-D PWM or D-to-A Watchdog tinner EEPROM — in addition to RO M PLL RTC Wake-up port DTMF OSD The basic hardware used by the CPU to access the outside world (read switches, drive LEDs, etc.). One off the most common and useful MCU peripherals — allows timing tasks to be accomplished while the CPU does something else. Both synchronous and asynchronous ports are available allowing fast serial communications over short or long distances respectively. 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 TV and radio. Real time clock. Special timer designed to count in real time, i.e. seconds, minutes and hours. Modified digital I/O port that can generate CPU interrupts when an input signal changes. 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 7 5 Auto electronics projects 76 The automotive industry is widely recognised by semi- conductor manufacturers as being the performance driver of the microcontroller market. Originally using microcontrollers with 4 and 8-bit buses, the automotive designer's quest for more processing power for some applications, such its engine management, has pushed the semiconductor industry into designing first 16-bit and now 32-bit MCUs. Some cars being designed today have more processing power under the bonnet than an aver- age PC! A well recognised trend in the automotive industry is to introduce new features on up-market cars and then mi- grate them down onto their mass market vehicles as reliability and user acceptance are proven, and costs come down. This explains why many of the features avail- able on today's cars (such as electric windows) were yesterday only available on expensive luxury models. However, in many cases these systems are using yester- day's dumb technology and many of the microcontroller applications of Table 3.2 are still the domain of up- market vehicles. As the technology migration trend and green legislation continue, this situation will change and within a few years all cars will contain more microcontrollers than wheels! See Figure 3.2. Interfacing MCUs in the automotive environment There is a fundamental problem with using micro- controllers, or digital logic in general, in an automobile; the vehicle electrical system is invariably 12 V and logi- cal devices work at around 5 V, and would be severely Microcontrollers Automotive Consumer Engine management Alarm system Anti lock braking Central locking Trip computer Dashboard Electric windows ln-car entertainment Active suspension Multiplexed wiring Seat adjustment Electric mirrors Television Microwave oven Telephone Video cassette recorder Washing machine Remote control system Toys Fridges and freezers Alarm system Radio Compact disc player Satellite receiver Table 3.2 Typical microcontroller applications Engine lanagement Dashboard A.B.S Alarm system Central locking Multiplexed wiring Active suspension Figure 3.2 Soon an average car will contain more microcontrollers than wheels! 77 Auto electronics projects damaged if connected directly to a 12 V system. 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. The MCU is also incapable of directly driving automotive loads, so that external drive circuits must be employed to interface the logic outputs to the 12 V loads. The situation is actually even worse than this ini- tial statement implies; the automotive environment is one of the harshest known, with extremes of temperature and the system voltage varying considerably depending on the condition of the battery and whether the vehicle engine is being cranked (when the voltage drops consid- erably). The biggest problem however, is the ignition circuit. When the ignition coil switches, large voltage impulses (50 to 100 V) can be generated on both rails of the entire electrical system. Although of short duration, these pulses would spell disaster for a logic circuit in- put. For this reason great care must be taken when designing protection circuits for the electronic hardware in cars. Despite these problems and the associated costs to counter them, the outlay is justified due to the ben- efits brought by electronics and microcontrollers, in particular to the automobile. In the following discussions and examples, the protection and drive circuits may not always be shown for simplicity, but the reader should be aware that these precautions have to be taken in all automotive microcontroller applications. Electric windows This is one of the most common electrical goodies to be fitted to many cars. Figure 3.3 shows the traditional dumb 78 Microcontrollers Door frame ι ι Figure 3.3 Conventional electric window circuit (duplicated for other doors) electric window circuit that is in common use today. The switches directly control the supply current to the mo- tors, thus propelling the window in the desired direction. When the window reaches the end of its travel there is no cut out, instead the motor simply stalls and the cur- rent is limited to a value that does not damage the motor windings. You can observe this by trying to raise both closed windows in a car when the engine is idling the engine r.p.m. will drop appreciably due to the heavy load- ing on the alternator. Although this system works quite well, it does have a couple of problems. The first of these is quite a major safety concern and stems from the fact that to deal with icy windows or a dirty mechanism a powerful motor is deployed. The problem is that if an obstruction is placed in the way of a closing window the motor will exert a great deal of force before it stalls; that obstruction could be a child's neck. The second prob- lem is more of an annoyance than a real problem and it concerns the amount of time that the driver must keep his finger on a small button to fully open or close the window. 79 Auto electronics projects Central locking That great innovation for the wet British climate, cen- tral locking, has traditionally been operated via a switch in the lock mechanism of the front doors, but in recent years a new development has made this feature even 80 Both these problems are solved by the intelligent MCU based system, shown in Figure 3.4. Here the switches and sensors are connected to inputs of the MCU and it in turn controls the motors via output ports that switch exter- nal drivers. The sensors inform the microcontroller that the window has reached the end of its travel and the MCU can stop the motors. This positional feedback along with the current sense means that the MCU can immediately detect when an obstruction other than the end-stop has caused the motor to slow or stall instead. In these cases the MCU can now take evasive action by stopping and reversing the direction of the window for a couple of inches thus releasing the obstruction. The MCU also al- lows the option of one-touch open or close, either via an additional button, or by counting how long the normal button is held for — e.g. if the button is pressed for more than 2 seconds then the MCU assumes a full motion of the window is required. Although these features could be implemented using logic control, the integration and very low cost of a simple MCU such as the MC68HC05J1 from Motorola make it the ideal choice. This device is supplied in a small 20-pin package and has only 1 Κ of ROM onboard to store the program, along with the CPU and a simple timer (Figure 3.1). However, these limited features linked with low cost make it the ideal device for displacing clumsy logic solutions. Microcontrollers 81 MC68HC05J1 MCU +5VI 1 Fuse +12V r— —} ηςΓ1 V DD —t 1 REG. E3 Ο supply from Crystal rh ιή I I ignition switch c^cuit 0SC2 Μ U >it r H . RESET —Γ Τ ^ ^ End-stop Λ „ αλ —· » Ο +5V sensor ° ^ ΡΑ0 ^ 1 Ί 0 + 12V Μ Ri9 H ht χ 1 μ- reo ΡΑ7 1 ±—^-ο ι υρ w ' TS Hi9h curren,/ 0 -4°-—ι Ri9h s f vXh d0W V leurrent! ν °" α9β PA6 - 1 1 ° Down rL I PB2 PA5 - 1 ±^_^ Up 0 + 12V T Q Right hand left , , I Μ Ä 1 window switch L °" j- 1 U- PB3 PA4 - 1 1 ° Down An w ' ?S High curren */ ί—ι— 0 +5V \ίί/ ι 1 voltage driver Π Ύ. Current _ pB4 M sense 1 , 1 OA _ Τ ~ Π t 0 Left hand left p ^5 LI 1 I window switch End-stop ^ PA2 — 1 1 ° Down T7tT? sensor v/ | v ss 1—I Π777 Figure 3.4 Microcontroller based electric window circuit [...]... Pulse 1 1 Auto electronics projects Figure 3.8 Continued interrupt Overflow Î 1 Interrupt enable ^ I κ comparator 16 Bit • Ν/ " 1 r °/C 2 j capture/output ' enable I L_P _J Interrupt Interrupt —if—1 ' 1 I via data bus CPU read ^> Other input 8L| 1 TOC2HIIJ TOC2LÖ] , I A Output compare I ^> Compare modules/pins I Iι j ' I 1 Ν Bus Timer I Output pulse Microcontrollers 93 Auto electronics projects rent... | I -t-" ^7 ι U 2- " 1 with ov I E fixed ~1 R °M Τ Inputs MC | Keyring , 1 OV ? | I v I I ! manufacture to produce I "unique" code I OV , during ) I.R Transmitter , 1 1 | 1 Microcontrollers 83 Auto electronics projects to c y c l e through, this would make t h e j o b o v e r l y time c o n s u m i n g for t h e potential intruder S i n c e t h e r e c e i v e r must remain p o w e r e d up at all t... a c c o r d i n g Open 1: Closed Intake Figure 3.6 Closed 2: Closed Compression Closed 3: Closed Combustion/ Power Closed 4: Open Exhaust The four strokes of the internal combustion engine 85 Auto electronics projects to a n u m b e r of f a c t o r s T h e m o s t significant of t h e s e fact o r s are engine s p e e d , t e m p e r a t u r e and engine load T h e j o b of engine m a n a g e m e... s e n s e t o c o m b i n e t h e c o n t r o l of b o t h into a single unit — t h e s o - c a l l e d e l e c t r o n i c engine m a n a g e m e n t s y s t e m With its ability to read 87 Auto electronics projects s e n s o r s , perform high-speed c a l c u l a t i o n s and m e a s u r e time, t h e m i c r o c o n t r o l l e r is t h e ideal d e v i c e for engine management Figure 3.7 s h... r r- temp ΑΓ ' quantity shaper 1 I I I Thermistor^] Figure 3.7 I wire Γ Engine speed/angle sensor Thermistor-^ hot Vane/ 'Missing' tooth I Γ co Spark k~Z Plugs Distributor Microcontrollers 89 Auto electronics projects rupt t h e CPU t o tell it t o r e a d t h e c a p t u r e d t i m e T h e following s e c t i o n i l l u s t r a t e s how t h e t i m e r s y s t e m interacts with the CPU on Motorola's.. .Auto electronics projects m o r e 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 u s e s a t r a n s m i s s i o n b y radio, or m o r e c o m monly infra-red (IR), to a... t i o n s o b t a i n e d from t h e various sensors As t h e r e a r e a n u m b e r of v a r i a b l e s t o b e taken into c o n sideration, these interpolation calculations are complex 95 Auto electronics projects and r e q u i r e a lot of p r o c e s s i n g power to b e c o m p l e t e d quickly, in time to s e t up t h e output timings for t h e next engine c y c l e T h i s is t h e r e a . Auto electronics projects ROM-10 24 bytes Self check ROM- 240 bytes RAM- 64 bytes RST CPU control Arithmetic logic unit (ALU). I Q PA7 PA6 PA5 PA4 Ρ A3 PA2 PA1 PAO ö Q PB5 PB4 PB3 PB2 PB1 PBO 1 5 Stage multifunction timer system Figure 3.1 Continued 73 Auto electronics projects • memory; usually. screen. Table 3.1 Commonly available on-chip microcontroller peripherals 7 5 Auto electronics projects 76 The automotive industry is widely recognised by semi- conductor manufacturers as being