Sunteți pe pagina 1din 53

ME262

Introduction to Microprocessor &


Digital Logic
(PLC and PLC Programming)
Summer 2010

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Electrical Circuits
A simple Electric Circuit is a closed connection of Power Supplies ,
Switches/Sensors and Wires. An Electric Circuit consist of voltage loops and current
nodes

The Electrical Circuits can be presented by ladder diagram.


diagram

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Sensors/ Switches
Switches
A switch is a mechanical device that either opens or closes sets of contacts inside
th body
the
b d off the
th switch.
it h

There are also multiple contact switches


utilized in electrical circuits. The contacts
in the switch change states from either
open to closed or vice versa, when the
switch is being operated.
operated

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Proximity Switches
The proximity switch can be either magnetic, inductive or capacitive. Magnetic
switches are usually adjustable, in that they can be moved along the length of
cylinder body to any desired position.
A magnetic strip attached to the piston gives a magnetic field which is sensed by the
reed switch when it is in its proximity.

Courtesy of Parker

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Optical Sensor
The optical switch, as its name implies, uses light to establish the position of objects
that are required to be sensed. The beam type has a sender, light sources and a
receiver. The light source shines a light beam into the receiver. When the light beam
i broken
is
b k by
b an object
bj t the
th state
t t off the
th electrical
l t i l output
t t from
f
he
h receiver
i
changers.
h

Courtesy of Festo

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Relays
The relay is widely used in electrical circuits. Applications range from classical
panel built control systems to modern interfaces between the microprocessor and
their power circuits or any applications where reliable galvanic separation is
required between different circuits.

Relay coil

Relay contact

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Timer, Counter
These two device are widely used in Electrical Circuits.
Timer contains of coil and contacts. When the timer coil is activated, the timer
mechanism starts working, and as soon as the time reaches the desired pre-set time,
the timer contacts switch over.
The counter also acts as the timer.

Timer contact

Counter contact

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Symbols
General normally open toggle switch

General normally close toggle switch


Alternative

Alternative

Pushbutton

Limit switch NO

Temperature sensor

Limit switch NC

Proximity limit switch

Pressure switch

Time delay

Indicator lamp

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

PLC as a brain in automation and control lines

PLC

Sensors

Actuators

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

Why PLC?

Increased Reliability
Increased Flexibility
C
Communication
i ti Feature
F t
Better real-time Performance
Lower Cost

Why not PC?

Electric Noise
Operating System
Computing Power
Input/output Connections and Wiring
Software
Shock
D st
Dust
Cost
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

10

PLC Hardware
Power Supply

Digital
Input
Module

Central Processing Unit


(CPU)

Digital
Output
Module

Memory
Program Data

Analog
Input
Module

Analog
Output
Module

Ethernet
Interface
Profibus
Programming
Device

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

11

PLC Architecture Block Diagram

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

12

PLC Size
Nano PLCs

Fitted in shirt pocket and handles up to 16 I/O

Micro
Mi
PLC
PLCs

connected
d up to 32 I/O
/O ddevices
i

Small PLCs

Connected up to 960 I/O in a single Rack

Medium PLCs
Large PLCs

More features such as Analogues modules


Connected to several thousands I/O devices

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

13

Power Supply Module


Typically, this module takes 110/220 V and provides the low
Typically
voltage (5/12/24 V DC) for the other modules.

CPU Module
The most important PLC-hardware is the central processing
unit (CPU), which corresponds to a computer in structure.
The processes take place in the central control unit. The data,
processedd andd storedd in
i the
h CPU are in
i the
h form
f
off binary
bi
signals. The CPU can usually manage many timers and
counters.

Memory

Communication
C
i ti Port
P t
Serial/parallel, 486 IEEE,..
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

14

I/O Module
The input/output modules are connected to sensors/actuators to obtain the binary
information from the system and implement the requested logics.

Wiring diagram
for Input
Module with 16
inputs

+
DC

To PLC

Two typical opto-isolators for


