53
ME262 Introduction to Microprocessor & Digital Logic (PLC and PLC Programming) (PLC and PLC Programming) Summer 2010 William W. Melek: Introduction to Microprocessor and Digital Logic, ME262, University of Waterloo, S'10 1

Introduction to Microprocessor & Digital Logicmme.uwaterloo.ca/~me262/Chapter 5.pdf · The Electrical Circuits can be presented by ladder diagram. ... Introduction to Microprocessor

Embed Size (px)

Citation preview

ME262

Introduction to Microprocessor & Digital Logic

(PLC and PLC Programming)(PLC and PLC Programming)Summer 2010

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

Electrical CircuitsA simple Electric Circuit is a closed connection of Power Supplies ,Switches/Sensors and Wires. An Electric Circuit consist of voltage loops and currentnodesnodes

The Electrical Circuits can be presented by ladder diagramThe Electrical Circuits can be presented by ladder diagram.

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

Sensors/ SwitchesSwitches

A switch is a mechanical device that either opens or closes sets of contacts inside th b d f th it hthe body of the switch.

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

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

switch is being operated.

Proximity SwitchesThe 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 theA magnetic strip attached to the piston gives a magnetic field which is sensed by the reed switch when it is in its proximity.

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

Courtesy of Parker

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 b k b bj t th t t f th l t i l t t f h i his broken by an object the state of the electrical output from he receiver changers.

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

Courtesy of Festo

RelaysThe 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.

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

Relay coil Relay contact

Timer, CounterThese 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 7

Symbols

General normally open toggle switch General normally close toggle switch

Alternative Alternative

Limit switch NOPushbutton Limit switch NC

Temperature sensor Proximity limit switch Time delayTemperature sensor Proximity limit switch Time delay

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

Pressure switch Indicator lamp

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 9

Why PLC?• Increased Reliability• Increased Flexibility

C i ti F t• Communication Feature• Better real-time Performance• Lower Cost

Why not PC?• Electric Noise • Operating System • Computing Power• Input/output Connections and WiringInput/output Connections and Wiring • Software• Shock

D st

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

• Dust• Cost

PLC HardwarePower Supply

DigitalOutputModule

DigitalInput

Module

Central Processing Unit(CPU)

AnalogOutput

AnalogInput

Memory

Program Data

ModuleModule

EthernetInterface

ProgrammingDevice

Profibus

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

Device

PLC Architecture Block Diagram

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

PLC Size

• Nano PLCs

Mi PLC

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

d 32 /O d i• Micro PLCs

• Small PLCs

connected up to 32 I/O devices

Connected up to 960 I/O in a single Rack

• Medium PLCs More features such as Analogues modules

• Large PLCs 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 lowTypically, this module takes 110/220 V and provides the low 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,

d d d i h i h f f biprocessed and stored in the CPU are in the form of binary signals. The CPU can usually manage many timers and counters.

C i ti P t

Memory

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

Communication PortSerial/parallel, 486 IEEE,..

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

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

AC To PLC

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 1Out 1

Out Com

PLC

TTL Output Unit

Out 1 Out 1 Out 1

Out Com

PLC

Out Com

PLC

Out Com

PLC

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

Transistor Sinking Output (NPN)

Transistor Sourcing Output (PNP)

Triac Output Unit (AC)

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 However any module comes withmodules in terms of number of inputs/outputs. 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

Wi i di fWiring diagram for 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.

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

PLC Programmingg gPLC program languages are categorized into three classes:

1. Statement list program (STL)

2. Ladder Diagram (LAD)

3. Function Chart (FUC)

Housekeeping memoryUsed to carry out functions

required for processor operate

Processor memory structure and organization

User program

p g y

Programs that operate thePLC in for a particular task

required for processor operate(No access by user)

Data table Input/output , flags, timer,counter locations

PLC in for a particular task

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

counter locations

Program Files

S fil• System files• Reserved• Main ladder/STL/FUC program

Data FilesO t t

p g

• Output• Input• Status• Bit• Timer• CounterCounter• Integer• Reserved

Net ork Comm nication

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

• Network Communication• User-defined

Input/Output Imaging

I t O t t

0

1

M

~0

