©EUROMICRO EUROMICROJournal 6 (1980)359-362
MicroprocessorApplicationsTraining F. Halsall and P. F. Lister
Schoolof Engineering& Applied Sciences, the Universityof Sussex,Brighton,UK
The teaching philosophy and the equipment developed for a course ~n microprocessor app!Zcations programming techniques suitable for retraining engineers in the potentiaZ uses of ~icroprocessots ~s presented. A brief explanation of the application modules designed i~r the course is gii)en and a detailed description of a typical application assig~lent is presented. The use of a high-leoel design notation language and the concept of stepwise refinement is introduced.
I . INTRODUCTION
At t h i s p o i n t , however, many engineers experience considerable d i f f i c u l t y in using t h i s knowledge and applying i t to t h e i r own s p e c i f i c a p p l i c a t i o n environments. In order to help to bridge t h i s gap most engineers require some formal t r a i n i n g in applications programming techniques before they can s t a r t to w r i t e t h e i r own applications software.
The microprocessor is having considerable impact on an increasing number of i n d u s t r i a l organisations who are r a p i d l y having to consider using and i n t e g r a t i n g microprocessors into t h e i r products. Many of the design engineers employed in these organisations, however, have no previous knowledge of software or computer technology and hence i t is necessary for many of them to undertake a complete r e t r a i n i n g programme. The lack of any previous knowledge in t h i s area is also true of undergraduate engineers who are being introduced to t h i s technology at an e a r l y stage in t h e i r courses. To meet these needs many educational e s t a b l i s h ments now o f f e r courses on these devices f i r s t l y to introduce the fundamental p r i n c i p l e s of microprocessors and secondly, and more recently, to introduce the basic i n t e r f a c i n g and a p p l i c a t i o n programming techniques required to a c t u a l l y use microprocessors in a range of a p p l i c a t i o n areas. This paper describes the teaching philosophy and the equipment developed by the authors for a course in microprocessor applications programming techniques. 2.
The approach adopted by the authors is to introduce a range of a p p l i c a t i o n examples and t h e i r associated programming techniques in a structured way. F i r s t l y , since basic d i g i t a l input-output using a programmable interface c i r c u i t is already understood, the use of the microprocessor as a d i g i t a l sequence c o n t r o l l e r is considered. This involves programming a microprocessor system to act as a simple t r a f f i c l i g h t c o n t r o l l e r (as t h i s requires only d i g i t a l outputs and internal program generated time delays), and then progressing to develop a programme f o r a conditional sequencer. As an example of such a system a s i m p l i f i e d washing machine c o n t r o l l e r has been selected since t h i s requires, in addition to d i g i t a l outputs to activate motors, pumps, e t c . , both i n t e r n a l l y generated time delays ( f o r wash times, spin times, e t c . ) and conditional ( d i g i t a l ) inputs (water level i n d i c a t o r , temperature thermostat, etc.).
TEACHINGPHILOSOPHY
After attending an i n t r o d u c t o r y course on microprocessors an engineer w i l l t y p i c a l l y be aware of the basic structure of a microcomputer system and also have gained an understanding of the types of machine i n s t r u c t i o n s used by microprocessors. These w i l l include i n s t r u c t i o n s from the data t r a n s f e r and a r i t h m e t i c and logical groups and also i n s t r u c t i o n s from the t r a n s f e r of control group. In addition, a basic appreciation of the various i n p u t - o u t p u t i n s t r u c t i o n s which are available with a microprocessor and the programming of peripheral interface devices w i l l also have been gained.
Hany microprocessor applications require e i t h e r the input data to be processed or the subsequent output data to be in an analogue rather than a d i g i t a l form and hence the programming techniques required to process and produce analogue signals are then introduced. This includes the basic theory and operation of a n a l o g u e - t o - d i g i t a l (ADC) and d i g i t a l - t o - a n a l o g u e (DAC) converters and an introduction to sampling theory and digital filters. Some of the associated programming techniques are those of table look-up and piece359
360
F. Halsall and P.F. L i s t e r
wise l i n e a r i n t e r p o l a t i o n . The programming techniques required to process i n t e r r u p t s are then introduced. The a p p l i cation selected is a real-time d i g i t a l clock which derives i t s basic timing function from i n t e r r u p t s derived from a counter-timer c i r c u i t . An alphanumeric display is used and hence students can progress to display the day and date in alphanumeric form.
the t r a f f i c l i g h t module is used to i l l u s t r a t e a practical use of simple d i g i t a l output and the washing machine module both d i g i t a l input and output. The clock module incorporates a 4d i g i t alphanumeric display which is driven by
Although most of the applications considered on a course of this type are necessarily s i m p l i f i e d and hence r e s u l t in only short programs, emphasis is placed on the advantages of using a high-level design notation language to f i r s t specify the algorithm and then the concept of stepwise refinement to evolve the executable code. 3.
APPLICATIONSHARDWARE
In order to introduce each a p p l i c a t i o n and i t s associated programming techniques in a structured way, a range of a p p l i c a t i o n 'modules' have been designed and b u i l t . It was decided to make the modules independent of the type of microprocessor to which they were to be connected. In this way each module can be used e i t h e r with a single board system with hexadecimal keyboard and display or with a more sophisticated development system.
Fig. 2 -
Washing Machine Module.
normal 7 - b i t ASC I I characters. I t is therefore connected to the output port of the microp~cessor and the various select switches to the input port l i n e s , The module assumes the microprocessor system has an integral counter timer c i r c u i t which can be programmed to generate continuous i n t e r r u p t s .
Each module is therefore interfaced to the microprocessor system using two separate 8 - b i t u n i d i r e c t i o n a l p a r a l l e l ports - one f o r output and one f o r input. In a d d i t i o n , separate power supply l i n e s are used to provide the modules with the necessary supplies. Each a p p l i c a t i o n module therefore has a single standard socket f o r connection to the host mircoprocessor system. Three example a p p l i c a t i o n modules used on the course are shown in Figs. I , 2 and 3 which are intended to simulate a c o n t r o l l e d t r a f f i c l i g h t j u n c t i o n , a washing machine and a real-time clock respectively. As has been mentioned,
Fig. 3 - D i g i t a l Clock Module.
Fig. 1 - T r a f f i c Light Mod~le.
In addition to the three modules i l l u s t r a t e d there is also a module containing an 8 - b i t DAC and an 8 - b i t ADC. This is used to demonstrate the e f f e c t of sampling and processing analogue signals. In p a r t i c u l a r the DAC is used to demonstrate waveform generation using table look-up and l a t e r how t h i s technique can be extended using piecewise l i n e a r i n t e r p o l a t i o n . The ADC is used in conjunction with the DAC to demonstrate the e f f e c t of sampling and a l i a s i n g . This is then extended to introduce the implementation of a simple d i g i t a l f i l t e r . For this section the additional hardware required is simply a waveform generator and an o s c i l l o scope.
Microprocessor A p p l i c a t i o n s T r a i n i n g
Logical Outputs
Controlled Device State Number
Hot water control valve Cold water control valve WH - Water heater MW- Tub motor - wash/rinse speed PM - Pumpmotor (for emptying tub) MS - Tub motor - spin speed
HV -
0
1
CV -
1
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
1
O
0
0
0
O 0
l 0
O 0
0 0
3 4 5 Logical I n p u t s 0 l
Significance FULL - Water level sensor HOT - Water thermostat
Fig. 4. Washing Machine I n p u t - O u t p u t Assignment.
For each a p p l i c a t i o n e x e r c i s e the student i s presented w i t h the a p p r o p r i a t e a p p l i c a t i o n module and a s p e c i f i c a t i o n o f the task to be performed, This i n c l u d e s the assignment of the v a r i o u s I - 0 l i n e s f o r the module, an o u t l i n e s p e c i f i c a t i o n f o r the program - w r i t t e n in a h i g h - l e v e l design n o t a t i o n language - and some a s s o c i a t e d programming h i n t s . As an example, the s p e c i f i c a t i o n f o r the washing machine c o n t r o l l e r i s given in the next s e c t i o n .
State Number "0
1
Controlled Device HV CV WH MW PM
2
OFF OFF OFF ON
3
OFF OFF OFF OFF
4
OFF
5 RINSE
6
SPIN 7
MS
Action
ON OFF OFF OFF OFF OFF Fill tub with hot water until full. OFF OFF ON OFF OFF OFF Hea~ water
WASH
until thermostat closes. OFF OFF Rotate tub a t wash/ rinse speed f o r a fixed time Dl. ON OFF Empty tub for a f i x e d time D2.
8
1
2
3
6
7
o 1
o o tub full
0
0 l
0 1 thermostat
0
0
1
0
l
O
0
l
0 0
0 0
0 I
0 0
1
0
0
l
0
1
0
0
1
0
0
0
0
1
Fig. 6. Washing Machine State Table.
4.
CONDITIONAL SEQUENCING - A WASHING MACHINE CONTROLLER
A washing machine c o n t r o l l e r is a c o n d i t i o n a l sequencer which i n v o l v e s both e x t e r n a l c o n d i t i o n inputs and i n t e r n a l p r e s e t time d e l a y s . The p r i n c i p l e s encompassed by t h i s example are a p p l i c a b l e to many i n d u s t r i a l sequencer applications. The c o n t r o l l e d devices i n t e r f a c e d to the l o g i c a l outputs and the i n p u t c o n d i t i o n s i g n a l s f o r a s i m p l i f i e d c o n t r o l l e r are as shown in Fig. 4. A t y p i c a l sequence o f a c t i o n s f o r the c o n t r o l l e r is t h e r e f o r e as given in Fig. 5 and the corresponding s t a t e t a b l e as shown in Fig. 6. The two columns headed ' d e l a y ' ( b i t s 1 and 0 of the s t a t e byte) are not used f o r c o n t r o l l i n g hardware but i n s t e a d are used e i t h e r to s p e c i f y the time delay to be computed (DELl or DEL2) o r , i f both are zero, to t e l l the program t h a t i t s next change o f s t a t e is t r i g g e r e d by an external input,
0
Z Por~ A
Microprocessor System
3 4
~ PIO
u
Hot water control valve Cold water control valve Water heater Tub motor (wash/rinse speed) Pump motor Tub motor (spin speed)
~ Not used
7
o
I 2
Porg g
OFF OFF OFF OFF OFF ON Spin f o r
3 4
Water level Thermostat
Not used
5 &
7
OFF OFF OFF OFF OFF OFF STOP.
Fig. 5. S i m p l i f i e d Washing Machine Sequence.
5
Delay/Input DI/FulI D2/Hot
0 0 0 1 0 0 0 0 0 0 1 0
ON
OFF OFF OFF OFF F i l l tub with cold water until full. OFF OFF OFF ON OFF OFF Rotate tub at wash/ rinse speed f o r f i x e d time. Dl. OFF OFF OFF OFF ON OFF Empty tub for a f i x e d time D2.
4
0 0 0 0 0 0
f i x e d time Dl.
OFF
Controlled Device CV WH MW PM MS
0
2
i
HV
361
Fig.
7. Washing Machine Input--Output.
362
F. Halsall and P.F. L i s t e r
PROGRAM Washing Machine
The designated logical outputs and logical inputs used by the module are shown in Fig. 7.
BEGIN REPEAT Output next state to PIO port IF delay required THEN wait appropriate time delay ELSE wait u n t i l i n p u t condition is s a t i s f i e d UNTIL A l l states have been Output END. (*Washing Machine*).
Fig. 8. Washing Machine C o n t r o l l e r I. 4.1. The Algorithm The state stable shown in Fig. 6 can be r e a d i l y stored in memory. I t is suggested therefore that where b i t s 6 and 7 of the state byte are both zero, the next consecutive byte in memory specifies the external input condition to be s a t i s f i e d before continuing. The c o n t r o l l e r program must therefore simply step through each state of the table and implement the appropriate time d e l a y o r loop f o r the relevant input condition. This approach makes i t easy to extend to larger numbers of states and controlled devices.
A program for the control of the washing machine module can now be evolved. Using a Pascal-like design notation language and the concept of stepwise refinement, two i t e r a t i o n s of the c o n t r o l l e r program are shown in Figs. 8 and 9. I t is suggested that the algorithm described in Fig. 9 is now used to implement the program.
5.
CONCLUSIONS
The philosophy o u t l i n e d f o r i n t r o d u c i n g engineers and students t o basic microprocessor a p p l i c a t i o n s programming techniques has been evolved in conjunction with engineers themselves in order t o provide a step by step development o f the m a t e r i a l which can be readily assimilated. This approach has been i n c o r p o r a t e d , in conjunction With the educational equipment m~nufacturers, Feedback
l lnstruments Ltd. of Crowborough, U.K., in a Icomprehensive microprocessor applications
I training system. PROGRAM WashingMachine Define variables and constants Initialise PIO ports: Port A = output Port B = input PROCEDURETime Delay (Delay) BEGIN
REPEAT perform single delay function decrement Oelay UNTIL Delay is zero
END (*Time Delay*) PROCEDUREOutput (Value, Port) BEGIN Output Value to PIO Port END (*Output*) PROCEDUREInput (Value, Port) BEGIN Input Value from PIO Port END (*Input*) BEGIN (*Main Program*) FOR Count := l to Tablelength DO BEGIN obtain Next State from State Table Output (Next State, Port A) IF delay required THEN IF short delay THENTime Delay (DI) ELSE Time Delay (D2) ELSE obtain Conditional State from State Table REPEAT Input (Present State, Port B) UNTIL Present State = Conditional State END END (*Main Program*). Fig. 9. Washing Machine C o n t r o l l e r I f .
Dr. F. Halsall is a lecturer in Electronics and Computer Science in the School of Engineering of the University of Sussex. He has published and presented many papers in the fielJ of microprocessors and is co-author of the popular text '~croprocessor Fundamentals' published by Pitman Education. His current research interests include the hardware and software of multiple microprocessor systems and local area computer communication networks. Dr. P.F. Lister is a lecturer in Electronics in the School of Engineering of the University o~" Sussex. He has published a number of papers in the areas of microprocessors and digital electronics. He is co-author of the text 'Microprocessor Fundamentals'. His current research interest include multimicroprocessor systems for signal processing and control applications.