Professional Documents
Culture Documents
An Introduction
(Higher)
6526
HIGHER STILL
Spring 2000
Mechatronics
Mechatronic Systems
An Introduction
Higher
Support Materials
CONTENTS
Microcontrollers
a) What is a microcontroller?
b) The needs of embedded control
c) The Basic Stamp microcontroller
d) The original Parallax Basic Stamp
e) The Higher Still developed Basic Stamp Controller
f) Intel 8XC196MC Industrial Motor Control Microcontroller
g) Intel Automotive 80C31BH/80C51BH/87C51 Microcontroller
Programmable Logic Controllers PLCs
a) What is a Programmable Logic Controller?
b) PLC Central Processing Unit (CPU)
c) PLC Memory
d) PLC Input/Output
e) PLC Programming Languages
f) Ladder Logic
Controller Types Reviewed
a) PC based
b) Embedded controller
c) Microcontroller
d) Programmable Logic Controllers
e) Hardwired Logic
PROGRAMMING
Compiled Languages
Interpreted Languages
Low-Level Computer Languages
High-Level Computer Languages
a) FORTRAN
b) BASIC
c) Pascal
d) C
Very High-Level Languages
Natural Languages
Object-Oriented Programming
a) Smalltalk
b) C++
c) Turbo Pascal
The ROM area is where micro code required for the correct internal operation of the
CPU will reside.
RAM will allow dynamically changing data to be temporarily stored and used within
the operation of a user program.
Both ROM and RAM memory exists in larger amounts external to the microprocessor
as well. This is where large application programs and data would be stored and again
this memory is accessed directly by the microprocessor via the buses.
ADDRESS BUS
I/O
or
Memory
CTRL BUS
Central
Processing
Unit
CTRL BUS
Memory
or
I/O
DATA BUS
Microprocessor architecture
There are three buses involved in the processor:
The Bus system
The data bus transfers data and instructions between memory and the CPU or
between the CPU and the memory. Data movement is bi-directional with the
direction being set by the control bus.
The control bus carries various signals that control the way the system responds to
both internal and external commands. Internal commands include the setting of
direction of data flow on the data bus whether memory is being read from or
written to and whether the memory being accessed is actually part of the
input/output area as data handling commands differ for I/O operations. This bus
can vary considerably between different processors, is more complex than the
other buses and is dependent on the processor manufacturer (INTEL,
MOTOROLA, AMD, ZILOG.)
Note: In the diagram above the control bus marked CTRL BUS although it
appears twice, is actually the same bus.
The address bus allows the CPU to pinpoint individual memory locations within
the system memory map. These memory locations originate from the CPU and are
dependent on whether the information required is program code or raw data. This
bus only has to work in one direction and so is known as uni-directional.
fluid in
stroke length
limit sw
limit sw
Voltage
Temperature
In the graph above the voltage rises smoothly, it has no visible steps, as the
temperature rises. If we wish to find a value at any instant in time we will get a value
that is representative of the original signal.
Note that this is not the only waveform that constitutes an analogue signal.
Voltage
Temperature
10
WHAT IS A TRANSDUCER?
1
Transducer (sensor):
is any device that converts a non-electrical parameter, for example, sound, pressure,
or light into electrical signals or vice versa. The variations in the electrical parameter
are a function of the input parameter
What is a sensor?
a microphone converts sound into electrical energy
a thermocouple converts heat energy into a change in voltage
a switch converts mechanical movement into one of two possible electrical states.
What is an actuator?
An actuator, in a control system, is a device which converts energy from one form
into another:
a speaker converts electrical energy into sound
a solenoid converts electrical energy into mechanical motion
a motor converts electrical energy into rotational motion.
WELL!!! IS IT A SENSOR OR IS IT AN ACTUATOR?
This is a classic question, and can only be answered by asking yourself a few
questions:
is the device doing a job, does it move something? If the answer is yes then the
chances are that the device is an actuator
if on the other hand it provides a changing signal then it is likely that it is a
sensor.
11
Sensors
Below is a list of sensors commonly found in a Mechatronics system.
Sensor name
Microswitch
Float switch
Photoelectric
Type
Digital
Digital
Digital
Inductive
Digital
Conductive
Capacitive
Ultrasonic
LVDT
Linear potentiometer
Rotary potentiometer
Magnetic reed switch
Infra red
Analogue
Digital
Digital/analogue
Analogue
Analogue
Analogue
Digital
Digital
Thermocouple
Strain gauge
Piezoelectric crystal
Analogue
Analogue
Analogue
Moire fringe
Hall effect
Digital
Analogue/digital
Tacho generator
Analogue
Vane anemometer
Analogue
Usage
End stop - limit switch
Liquid level detection
Through beam
Retro-reflective
Diffuse
Background/foreground
suppression (BGS/BFS)
Fibre optic
Proximity detector
Shielded sensor
Unshielded sensor
Distance sensing
Level sensing
Proximity detector
Level/depth sensors
Linear displacement
Linear displacement
Angular displacement
End stop limit switch
Reflective proximity can
be used for positional or as
part of a shaft encoder
arrangement to provide a
stream of pulses
Temperature measurement
Force displacement
Pressure displacement
Among others
Linear positioning
Position; can be used
within a shaft encoder to
supply a stream of pulses
Speed control; driven
permanent magnet motor
will give a voltage
proportional to the speed
of rotation
Fluid flow
12
The microswitch
Switch2:
A device that causes the operating conditions of a circuit to change between discrete
specified levels.
The micro in microswitch refers not to the physical size of the device but the
actuation movement required to open or close the contacts from Normally Closed
(NC) to Normally Open (NO). The internal operation of the microswitch can be seen
in the figure below:
normally closed
nc
common
com
normally open
no
Microswitch
Microswitches, which are digital in operation, are used extensively to detect end of
stroke movement. The microswitch requires physical contact in order to operate, is
mechanical in operation and consequently has a restricted life due to the flexing
operation of its internal mechanism. The microswitch may also be found in a nonmechanical, non-contact, inductive proximity format as well.
The inductive proximity sensor
The inductive proximity sensor consists of a coil wound around a ferrite core at the
sensing head. A high frequency signal is applied to this, generating an oscillating
electromagnetic field around it as shown in the figure below. This is monitored by the
internal electronics.
copper
coil
electronics
Proximity detector
When a metallic object travels towards the field, electric currents are generated within
it. As the object approaches the sensing face of the sensor these currents increase in
size.
2
13
The currents cause a transformer like effect and as a result the energy in the detecting
coil lessens and the oscillations reduce. As the object moves in closer the oscillations
finally stop.
Sensing distances are usually quoted by the manufacturers and are dependent on the
target material type and target size. The sensing distance quoted in the device
specifications for the proximity sensors are based on a standard target. This target
(known as a standard object) is a square plate of mild steel 1 mm thick, a primarily
ferrous object.
standard
target
sensing distance
(operating position)
sensing distance
(operating position)
14
Where other target materials are to be used for example paper, card or plastic other
proximity detectors exist that will sense these materials.
The thermocouple
The thermocouple, shown below is a sensor used in the monitoring of temperature.
As a sensor it has a relatively simple construction. Two wires of different metallic
materials are brought together and bonded, usually in a high temperature arc welding
process. The result of this process leaves a sensor that generates very small voltages
proportional to a rise in temperature. These voltages can be amplified and used
within a mechatronic system to allow temperature control.
welded
tip
Thermocouple
The thermocouple comes in many forms to cover the temperature ranges as listed in
the table below.
Minimum continuous
temperature
Maximum continuous
temperature
Maximum spot reading
Type J
-60
Type R
-50
+1100
+400
+1350
+1400
+850
+1300
Units
O
C
The 3Graph above shows that the Type K thermocouple output is linear and usable
over quite a large range of temperatures from approximately 100OC to 400OC.
Note: thermocouples are only one of a variety of sensors available for temperature
control.
3
Courtesy of RS Components
15
Flow sensors
Measurement of flow is required in many automated processes. The simplest method
of flow measurement uses a device known as a turbine. This device, however, is by
nature intrusive. That is, it must fit inside the system and be moved directly by the
fluid being monitored, and so it must be realised that this type of device will restrict
the flow while measuring it. The diagram below shows a simple flow sensor in
operation.
sensing
coils
Flow
magnetic
inserts
Flow sensor
As the liquid flows through the pipe it forces the turbine to turn. As the blades rotate
the magnetic inserts pass in close proximity to the sensing coils, this induces a current
in the coils. If these coils are placed symmetrically around the outside of the pipe
then a series of pulses will be produced. Information about speed of rotation of the
turbine can then be converted into the rate of flow of the fluid within the pipe.
For a very good description of the paddlewheel sensor, point your browser at:
http://www.sensorsmag.com/articles/1299/63_1299/main.shtml
Where you will find an article named:
Paddlewheel Flow Sensors: The Overlooked Choice
Another type of flow measurement device, which can be used without restricting the
flow of the liquid within the pipe, is the ultrasonic flowmeter. These devices can be
strapped onto the outside of the pipe and use sound to calculate rate of flow.
16
direction of flow
ultrasound
transmitter
ultrasound
receiver
Pulses of sound are emitted by the transmitter, this sound is reflected by the back wall
of the pipe, but because of the fluid flow the pulses are forced to travel downstream.
Electronics within the system measure the difference in time between the pulses and
using maths the distance travelled can be calculated.
These systems are known as time of flight measurement devices.
For a very good description of ultrasonic flowmeters, point your browser at:http://www.sensorsmag.com/articles/1097/flow1097/main.shtml
Where you will find an article named:
Ultrasonic Flowmeter Basics
These are not the only type of flow measurement device and so below are a few other
devices that can be used.
A
A
B
(a) Nozzle.
(b) Venturi
17
stainless
steel
diaphragm
sensor
element
external
connections
constant
current in
voltage
out
voltage
out
reference
element
sensing
element
ground
18
In the case of the venturi in the figure below; there are two pressure tapping points
A and B. In order that continual monitoring of the rate of flow can be carried out
the pressure difference between these two points must be known. This can be carried
out by installing either two pressure sensors as shown previously or by employing a
differential type to provide the information. The information from the transducer/s is
then used to calculate the final rate of flow.
A
B
Venturi sensor
For a good description of pressure sensor technology, point your browser at:
http://www.sensorsmag.com/articles/1198/fun1198/main.shtml
Where you will find an article called
Fundamentals Of Pressure Technology
Note: It is worth visiting the site http://www.sensorsmag.com as there is a wealth of
information on all aspects of sensors to be found here.
19
Actuators
Below is a list of actuators commonly found in a Mechatronics system:
Actuator name
Stepper motor
Solenoid
Type
Digital
Digital
Actuation
Rotational
Linear &
rotational
Pneumatic cylinder
Analogue/digital Linear
Hydraulic cylinder
Analogue/digital Linear
DC motor
Analogue
Rotational
AC motor
Analogue
Rotational
Work type
Positional
Mechanical displacement
Relay
Air flow control
Mechanical displacement
This type of device comes
in many forms from purely
digital linear operation, to
analogue linear operation
and from purely digital
rotational operation to
analogue rotational
operation
Linear or rotational
displacement
Direct drive
Servo control
Direct drive
Closed loop control such
as harmonic drive.
fluid in
Brake piston
20
Fluid forced in under pressure at the right hand side of the cylinder pushes the piston
to the left. Fluid on the left of the piston is exhausted from the connector on the lefthand side thereby forcing the internal piston to the left imparting linear motion. If on
the other hand fluid is being forced in on the left side and fluid is allowed to exhaust
on the right then the piston will move to the right, again imparting linear motion.
Hydraulic fluid is generally a mineral oil.
The same diagram and description will also suffice to explain the action of a
pneumatic system in which the oil is replaced by compressed air. The main
difference between these two systems is their ability to do work. Air is compressible
even when it has previously been compressed to 100 psi. This fact means that
pneumatic systems are limited to relatively light loads. Hydraulic systems on the
other hand can do many times more work due to the incompressibility of oil.
The hydraulic/pneumatic rotary actuator
Another type of actuator exists which will create rotary motion, as seen in the figure
below.
rotation
fluid in
exhaust
stator
field coils
magnet
commutator
magnet
rotor
DC motor
21
OFF
Stator
Rotor
Stator
Rotor
N3
OFF
N2
N1
ON
N1
OFF
S1
S3
S3
S1
N3
N2
S2
ON
S2
ON
OFF
Diagram a
Diagram b
22
What is control?
Is a man with a box and arrow taking aim an open or closed loop control system?
Closed loop control
Closed as the man will adjust his aim to take care of wind direction or movement of
the target etc.
When the trigger is pulled and the arrow leaves the box is it an open or closed loop
system?
Open loop control
Open as the arrow can not change its trajectory whilst in flight. It cannot adjust to
compensate for unexpected external influences.
External
Influences
SYSTEM
INPUTS
Controller
SYSTEM
OUTPUTS
System
Under
Control
Digital
Actuators
Controller
Analogue
Sensors
Analogue
Actuators
23
Analogue
Sensors
P
R
O
C
E
S
S
Controller
P
R
O
C
E
S
S
Digital
Actuators
Analogue
Actuators
Input sub-processes
Digital information may require little, if any, processing before passing to the
controller. (This might include switch de-bounce, pulse shaping and code conversion.)
Analogue information generally requires more processing to present it to the
controller in a useable condition. (This might include amplification, filtering and
analogue to digital conversion.)
Output sub-processes
Digital information may require processing before passing to the actuator. (Darlington
current drivers)
Analogue information generally requires more processing to present it to the actuator
in a useable format. (digital to analogue conversion, filtering)
24
Interfaces
In order to protect the system controller and the end user from possible dangers due to
the malfunction of internal or external power supplies, controllers must be isolated
from the devices connected to them. This isolation is normally placed at the interface
between the input devices and the controller or the controller and output devices.
Digital
Sensors
Digital
Actuators
Input
Interface
Controller
Output
Interface
Analogue
Sensors
Analogue
Actuators
Along with this isolation the interface may also accommodate the signal conditioning
electronics needed for both the digital and analogue inputs and outputs.
Digital
Sensors
Digital
Interface
Digital
Interface
Digital
Actuators
Analogue
Interface
Analogue
Actuators
Controller
Analogue
Sensors
Analogue
Interface
25
Programs
A program is a structured list of commands that can be made to collect status
information from the external sub-system sensors, process this information and act to
make the sub-systems carry out the required process steps. The program is normally
stored within the controller and each controller can have a different method of
inserting the program.
Mechatronic systems examined
Lets look at some Mechatronic systems now.
Automatic camera
Take
Photo
Use
Flash
Aperture
output
I/P
Interface
Programmable
Unit
O/P
Interface
Light
Condition
Shutter
output
Film
wind
the user would simply indicate the use of flash or not then press the button to take
the photo
the light condition and the user I/P information would provide I/P data for the I/P
interface
the I/P interface would condition the I/P signals for the programmable unit
the programmable unit would process the I/P information as per the internal
program and deliver appropriate desired O/P signals to the O/P interface
the O/P interface would condition the O/P signals for the O/P actuators
the aperture would be set for best photograph
the shutter speed would be set and activated
the film would then be wound on for the next photo.
Automatic washing machine
Door
Closed
Drawer
Closed
Program
Selected
Cold
Water
Fill
Water
Level
I/P
Interface
Programmable
Unit
Temp
Level
Motor
Wash
Cycle
Motor
Spin
Cycle
O/P
Interface
Hot
Water
Fill
Waste
Pump
26
X axis
actuator
Position
X axis
Z axis
actuator
I/P
Interface
Position
Y axis
Programmable
Unit
O/P
Interface
End
effector
Tactile
info
Y axis
actuator
Speed
Limiter
Engine
Speed
I/P
Interface
Throttle
Position
Programmable
Unit
Engine
Temp
O/P
Interface
Head up
Display
Fuel
Delivery
27
The Engine Management System (EMS) takes control of many aspects of the car:
as the driver presses down on the accelerator so the information from the throttle
position sensor is passed to the I/P interface
the I/P interface conditions the I/P signal for the programmable unit
the programmable unit processes this signal as per the internal program and
delivers suitable O/P signals to the O/P interface
the O/P interface conditions this signal and feeds it to the fuel delivery system
at the same time, info from the engine speed sensor is passed to the I/P interface
which conditions the signal and passes it on to the programmable unit
the programmable unit processes this information as per the internal program and
delivers an appropriate signal to the O/P interface
the O/P interface conditions this O/P signal for the O/P actuators
the speed limiter can be activated if over reving engine
the engine speed can be sent to the head up display for the user
the fuel level signal can be fed again through the I/P interface
converted to a useable format
acted on by the programmable unit processed by the internal program and provided
to the O/P interface
the O/P interface conditions the signal for the O/P actuators
fed to the head up display for user
also used to display fuel consumption
engine temperature likewise is sent to the I/P interface
conditioned for the programmable unit
processed by the internal program and provide the O/P interface with a signal
the O/P interface conditions this signal for the O/P actuators
this signal is fed into the head up display for the user
the signal is also used to set fuel mixture levels.
Vending machine
Payment
made
Selection
Output
I/P
Interface
Programmable
Unit
Selection
made
O/P
Interface
Item
Output
the customer would make payment Correct payment would be sensed and
indicated at the I/P interface
the customer would make selection any selection made would be sensed and
indicated at the I/P interface
the I/P interface would condition the sensor signals for the programmable unit
(controller)
the programmable unit would process the sensor I/P signals as per the internal
program and deliver appropriate desired O/P signals to the O/P interface.
28
the O/P interface would condition the O/P signals for the O/P actuators
the selection O/P actuator would select the desired item
the selected item would be delivered to the customer.
As for the remaining systems it is left up to the reader to produce their own versions.
Computer controlled fitness equipment
Pick and place robot
29
From the start they had very limited memory, 64K maximum, and by todays
standards uncomfortably small hard disk drives around 10 MB, if they had a hard disk
at all. The operating system or O/S, more about this later, was a text based operating
system and not the graphical systems we are so used to today.
PC Architecture
MEMORY
INPUTS
OUTPUTS
INPUT
INTERFACE UNIT
OUTPUT
INTERFACE UNIT
ADDRESS BUS
CPU
DATA BUS
CONTROL BUS
The PC architecture
(note other format on page 3)
The CPU
The Central Processing Unit is the brain of the microprocessor. All fetch-execute
instructions originate from the CPU, all logic and mathematical functions are carried
out within the CPU and all data movement around the microprocessor is co-ordinated
by the CPU.
All of this co-ordination comes about because of an underlying sequence of
instructions held within memory, the program. The program can be user defined or
may be processor resident, put there by the manufacturer, known as micro code and is
stored in memory.
The Memory
Memory comes in two formats. Read Only Memory (ROM); this memory as it states
can only be read from, no data can be written to this type of memory.
30
ROM generally has the program burned into it by the manufacturer and is permanent
even when power is removed. This type of memory is said to be non-volatile.
Random Access Memory (RAM); this memory can have data read from and or
written to it repeatedly but will lose its contents when power is removed. This type of
memory is said to be volatile.
There are usually small areas of both of these types of memory manufactured into the
microprocessor. The amount of each type of memory included within each
microprocessor varies with manufacturer.
The ROM area is where micro code required for the correct internal operation of the
CPU will reside.
RAM will allow dynamically changing data to be temporarily stored and used within
the operation of a user program.
Both ROM and RAM memory exists in larger amounts external to the microprocessor
as well. This is where large user written programs and data would be stored; again
this memory is accessed directly by the microprocessor via the buses.
The Bus System
There are three buses involved in the processor:
the data bus that transfers data and instructions between memory and the CPU or
between the CPU and the memory, movement of data is bi-directional. Direction
is set using the control bus.
The control bus carries various signals that control the way the system responds to
both internal and external commands. Internal commands include the setting of
direction of data flow on the data bus, whether memory is being read from or
written to, whether the memory being accessed is actually part of the Input/Output
area, as the data handling commands differ for I/O operations. This bus can vary
considerably between different processors, is more complex than the other buses
and is dependent on the processor manufacturer (INTEL, MOTOROLA, AMD,
ZILOG.)
The address bus allows the CPU to pinpoint individual memory locations within
the system memory map. These memory locations originate from the CPU and are
dependent on whether the information required is program code or raw data. This
bus only has to work in one direction and so is known as uni-directional.
Input and Output Units (I/O)
Input. Communication with the computer is via some kind of input unit, which can
generally handle several peripherals. This communication is often referred to as the
man-machine interface. For example, the keyboard is an input device that interfaces
with the input unit and allows the operator to enter data, programs and operating
system commands into the computer. The mouse is another input device that allows a
graphical pointer to be easily moved about the video screen by the operator.
31
Output The computer communicates with us (the user) via the output unit, which
can generally handle several peripherals (external devices, printer, plotter, modem
etc.). This communication is known as machine-man interface. For example, the
output unit allows information from the computer to be displayed on a video monitor
or to be printed by a printer.
There are of course devices that act both as input and output devices. Examples are
disk drives, tape drives and modems.
Buses The CPU is connected to other internal parts of the computer by three sets of
parallel connections called buses, since they transport the information around the
computer. The data bus carries the data for processing and is a two-way or bidirectional system this can be 4, 8, 16 lines, each line carrying one bit at a time. The
address bus is a one-way or uni-directional system and conveys, as its name
implies, the various addresses required by the CPU, and has anything from 4 to 32
lines depending on the number of memory addresses. The final bus, the control bus
deals with timing signals and may have 3 to 10 or even more lines.
Operating system
Consider when we are writing and running a program in say assembly language we
start by:
run the editor program create a text file from the keyboard
temporarily store the text file
start up the compiler program
compile the stored text file assembly language file
store this program
start up the assembler
produce a machine language file from the stored assembly language file
finally you link the assembly language program with other pre-assembled
subroutines and library routines.
now you can finally run your program.
For all of these above operations consider what is taking care of all the transfer of
information between keyboard and PC, between microprocessor and RAM, from
RAM to (disk drive), between the disk drive and PC etc..? These are some of the
tasks of the operating system, a large complex program that oversees the loading of
user programs (the ones you write) and utility programs (editor, compiler, assembler
linker etc.) as well as the handling of I/O and interrupts, the creation and manipulation
of files.
32
Used on early IBM PCs and clones pre-1995; still used on some.
Used on later IBM PCs and clones 1995 on
Used on later IBM PCs and clones 1995 on
Used on IBM PCs successor (version also available for PC)
Created by Bell Labs; widely used on mainframe computers
Created by Linus Torvald as a UNIX-like operating system for
PCs as UNIX does not run on PCs
Created for Apple Mac computer systems
Created as an off-the-shelf operating system
There are also other operating systems available off-the-shelf for including in your
own designs, but they are complex.
These operating systems can be found included with some Microcontrollers and
ASICS whilst others have Operating Systems specifically written for them by the
manufacturers.
33
Hardwired logic
There is a requirement that 3 switches A, B and C activate an alarm unit (X) when the
switch configuration matches the following criteria:
The alarm (X) should sound whenever:
Switch A is HI and B is LO
or
Switch A is HI and C is LO
This problem mimics the type of safety system fitted to many industrial processes
such as the component access doors on a 10-ton machine press. Such a system has a
sensor, A, fitted to make sure the doors are firmly closed and there is no possibility
that the operators can have their hands within the presss work envelope. The second
input, B, comes from a foot-operated switch. The third input, C, checks for the
presence of a component within the press.
Design
To start the design for this section design tools will be employed that you may well
have not come across yet. You will not be required to remember these methods, but
they are being used here to prove a point.
In the design criteria above there are three inputs to the controller and one output.
If we have three inputs then we have a possible eight combinations at these inputs.
Truth Tables
But we are only interested in certain combinations, where the output (alarm) is to be
on. This can be seen in the truth table (a) below; remember, HI = 1 and LO = 0.
Firstly we are looking for any input status line where A = 1, B = 0 and C can have any
value.
A
0
0
0
0
1
1
1
1
I/P s
B
C
0
0
0
1
1
0
1
1
0
0
0
1
1
0
1
1
Truth table (a)
O/P
X
34
I/P s
B
C
0
0
0
1
1
0
1
1
0
0
0
1
1
0
1
1
Table x (b)
O/P
X
1
1
Now we are looking for any input status line where A = 1, C = 0 and B can have any
value.
A
0
0
0
0
1
1
1
1
I/P s
B
C
0
0
0
1
1
0
1
1
0
0
0
1
1
0
1
1
Table (c)
O/P
X
1
1
Again where these input conditions arise we want to see a HI or 1 at the output:
A
0
0
0
0
1
1
1
1
I/P s
B
C
0
0
0
1
1
0
1
1
0
0
0
1
1
0
1
1
Table (d)
O/P
X
0
0
0
0
1
1
1
0
35
36
37
Microcontrollers
What is a microcontroller?
A microcontroller is by nature, of the ASIC type. It is a System On Chip as explained
above. All microcontrollers have at their heart a microprocessor (CPU), which will
have RAM/ROM and I/O interfacing in one form or another. They will also have
some, but not necessarily all of the following:- A/D Converters, D/A Converters,
timers, serial interfaces, parallel interfaces, watchdog timers, oscillators, Pulse Width
Modulators.
The needs of embedded control
The needs of embedded control are very different from those of the standard personal
computers. For the life of the device, usually it will run only one program, apart for
the occasional program update. Because there is little support hardware; VDU,
keyboard, hard-drive or floppy disk there is little need for mass storage. Manmachine, machine-man interaction is also limited.
They are often required to operate in hostile environments such as high temperatures,
dust/corrosive atmospheres and perhaps both mechanically and electrically noisy.
The main features of a microcontroller system can be seen in the simplified diagram
below:
RAM
program
memory
PROGRAM
COUNTER
Arithmetic
Logic
Unit
ALU
clock
ROM
program
memory
I/O
ports
'Real'
world
timers
Microcontrollers contain all the features within a single package, as opposed to the
microprocessor system where each block in the diagram above is normally a separate
integrated circuit. In general the only component that needs to be added to a
microcontroller is a clock circuit, this can take the format of either a ceramic
resonator or a quartz crystal.
To give you a feeling for the characteristics and architecture of the microcontroller
Let us examine a microcontroller that has been designed especially for use in Higher
Still courses, the Basic Stamp microcontroller.
38
Stamp
Vin
+5V
7
6
5
4
3
2
1
0
GND
39
COMPUTER LINK
V+
0
1
2
3
POWER
BROWN OUT
REGULATOR
EEPROM
MICROCONTROLLER
0V
7
6
5
4
RESET
CLOCK
V+
0V
INPUT
OUTPUT
4 MHz
0 V V+
V+
V+
0V
4
0V
STAMP CONTROLLER
40
In order that you get a balanced introduction to microcontrollers, the following two
Intel microcontroller examples show their diversity:
Intel 8XC196MC Industrial Motor Control Microcontroller
Specifications:
3 S 32/16 divide
1.75 S 16 x 16 multiply
Idle and power down modes
Architecture:
VREF
ANGND
NMI
16
CPU
A/D
CONVERTER
488
BYTE
REGISTER
FILE
MICROCODE
ENGINE
S/H
MUX
16K ON-CHIP
ROM/OTPROM
(OPTIONAL)
INTERRUPT
CONTROLLER
ALU
PERIPHERAL
TRANSACTION
SERVER
MEMORY
CONTROLLER
QUEUE
16
TIMER 0
TIMER 1
PORT 0-1
A/D
PORT 0-1
EVENT
PROCESSOR
ARRAY
2 PWM
PORT 3
ADDR/DATA
BUS
PORT 4
3-PHASE
WAVEEFORM
GENERATOR
PORT O/1
PORT O/1
EPA
PORT 2
PORT 6
PORT 5
CONTROL
SIGNALS
WATCHDOG
TIMER
EXTINT
41
5 interrupt sources
Boolean processor
RAM ADDR.
REGISTER
RAM
PORT 0
DRIVERS
PORT 2
DRIVERS
PORT 0
LATCH
PORT 2
LATCH
EPROM
ROM
PROGRAM
ADDR
REGISTER
ACC
B
REGISTER
TMP 2
TIMING
AND
CONTROL
ALE
EA
RST
INSTRUCTION
REGISTER
ALU
PSEN
OSC.
XTAL 1
BUFFER
TMP 2
INTERRUPT, SERIAL PORT,
AND TIMER BLOCKS
PC
INCREMENTER
PROGRAM
COUNTER
PSW
DPTR
PORT 1
LATCH
PORT 3
LATCH
PORT 1
DRIVERS
PORT 3
DRIVERS
XTAL 2
42
As you can see from the previous pages microcontrollers are varied in the way they
are put together. It is entirely possible to pick up an off the shelf microcontroller for
just about any system. This, their size, their relative cost and their availabilty makes
them ideal for embedding in control systems which require little if no interference or
maintenance.
In the first Intel example the microcontroller has been designed specifically to deal
with an industry wide problem, the control of an AC motor. Motor control can be
carried out using discrete electronic circuitry but with this device fewer components
means less chance of circuit failure.
A 3-phase waveform generator is included on chip to be used in conjunction with an
inverter driver, which is a special arrangement of diodes. The device comes in
either a 64 pin format or in the 84 lead package.
The second example is an 8-bit microcontroller designed specifically for the
automotive area. The device comes in either a 40-pin or in a 44 pin package.
There are many other microcontroller manufacturers producing devices for an everwidening number of diverse applications.
Programmable Logic Controllers PLCs
What is a Programmable Logic Controller?
The Programmable Logic Controller (PLC) is a device, which was developed to
replace sequential relay circuits employed for plant control. The PLC operates by
examining the state of all inputs and depending upon their status, changing the outputs
to reflect the needs of the system.
PLCs are employed in many real world applications and are widely employed in
industrial locations. Machining, packaging, material handling, automated assembly
and many other situations. Just about any application that needs electrical control
could employ a PLC.
Control Bus
Address Bus
Data Bus
CPU
INPUT/
OUTPUT
MEMORY
CLOCK
The PLC consists of a Central Processing Unit (CPU), an area of memory and an area
to handle inputs and outputs. The PLC can be considered to be a box full of hundreds
or even thousands of separate relays, counters, timers and data storage locations.
These counters, timers etc. do not physically exist but rather they are simulated and
can be seen as software counters, timers etc.
INPUT
MODULE
OUTPUT
MODULE
PROGRAM
INPUT
PLC Architecture
43
44
Ladder Logic
What is ladder logic?
It is the graphical representation of how the system should react to changes at both its
inputs and its outputs.
The graphic symbols usually used are as follows:
Input rung of the ladder logic program
Output rung of the ladder logic program
or
Output Devices
The LOGIC in ladder logic programs is implemented in the way these inputs and
output symbols are connected. Below is a single rung of a ladder logic program.
In 1
In 2
out 1
out 1
In 2
Simple (one rung) Ladder Logic Program (or function)
The PLC has evolved to deal with digital switching but can be used to carry out
analogue control provided the correct analogue units have been added to the system.
These modules, usually provided by the same manufactured, allow the PLC to stay a
very flexible device. A minimal system usually forms the basis for a control problem
and extra modules are added as your systems requirement grows.
For more information about program writing in ladder logic and using LadSIM and
the ladder logic simulation program see the Programmable Controlled Systems (D147
12) Support notes.
45
46
PROGRAMMING
There are many different ways of visualising the internal architecture of the
microprocessor.
In the early days, computers were programmed by setting switches and by using patch
leads (this was the program). We have evolved since the days of toggle switches and
patch leads and now have these wonderful things called programming languages.
Without going into too much theory of computer science, the PC sitting on your desk
cannot, and never will be able to directly understand any word you care to say to it. If
you could open it up, apply your fingers to the internal tracks on the circuit board, and
tap out an electronic rhythm of 1s and 0s, then you might be approaching something
that could be called PC communication.
Writing computer programs this way would be tedious, error prone, and in reality
virtually impossible.
Traditionally programming languages have been divided into two forms, interpreted
and compiled.
Interpreted languages have a reputation for isolating their users from the system,
shielding them from the harsh realities of computer use and generally giving them a
very soft introduction to programming. Interpreted languages allocate the memory
requirements without the users knowledge. They also tend to be a lot slower and a lot
less slick than their compiled counterparts.
The reason for this latter point is simple. The interpreter adds code overheads which
are extra to the program. This makes the resulting machine code less efficient than a
version specifically tailored for the processors architecture.
Compiled Languages
A computer compiler takes your instructions and keywords (programs) and translates
them into the electronic 1s and 0s that the computer needs in order to be able to go
and do what you want it to do.
The original program is called the source program, sometimes referred to as the
source code. The machine language form of this program, after compilation, is called
the object code.
Once it has been translated into object code, it is linked with small, standard
procedure programs called library routines. It is these library routines that have
made compiled languages like C so popular due to the ability to selectively include
library files for different processor types, thus allowing cross platform compilation.
Compiled languages execute faster than interpreted programs, as they do not have the
burden of the underlying interpreter. Programmers using compiled language must
have a much better understanding of the memory requirements for their programs as
compilers leave this entirely up to the user.
DET: Mechatronic Systems: An Introduction (Higher)
47
Interpreted Languages
An interpreted program, on the other hand, does not immediately do what you want
it to do. It needs a program that sits in between the machine and your program.
When you run your program you are really running the interpreter which then happily
plods through your code one line at a time, transferring translated, interpreted
statements to the computer in a format it understands. It's a slow process, like talking
to someone through an interpreter.
Interpreted languages can alerts users to errors in statements at time of execution.
Interpreted languages also allow the user to execute a single statement before it is
included in the program.
This difference in languages is generally categorised into High-Level and Low-Level
Languages
Low-level languages (first and second-generation languages) provide binary
instructions for the computer to execute: these are known as machine languages.
High-level languages (third-generation languages) use English-like instructions that
cause the computer to carry out binary commands. They work at the level of the
programmer rather than at the level of the machine.
Low-Level Computer Languages
Machine Language (1st Generation Languages)
Expressed in binary, octal, or hexadecimal codes
Depends on the processor type
Assembly Language (2nd Generation Languages)
Expressed in abbreviations of commands: (mnemonics)
Depends on the processor type
User has complete control over the computers operations.
Executes faster than high level
High-Level Computer Languages
FORTRAN
FORmula TRANslator.
First high-level language, released in 1956.
Designed for scientific, mathematical, and engineering applications:
Compiled language - once compiled, extremely fast execution.
BASIC
Beginners All-purpose Symbolic Instruction Code.
Designed to be easy to learn, yet retain the formula translation characteristics
of FORTRAN. First used in 1964.
Current versions are much more powerful than early, simpler versions.
Very popular on personal computers.
Interpreted language, but compilers are available.
48
Pascal
Developed as a teaching language.
First released in 1971.
Programs must be written in a manner that meets accepted programming
standards. Enforces structured programming.
Now used for commercial applications as well as for teaching.
Most versions are compiled, but an interpreted version is available.
C
Developed at Bell Labs in 1974.
Produces machine-language code that executes extremely fast.
Allows a high degree of control over the machine.
Easily portable among computers and operating systems.
Many commercial programs are written in C.
Compiled language.
Very High-Level Languages
Often known as fourth-generation languages (4GLs).
Move the programmer even further away from the machine-code level than
high-level or third-generation languages.
They are usually nonprocedural - a user need write only what is to be done,
not how.
Natural Languages
Natural languages are closer to everyday human languages.
Natural languages excel at easy data access and are most commonly used to
interact with databases.
Object-Oriented Programming
Use objects (self-contained items that combine data and algorithm) instead of
structured programming.
Object-oriented programming languages:
Smalltalk
C++
Turbo Pascal
Your choice of programming languages should not be based solely on the ease of a
language to learn, however. You should also think carefully about the sort of tasks
you are likely to want your programs to perform. As noted, Perl is very well suited for
text manipulations and related tasks, but C would probably be preferred for a program
that needs to do a good deal of number crunching.
49