AC & DC inputs
AC

To PLC

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

15

I/O Module

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

16

Wiring diagram
for output
Module with 16
outputs

Out 1
Out Com

PLC

TTL Output Unit

Out 1

Out 1

Out Com

Out Com

Out 1

Out Com

PLC

PLC

Transistor Sinking
Output (NPN)

Transistor Sourcing
Output (PNP)

PLC

Triac Output
Unit (AC)

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

17

I/O Module

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

18

Analogue Input/output Module


The analogue input/output modules are connected to analogue sensors/actuators to
obtain the continuous information (0-10 DC V or 4-20 mA current) from the system
and implement the requested logics. There are different form of analogue input/output
modules in terms of number of inputs/outputs.
inputs/outputs However,
However any module comes with
many ports which can be connected to the sensors or actuators based on the shown
diagrams.

Wiring diagram for


Analogue Input Module
with 8 inputs

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

19

Wiring
Wi
i diagram
di
for
f
Analogue Output Module
with 8 outputs

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

20

Interface Module
This module is used to communicate with other PLCs or control systems through
Serial/Parallel, Ethernet, Profibus FMS,VME, etc. A number of standard protocols are
implemented and allow data transfer with a wide variety of stations.

Courtesy of Siemens
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

21

PLC Programming
g
g
PLC program languages are categorized into three classes:
1.

Statement list program (STL)

2.

Ladder Diagram (LAD)

3.

Function Chart (FUC)

Processor memory structure and organization


Housekeeping
p g memory
y

Used to carry out functions


required for processor operate
(No access by user)

User program

Programs that operate the


PLC in for a particular task

Data table

Input/output , flags, timer,


counter locations

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

22

Program Files
System
S
fil
files
Reserved
Main ladder/STL/FUC pprogram
g

Data Files

Output
O
t t
Input
Status
Bit
Timer
Counter
Integer
Reserved
Net ork Comm
Network
Communication
nication
User-defined
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

23

Input/Output Imaging

M
0
I
N
P
U
T

1 IInputt
0 Image

0
MEMORY

Output
O
t t 1
Image
0
1

Data bus

C.P.U.

A.L.U.

O
U
T
P
U
T

K.B.,
Port,
H/D,
Etc.

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

24

Operating Cycle

Initialization

Set Output
Output
Set

Self-Test
PLC
SCAN
CYCLE

Solve Logic
Solve
Logic

Read Input
Input
Read

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

25

Read Inputs and Outputs


and copy into memory.

Do the overhead work


required to keep the
process working
properly.
l

1
Service
S
i
Comm
etc.

Input
Scan

Output
Scan

Program
Scan
3

Update Outputs based


on the values in
memory.

Execute PLC program with


Input variable being read
from the memory and the
Output being updated in
memory
memory.

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

26

Response time
1

IN

RUN

Scan 1

Pulse Stretch

OUT

IN

RUN

OUT

IN

Scan 2

RUN

OUT

Scan 3

Interrupt Function

Scan
IN

RUN

OUT

IN

Scan
IN

RUN

OUT

Pulse Stretch
Interrupt

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

27

PLC addresses
The following letters are used for the modules (For Siemenss PLCs):
I= Input
C= Counter
C

O= Output

F= Flag

RI= Analogue Input


RI

T= Timer
RO=Analogue
RO
Analogue Output

How to realize the address in a general fashion?

ZXX.YY
bit address or desired I/O
number on module

Type of Module

assigned address of module in PLC rack


I0

O1

O2

0
1
2

Power
supply

3
4
5
6
7

I0.6
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

28

Ladder Diagram Elements

NO Switch: Normally Open Switch

NC Switch: Normally Closed Switch

NO Output

NC Output

Function Block

FUN (name)
Parameter 1
Parameter 2 (opt)
.
.
Parameter N (opt)

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

29

Rung

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

30

Example
Sink

Rung

Output 1
Output_1

Output 2
Output_2

Conditions In

Results Out