1MEMORYI

NPUT

OUTPU

Input Image

Output Image

1

0

1 C

1

0

1

Data bus

K.B.,Port,

T UT

C.P.U. A.L.U.Port,H/D,Etc.

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

Operating Cycle

Initialization

PLCSCANCYCLE

Set Output Self-TestSet Output

CYCLE

Read InputSolve Logic Read InputSolve Logic

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

1

S i

Read Inputs and Outputs and copy into memory.

Do the overhead work required to keep the

process working l

Input Scan

Service Comm etc.

properly.

Program

2

Output Scan

4

Scan

3

Execute PLC program with Input variable being read from the memory and the Output being updated in

memoryUpdate Outputs based memory.Update Outputs based on the values in

memory.

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

Response time

31 2

IN RUN OUT IN RUN OUT IN RUN OUT

Pulse Stretch Interrupt Function

Scan 1 Scan 3Scan 2

Scan

IN RUN OUT

ScanIN RUN OUT IN

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

InterruptPulse Stretch

PLC addressesThe following letters are used for the modules (For Siemens’s PLCs):

I= Input O= Output F= Flag T= Timer

C= Counter RI= Analogue Input RO=Analogue OutputC Counter RI Analogue Input RO Analogue Output

How to realize the address in a general fashion?

ZXX.YYType of Module bit address or desired I/O

number on moduleassigned address of module in PLC rack

number on module

I0 O1 O201

Powersupply

6

5

4

32

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

7

6

I0.6

Ladder Diagram Elements

NO Switch: Normally Open Switch

NC Switch: Normally Closed Switch

NO Output

NC Output

Function Block FUN (name)

Parameter 1Parameter 2 (opt)

.

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

.Parameter N (opt)

Rung

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

Example

Output 1

SinkRung

+-

Output_1

Output 2Output_2

Conditions In Results Out

Source

Conditions In Results Out

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

Digital Logic and Ladder Diagram

X ZYAND

X Z

X Y Z0 0 00 1 0

Y

Z1 0 01 1 1

Truth Table

ORZ=XY

X Z X Z

X Y Z0 0 00 1 1

Y

X

Y

Z 0 1 11 0 11 1 1

Truth Table

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

Y

Z=X+Y

X Y

NOT

X Y

X Y

X Y

1 0

0 1

Truth Table

Y = X

Truth Table

XOR

X ZYX Y Z0 0 00 1 1

X

YZ

X Y1 0 11 1 0

Truth Table

Y

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

Z = X Y

