Mechatronics I
Moumen T. El-Melegy
Electrical Engineering Engineering
Assiut University
Assiut 71516
Mechatronics I
MECHATRONICS I:
INTRODUCTION TO MECHATRONICS
Mechatronics I
Controller
Mechatronics I
Lecture Outline
Controller types
Microcontroller
Microprocessor
Microprocessor controller interfacing
Microprocessor controller programming
Mechatronics I
A Mechatronics System
Mechatronics I
Controller
The “heart” and “brain” of the mechatronics
system
an analog or digital circuit that accepts data
from the sensors, makes a decision, and
sends the appropriate commands to the
actuator.
In general, the controller is trying to keep the
controlled variable—such as temperature,
liquid level, position, or velocity—at a
certain value called the set point (SP).
Mechatronics I
Controller Types
Analog circuit alone
Digital circuit alone
Microprocessor based
Programmable Logic Controller
Microcontroller
Single-board computer
controllers
Personal Computer
Digital Signal Processor
Mechatronics I
I- Analog Circuits
Simple analog signal processing circuits
consisting of op amps and transistors.
Op amps can be used to perform comparisons and
mathematical operations such as analog addition,
subtraction, integration and differentiation (i.e., all
required operations to provide control signal in PID
controllers).
Simple to design and easy to implement.
Example: controller in magnetic levitation project.
Mechatronics I
I- Analog Circuits
Mechatronics I
II- Digital Circuits
If the input signals are
digital or can be
converted to digital, then
combinational or
sequential logic
controllers may be used.
Variety of specialized
digital devices can ease
the design task, such as
multiplexers, program
logic arrays (PLA), and
read only memory (ROM).
Easy and standard to
design.
Mechatronics I
Microprocessor based controllers
Some reasons for using a digital, microprocessor design in control
systems are the following:
A microprocessor can easily handle complex calculations and
control strategies.
Low-level signals from sensors, once converted to digital, can be
transmitted long distances virtually error-free.
Long-term memory is available to keep track of parameters in
slow-moving systems.
Changing the control strategy is easy by loading in a new
program; no hardware changes are required.
Microprocessor-based controllers are more easily connected to
the computer network within an organization. This allows
designers to enter program changes and read current system
status from their desk terminals.
Mechatronics I
III- Microcontrollers
A microcontroller is a computer on a single IC,
designed specifically for control applications.
It consists of a microprocessor, memory (both RAM
and ROM), I/O ports, and possibly other features such
as timers and ADCs/DACs.
Having the complete controller on a single chip allows
the hardware design to be simple and very
inexpensive.
Microcontrollers are showing up increasingly in
products as varied as industrial applications, home
appliances, and toys. In such uses as these, they are
called embedded controllers because the controller is
located physically in the equipment being controlled.
Mechatronics I
III- Microcontrollers
Mechatronics I
Microcontrollers vs. Microprocessor
Microcontroller Microprocessor
More suitable for More suitable for general-
embedded control or purpose computing.
embedded computing
CPU plus code and data CPU only. Code and data
memory. memory is external to the
CPU.
Peripherals e.g. timers, Very few or no
counters, analog-to-digital peripherals.
converters, pulse-width
modulation, networking,
power control.
Mechatronics I
Microcontrollers vs. Microprocessor
Microcontroller Microprocessor
Bit-oriented instructions. Large data word
instructions for increased
processing capability.
Can be used as a stand- Needs support chips to
alone chip. make a viable system.
Mechatronics I
Popular Microcontrollers
Mechatronics I
Popular Microcontrollers
Mechatronics I
Popular Microcontrollers
Mechatronics I
Popular Microcontrollers - The 68HC11
From Motorola
8-bit data
16-bit address
CISC processor
Running at 2MHz
built-in EEPROM and RAM
several digital I/O lines
timers
A/D converters,
a PWM generator, and
an RS232 communication channel
Mechatronics I
How to select a microcontroller?
Number of bits (8, 16 or 32)
Number of available I/O lines
Included devices (ADC, timers, counters, PWM
circuits, …)
Speed
Availability
Cost
Mechatronics I
IV- Digital signal Processors (DSP)
DSP devices are in many ways similar to microcontrollers
with respect to peripheral integration, power consumption,
etc.
They are designed to support high-performance, repetitive,
numerically intensive tasks.
For example, DSPs may be able to do two multiply
operations at the same time, can perform tight, quick loops,
and have irregular instructions sets that allow several
instructions to be encoded in the same instruction.
DSP is good for control operations where multiple-axis
operation and quick response are required.
DSP devices are ideal for use in systems that process
blocks of data, such as speech, video and music, or for
robust control and communications applications.
Mechatronics I
V- Programmable Logic Controllers (PLC)
A small, self-contained, rugged computer
designed to control processes and events in an
industrial environment.
An improvement over the older hard-wired relay
logic logic controllers.
Wires from switches, sensors, and other input
devices are attached directly to the PLC; wires
driving lights, small motors, motor starters, and
other output devices are also connected directly
to the PLC.
Mechatronics I
V- Programmable Logic Controllers (PLC)
Each PLC contains a microprocessor that has
been programmed to drive the output terminals in
a specified manner, based on the signals from the
input terminals.
The PLC program is usually developed on a
separate computer such as a personal computer
(PC) via Ladder Diagram Programming, using
special software provided by the PLC
manufacturer.
Once the program has been written, it is
transferred, or downloaded, into the PLC. From
this point on, the PLC may operate on its own, as
a completely independent controller.
Mechatronics I
Programmable Logic Controllers (PLC)
A PLC and its related
components.
Mechatronics I
Programmable Logic Controllers (PLC)
Block diagram of a PLC
Mechatronics I
VI- Single-Board Computers
Good alternative when an application requires more
features or resources than can be found on a typical
microcontroller and when size is not a major concern.
Single-board computers are off-the-shelf microprocessor-
based computers built on a single printed-circuit card.
They come in many configurations, but in general they use
a standard microprocessor such as the Zilog Z80, the Intel
x86 family, or the Motorola 68000.
They also include memory ICs (both RAM and ROM), I/O
capability, and perhaps special interface circuits such as
ADCs or DACs.
This is particularly important in small-volume production
or one-of-kind systems.
Mechatronics I
VII- Personal Computers (PC)
The availability of relatively low-cost, off-the-shelf
personal computers (PCs) has made them an
attractive alternative for small, one-of-kind control
applications.
Easier user interaction via PC console (keyboard +
screen).
PC is easily interfaced to sensors and actuators using
PC’s parallel, serial and USB ports or the
commercially available plug-in data acquisition cards.
Control system software packages are commercially
available for the PC that run under DOS and Windows.
Mechatronics I
VII- Personal Computers (PC)
These programs are adaptable and allow the user to
tailor the software to fit the control application,
essentially turning a PC into a PLC (although not as
rugged).
Most of these packages use interactive graphics to
link animation with changing process values. Some
programs have provisions to mathematically simulate
the process being controlled to help optimize the
controller coefficients.
Mechatronics I
Distributed Control System (DCS)
In this system, each process has its own separate
controller located at the site.
These local controllers are interconnected via a local
area network so that all controllers on the network
can be monitored or controlled from a single
supervisory computer (master controller).
Mechatronics I
Microprocessor Fundamentals
Mechatronics I
What is a Microprocessor (CPU)?
Mechatronics I
Interfacing to a Microprocessor Controller
For a digital controller, data enter and exit
through a parallel interface or through a
serial interface.
Mechatronics I
Parallel Interface
The parallel interface transfers data 8 bits (or more)
at the same time, using eight separate wires.
The parallel interface is ideal for inputting or
outputting data from devices that are either on or
off.
To connect to an analog device, a ADC or DAC is
required.
If parallel port cannot provide enough current, use
bus transceiver (e.g., the uni-directional 74244 or
the bi-directional 74245)
Mechatronics I
A
control
system
using
parallel
ports
Mechatronics I
Bus transceiver
Mechatronics I
Bus transceiver
Mechatronics I
Bus transceiver
Mechatronics I
Bus transceiver
Mechatronics I
Serial Interface
In a serial interface, the data are sent 1 bit after the other
on a single wire.
Cabling is simpler because only two wires are needed
(at a minimum), those being “data” and “return.”
Second, shielding a small group of wires, which is often
necessary in an electrically noisy industrial
environment, is easier.
Serial data can make use of existing single-channel data
lines such as the telephone system (which may require
using a modem).
Serial data transfer is usually recommended for
distances greater than 10-30 ft.
Mechatronics I
Serial Interface
Because data always exist in a parallel form inside
the computer, it must be converted to serial data
by a special parallel-to-serial converter IC called a
universal asynchronous receiver transmitter
(UART).
Mechatronics I
Serial Interface
A byte of data is sent in a package of (10 on the
average) bits.
Standard bit rates are 300 bps (bits per second),
1200 bps, 2400 bps, 9600 bps, 14,400 bps 28,800
bps, 33,600 bps, and 57,600 bps.
Mechatronics I
I/O Port Addressing
Each I/O port must have an address.
I/O Addressing
Memory mapped
Isolated
Mechatronics I
Memory-Mapped Ports
I/O device appears as if was in memory.
Example: Port B has address $1004 in 68HC11
Can use normal data movement instructions
to/from memory, e.g., LDAA in 68HC11
Typically used in microcontrollers.
Mechatronics I
Isolated Ports
Separate from memory address
Has own address space.
Example: PC parallel port has address $3F8
Use instruction for data movement to/from ports,
e.g., IN and OUT in Assembly language for INTEL
x68.
Typically used in PCs.
Mechatronics I
Microprocessor Controller Programming
A digital, microprocessor-based controller is a
computer operating in real time.
This means that the program is running all the time—
repeatedly taking in the newest sensor data and then
calculating a new output for the actuator.
The basic structure of a controller program is a loop.
In a loop structure, the same sequence of instructions
is executed over and over again, and each pass
through the loop is called an iteration, or scan.
Mechatronics I
Microprocessor Controller Programming
The time it takes for the computer to
execute one pass through the loop
determines the time interval between
input readings (known as the
sampling rate).
If this interval is too long, the
computer may not get an accurate
picture of what the controlled variable
is really doing (aliasing).
Execution of the loop can be
accelerated by specifying a faster
computer or streamlining the
program.
Mechatronics I
Microprocessor Controller Programming
In other situations, the computer must pause and wait. For
example, a pause might be inserted to give an operator time
to make some adjustment or to allow time for a motor to
“spin down.” This is done by inserting time-delay loops in
the program.
A time-delay loop is simply a do-nothing, “wheel-spinning”
loop where the computer is instructed to count up to some
large number. Using this technique, we can make the
program pause for any length of time—from a few
microseconds to hours.
If a time-delay loop is inserted in the main program loop, the
effect is to slow the cycle time for the main loop.
This is sometimes done to force matching of the sample rate
to some predetermined value.
Mechatronics I
Microprocessor Programming Languages
Microprocessor controllers are most commonly
programmed in low-level languages for maximum control
over the hardware resources.
Traditionally, the programmer would directly select the
machine language instructions.
Today, sophisticated compilers can convert a program
written in a high-level language, primarily C, into very
efficient machine language.
The most time-critical sections of the code are generally
programmed in assembly language, which is the lowest-
level language understood by a microcontroller.
Mechatronics I
Microprocessor Programming Languages
Using a high-level language (primarily C) to write programs
for a microprocessor offers big advantages, such as more
compact program listing, ease of writing equations, and
more comprehensible documentation.
Also, programs written in a high-level language can be
compiled to run on any model of microprocessor.
Even higher-level languages, such as C++ or Java, are not
well suited for embedded programming as they require
larger amounts of memory and are not designed for low-
level access to hardware resources.
Mechatronics I
Microprocessor Programming Languages
Fragment of an assembly language program written for the Microchip PIC
16F84A microcontroller. It enables power to a DC motor (through an
external interface circuit) when two digital inputs are both at a logic 1
level. The code runs continuously, always checking for the status of the
two digital inputs (which may be manual switches, current sensors, etc.).
Mechatronics I
Microprocessor Programming Languages
Fragment of C code to effect the same functionality as the
Assembly code. The code is more compact and easier to
read since C is a higher-level language than Assembly.
Mechatronics I
Data Acquisition Procedures
Polling method
Hardware interrupt method
Direct memory access (DMA) method
Mechatronics I
Polling Method
Polling is the sequential testing of the
status of an I/O device to determine
whenever service is required.
CPU becomes busy checking otherwise
I/O signal is missed
Simpler to implement
Mechatronics I
Polling Method
Program triggers I/O
device
Program reads I/O device
status bit
No Is bit set?
Yes
Program reads data
(status bit reset)
Program delay
Mechatronics I
Hardware Interrupt Method
I/O signals the CPU such that it pauses
whatever it is doing and executes an
interrupt-service routine (ISR) to handle
the I/O.
Once the ISR has serviced the interrupt,
the paused program is resumed.
Saves the CPU time
Rather complicated and involved.
Mechatronics I
Hardware Interrupt Method
Program initializes
interrupt mechanism
Program triggers I/O device
and can do other things
I/O device generates an
interrupt request
CPU is interrupted and
executes ISR to read the
CPU resumes
Program delay
Mechatronics I
Direct-Memory-Access Method
Permits direct transfer of data to memory
without interrupting the CPU.
Saves the CPU time.
Complicated.
Mechatronics I
Direct-Memory-Access Method
Program initializes
interrupt mechanism
Program triggers I/O device
and can do other things
I/O device generates an
interrupt request
Program delay
Mechatronics I
Dig More
W.D. Cooper and A.D. Helfrick, “Electronic
Instrumentation and Measurement Techniques”, 3rd
Ed., Prentice Hall.
Christopher Kilian, “Modern Control Technology:
Components and Systems”, Delmar Thomson
Learning, 2nd Ed., Dec. 2000.
N. Mahalik, “Mechatronics: Principles, Concepts
and Applications”, Tata McGraw-Hill, 2003.