Source

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

31

Digital Logic and Ladder Diagram


AND
X

X
0
0
1
1

Z
X

Y
0
1
0
1
Truth Table

Z
0
0
0
1

Z=XY
OR

X
0
0
1
1

0
1
0
1

0
1
1
1

Truth Table

Z=X+Y
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

32

NOT
X

Y
X

Truth Table

Y=X
XOR

Z
X
Z
Y

X
0
0
1
1

Y
0
1
0
1

Z
0
1
1
0

Truth Table

Z=X Y
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

33

Example 1: Program the following Boolean expression by ladder diagram

Z (X Y)

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

34

General Programming Rules


(Utilized in OMRON PLCs)

Switches can be reused in a ladder diagram:


SW_C
SW_C

SW_D

Output_E

SW_D
END (01)

Any number of switches can be used to generate the rung


condition:
SW_A

SW_B

SW_N

Output_A

SW_A2

SW_AN

END (01)

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

35

Common Errors

SW_1

Output_1
END (01)

SW_1

Output_1

SW_N

Output_1

Output_NoGood
TIM
000
#0020

END ((01))

Problem:
Causing
g Logical
g
Error !!!

END (01)

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

36

Important Functions

(OMRON)

SET andd RESET functions


f ti
Set
Button

SET

Set
Button
Output

Reset
Button

Reset
Button

RESET

Output
Output

INC function

Start Count
INC

Start
Count

DMxxxx

DMxxxx

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

37

TIM and TIMH Functions


Start Time

TIM
xxx

Start
Time

Set Value
Present
V l
Value
TIMxxx

TIMxxx

Output
Output

TIM interval= 0.1 second


TIMH interval= 0.01 second
CNT Function
Start Count
CNT
Reset Count

xxx
Set Value

Start
Count
Reset
Count

Present
Value

CNTxxx

Output
Output

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

38

CNTR Function
Count UP
Count
Up
CNTR
Count Down

Count
Down
xxx
Reset
Count

Count Down

Set Value
Present
Value

CNTxxx

Output

Output

DIFU Function
Input
p _SW
DIFU

Input_SW

OneShotOut

O Sh tO t
OneShotOut

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

39

DIFD Function
Input_SW
Input_SW

DIFD
OneShotOut

OneShotOut

MOV Function
Input_SW

MOV

Input_SW

Source
Destination

Source

Destination

2918

0000

2918

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

40

Status Monitoring

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

41

The Procedure for writing a PLC program


Control Task

Understanding the required Logic


Allocation List
LAD, STL, FUC programming
Transmission to the PLC

RUN

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

42

Example
Q: A lamp (H1) is to remain switched on as long as push button S1 and either one
or both of the push buttons S2 and S3 are actuated.

I0
S1

S2

S3

H1

0
0
0
1

0
1
1
0

1
0
1
0

0
0
0
0

1
1
1

0
1
1

1
0
1

Truth table

0
1
1
1

S1
S2

O0

0
1

0
1

H1

S3

-Circuit diagram

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

43

Allocation List
Designation

Abbrev.

Push button S1

S1

I0.0

Push button S2

S2

I0.1

P h bbutton S3
Push

S3

I0 2
I0.2

H1

O0.0

Light H1
S2S3
S1

S3
00

S3
01

S3
10

11

0
S1

Address

Function
I0.0, I0.1, I0.2 carry 1, as long
as push button actuated

Light is lit when O0.0 carries 1

I0.0

I0.1

O0.0

S1

S2

I0.2

S2

S1S 3

S1S 2

H1 S1 ( S 2 S3 )
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

44

Example 2:

A conveyor is run by a motor that can move in either direction. The


conveyor moves in the forward direction when output F is turned ON, and moves in the
backward direction if output B is ON.
ON There are two start buttons (one for each direction)
called SF and SB, and a single stop button called STOP. The user has to push STOP before
being able to change the direction of motion of the conveyor. There is also an overload
sensor OL that stops the conveyor if the motor overheats. Write a LAD program (Using CX
Programmer Command of OMRON) for:
a) The conveyor starts moving when SF or SB is depressed (and is not yet moving)
b) The conveyor stops moving when STOP is depressed or OL is ON

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