Example 1: Program the following Boolean expression by ladder diagram

)( YXZ )( YXZ

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

General Programming Rules(Utilized in OMRON PLCs)(Utilized in OMRON PLCs)

Switches can be reused in a ladder diagram:

SW_C Output_ESW_D

END (01)SW_C SW_D

Any number of switches can be used to generate the rung condition:

SW_A Output_ASW_B

SW_A2

SW_N

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

END (01)SW_AN

Common Errors

Output_1 SW_1

END (01)

SW_1 Output_1

TIM

Output_NoGood

000

#0020Problem: Causing Logical END (01)

SW_N Output_1

END (01)

g gError !!!

( )

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

Important Functions (OMRON)

SET d RESET f ti

SET

SetButton

SetButton

SET and RESET functions

Output

ResetButton

Button

ResetButtonRESET

Output

RESET

Output

INC function

INC

DMxxxx

Start CountStartCount

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

DMxxxx

TIM and TIMH Functions

TIMStart Time

TIM

xxx

Set Value

StartTime

PresentV l

TIMxxx

ValueTIMxxx

Output

TIM interval= 0.1 second TIMH interval= 0.01 secondCNT Function

Output

CNT Function

CNT

xxx

Start Count

StartCount

Reset Count Reset

Set Value

PresentValue

Reset Count Count

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

CNTxxx

Output

Output

Count UP

CNTR Function

CNTR

xxx

CountUp

Count Down CountDown

Reset

Set Value

PresentValue

Count Down

ResetCount

CNTxxx OutputOutput

Input SW

DIFU Function

DIFU

OneShotOut

p _Input_SW

O Sh tO t

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

OneShotOut

DIFD Function

DIFD

OneShotOut

Input_SWInput_SW

OneShotOut

MOV Function

MOV

Source

Destination

Input_SWInput_SW

Source 2918

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

ExampleQ: 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 O0

0 0S1 S2 S3 H1

1

2

3

1

2

3

S1

S2H1

0

00

0

01

0

10

000 3 3

S3

00

11

01

1

1

0

0

0

1

0

01

0

+ --

111

011

101

111

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

Circuit diagramTruth table

Designation Abbrev. Address Function

Allocation List

Push button S1

Push button S2

P h b S3

S1

S2

S3

I0.0

I0.1

I0 2

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

Push button S3

Light H1

S3

H1

I0.2

O0.0 Light is lit when O0.0 carries 1

I0.0 O0.0I0.1S2S3

S100 01 11 10

0 S1

S3 S3 S3

I0.2

0

1 11 1S1

S1

21SSS2 S2

31SS

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

)( 3211 SSSH

Example 2: A conveyor is run by a motor that can move in either direction. Theconveyor moves in the forward direction when output F is turned ON, and moves in thebackward direction if output B is ON There are two start buttons (one for each direction)backward direction if output B is 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 beforebeing able to change the direction of motion of the conveyor. There is also an overloadsensor OL that stops the conveyor if the motor overheats. Write a LAD program (Using CXProgrammer 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 ONb) 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 Diagramg 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 inputsand past states of the inputs.

A state diagram consists of inputs, outputs, and states. A state of a logic system is a

State Diagram ElementsA 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 causesa transition from one state to the

next state

StateNumber

next state

Transition

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

Outputs

STATE

State Diagram Elements in a Digital FashionBased on the number of states a binary number is given to each stateBased on the number of states a binary number is given to each state.

Inputs requires for transitionfrom state 0 to state 1

All combinational logics thatdon't cause a transition

000

Outputs (0)

001

Outputs (1)

0 to 23 to 2

011

Outputs (3)

010

Outputs (2) 4 to 0 2 to 6

100

Outputs (4)

1 to 3110

Outputs (6)

4 t 5p ( )

6 to 4

101111

7 to 6

4 to 5

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

Outputs (5)111

Outputs (7)

5 to 7

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

l bi i h d ( f 010 011) h i i lifi d honly one bit is changed (e.g., from state 010 to 011), otherwise we cannot simplified the equation.

How to write a ladder program from a state diagramp g g1. Number each state uniquely and allocate enough bits for a state identifier. 2. For the number of state identifier bits consider SET and RESET functions.3. For each output variable, create a rung ORing the states in which it is active.4. For each state transition, create a rung as follows:

101101 100100

F2F1F0 F2F1F0

SET

F2F2 F1 F0 TIM001 A D

Stop RESET

X+, Z+, TIM001X+, Z+, TIM001 Z-, Gr, TIM002Z-, Gr, TIM002

TIM001, A, D

Stop

Stop

F1

RESET

F0Current TransitionC diti

New

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

State Conditions State

A i t ll d b hb tt it h Wh th it h i d d

Example A conveyer is controlled by a pushbutton switch. When the switch is depressed

the conveyer: Moves forward if it is moving backward, Moves backward if it is moving forward Moves backward if it is moving forward.

Forward MotionBackward Motion

Pushbutton Switch (I)Motor (M)

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

I tI

Inputs:Pushbutton Switch (I)

Output:

M=0

MF: ON

M=1

MB: ON

States:

Output:Motor forward (MF)Motor backward (MB) I

States:State 1 (0)- Conveyer moves forwardState 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 1 State 2: Con e er mo es back ardM = 1, State 2: Conveyer moves backward

2. For the number of state variable bits consider SET and RESET functions, (if you OMRON PLC ) th i i t l l (FLAG) b duse OMRON PLCs); otherwise a virtual relay (FLAG) can be used.

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

M MB

MFM

M I

SETSET

MM

IM

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’ bitsState diagram can be used in deriving simplified expressions for states bits ThisState diagram can be used in deriving simplified expressions for states 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 that’s a case, the expression for each bit can be found by:

)( memoryYXM

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-by-In order to study the state diagram approach, the following example is solved step bystep.

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