45

State Diagram
g

A state diagram is used to show a sequential logic graphically.

Definition of Sequential Logic

The output (s) of a sequential circuit depends on the current


and past states of the inputs
inputs.

State Diagram Elements


A state diagram consists of inputs, outputs, and states. A state of a logic system is a
unique configuration that the system can take.
Combinational Logic that causes
a transition from one state to the
next state
State
Number

Transition

Outputs

STATE
William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

46

State Diagram Elements in a Digital Fashion


Based on the number of states a binary number is given to each state.
state
All combinational logics that
don't cause a transition

Inputs requires for transition


from state 0 to state 1
000

001

Outputs (0)

Outputs (1)
0 to 2

3 to 2
011
Outputs (3)

010
Outputs (2)

4 to 0

2 to 6

110
100

1 to 3

Outputs (6)
4 tto 5

p ((4))
Outputs
6 to 4
7 to 6

101
111
Outputs (5)
Outputs (7)
5 to 7

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

47

The governed logic can be simplified using the state diagram drawn for the desired system.
This simplification is possible if transitions occur from one state to the other state in which
only
l one bit
bi is
i changed
h
d (e.g.,
(
from
f
state 010 to 011),
011) otherwise
h
i we cannot simplified
i lifi d the
h
equation.

How to write a ladder pprogram


g
from a state diagram
g
Number each state uniquely and allocate enough bits for a state identifier.
For the number of state identifier bits consider SET and RESET functions.
For each output variable, create a rung ORing the states in which it is active.
For each state transition, create a rung as follows:

1.
2.
3.
4.

SET

F2F1F0

F2F1F0

101

F2

F1

100

TIM001

F2

RESET

Stop

TIM001, A, D
X+, Z+, TIM001

F0

F1

Z-, Gr, TIM002


RESET

Stop
Current
State

Transition
C diti
Conditions

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

New
State

F0

48

Example

A conveyer iis controlled


t ll d by
b a pushbutton
hb tt switch.
it h When
Wh the
th switch
it h is
i depressed
d
d
the conveyer:

Moves forward if it is moving backward,

Moves backward if it is moving forward.


forward

Backward Motion

Motor (M)

Forward Motion

Pushbutton Switch (I)

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

49

IInputs:
t
Pushbutton Switch (I)
Output:
Motor forward (MF)
Motor backward (MB)

M=0

M=1

MF: ON

MB: ON

States:
State 1 (0)- Conveyer moves forward
State 2 (1)- Conveyer moves backward

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

50

1. Number each state uniquely and allocate enough bits for a state variable. For
the example, we have two states and hence, one bit is sufficient.

M: State variable
M = 0,

State 1: Conveyer moves forward

M = 11, State 2: Conveyer


Con e er moves
mo es backward
back ard
2. For the number of state variable bits consider SET and RESET functions, (if you
use OMRON PLC
PLCs);
) otherwise
th
i a virtual
i t l relay
l (FLAG) can bbe used.
d
3. For each output variable, create a rung ORing the states in which it is active,
4. Use SET and RESET functions by ANDing the bits of the previous state and the
condition for the transition from the previous state to the new state.

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

51

MB

MF

I
SET
M

I
RESET
M

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

52

How to find a simplified expression for states bits


State diagram can be used in deriving simplified expressions for states bits.
bits This
is possible if there is no any double transition from one state to the other state; in
fact only one change in the bits combination from one state to the other state. In
this approach, we try to find the ON and OFF statuses of each bit not the State.
If thats a case, the expression for each bit can be found by:

M X (Y memory)
where X is the turn off signal and Y is the turn on signal for State M.
In order to study the state diagram approach, the following example is solved step
step-byby
step.

William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10

53

S-ar putea să vă placă și