Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

Ladder

Programming

infoPLC.net

Automation Systems
Basic
Ladder Rules

Automation Systems
Ladder Rules: Fundamentals…

•Rungs are executed TOP to DOWN


•Elements in same level are executed LEFT to RIGHT

Automation Systems
Ladder Rules: NO, we can’t…

•Contact can not be set in the most right side of a Rung

•Empty Rung is not allowed

Automation Systems
Ladder Rules: NO, we can’t…
•Only a COIL can be sereialized after a COIL

Automation Systems
Ladder Rules: YES we can…

•Coils FBs and FUNs can be set without need of a contact

•Coils and Contacts can be inserted wherever as far as the logic


makes sense and no contact is set in the most right position

Up to 50 parallel branches are


allowed per rung

Automation Systems
Contacts , Coils and
Sequence Instructions

Automation Systems
Contacts, Coils and Sequence Instructions

Contacts and Coils

Can be negated, differenciated, Set, Reset, etc…


SET Coil

Coil
Diff UP Contact

Contact RESET Coil


Inverted Contact

Automation Systems
Contacts, Coils and Sequence Instructions
R_TRIG, F_TRIG and Differenciation
•IEC611313 defines R_TRIG and F_TRIG functions for the
Rising/Falling Edge detection
•NJ Series supports OMRON’s traditional Diff up/down and R_TRIG
(Up) and F_TRIG (Down)

Instance is needed !

Automation Systems
Contacts, Coils and Sequence Instructions

Contacts and Coils


•TestABit and (TestABitN) Negated TestABit returns TRUE when the
Bit in position (Pos) of the BitString (In) is TRUE (FALSE)
3
ProductCode

Automation Systems
Contacts, Coils and Sequence Instructions

SR and RS : Set
•Functions are used to SET and RESET the Keep Bit
•SR: Gives Priority to the Set Input when Set and Reset both are TRUE
•RS: Gives Priority to the Reset Input when Set and Reset both are TRUE

Automation Systems
Contacts, Coils and Sequence Instructions

SetBits/ResetBits
•Declaring “In” as a BitString.
• SetBits: Sets “n” bits to TRUE from bit number “Pos” in the BitString.
• ResetBits: Sets “n” bits to FALSE from bit number “Pos” in the BitString

Automation Systems
Contacts, Coils and Sequence Instructions

SetABit/ResetABit
•Declaring “In” as a BitString.
• SetABit: Sets TRUE bit in position “Pos” in the BitString.
• ResetABit: Sets FALSE bit in position “Pos” in the BitString

Automation Systems
Contacts, Coils and Sequence Instructions

OutABit
•Declaring “In” as a BitString.
• OutABit sets TRUE or FALSE the bit in position POS depending on the
value of BitVal

(TRUE)

Automation Systems
Timers

Automation Systems
Timers

•NJ Series supports five different kinds of


timer instructions:

•TON (Timer On Delay)


•TOF (Timer Off Delay)
•TP
•AcumulativeTimer (Retentive Timer)
•Timer ( hundred ms timer)

Automation Systems
Timers

•Instance Of the Timer FB’s consist of:

Instance_name

FB_Type

BOOL BOOL

TIME TIME

In Timer Input BOOL


PreTime Preset Time TIME
Reset Timer Reset (Atime only) BOOL
Q Timer Output BOOL
ElapTIme Elapsed Time TIME

Refere TIME Datatype for formating details


Automation Systems
Timers

TON (Time On Delay)


•Timer Output (Q) is TRUE when ElapTime achieves PreTime
•Timer Output (Q) turns to FALSE whenever (In) Becomes FALSE

T#10ms

In
Q
PreTime
Elap
Automation Systems
Timers

TOF: Time Off Delay

•Timer Output (Q) is TRUE when (In) is TRUE and after (In) turns to
FALSE and ElapTime does not reach PreTime

T#10ms

In
Q
PreTime
Elap
Automation Systems
Timers

TP (Pulse Timer)
•Timer Output (Q) is TRUE with (In) Rising Edge
•Timer Output (Q) goes FALSE when ElapTime reaches PreTime

T#10ms

In
Q
PreTime
Elap
Automation Systems
Timers: Timer (Hundred ms Timer)

•Timer Output (Q) is TRUE when ElapTime achieves PreTime


•Timer Output (Q) turns to FALSE whenever (In) Becomes
FALSE
•ElapTime increments in steps of 100 ms !
•Only reason for using this Timer instead of TON is to reduce
program execution time

Automation Systems
Timers

Acumulation Timer (Retentive Timer)


•Acumulation Timer starts counting when In becomes TRUE and freezes
counting when In bcomes FALSE (ET Time is keept)
•Q Output is TRUE when PT time value is achieved
•Q Output and ET are reset when Reset input is enabled

In
PT
ET
Q
Even when Input is FALSE
Reset
Acumulated time is retained
Automation Systems
Counters

Automation Systems
Counters

CTU, CTD: Counter Up, Counter Down


•CTU is a Counter Up instruction
•CTD is a Counder Down instruction
•When (CU) or (CD) transition from FALSE to TRUE Counter
Increments (CTU) or Decrements (CTD) it’s Counter value
(CtVal)
•(Reset) will Reset (CurVal) to zero and (Q) to FALSE
•(LD) will Load (PreVal) to (CtVal) and set (Q) to FALSE
•(Q) is TRUE when:
•CTU: Counter Value (CtVal) = to Preset Value (PreVal)
•CTD:Counter Value (CtVal) = 0
Instance_name Instance_name

BOOL BOOL BOOL BOOL


BOOL INT BOOL INT
INT INT
Automation Systems
Counters

CTU: Counter Up

CU

Reset

CtVal

Automation Systems
Counters

CTD: Counter Down

CD

LD

CtVal

Automation Systems
Counters

CTUD: Counter Up/Down

This is an UP/DOWN counter that includes two new outputs:


(QU) and (QD) to differenciate maximum/minimum CtValue
achievement

CU
CD
CtVal

QU

QD
Reset
LD
Automation Systems
Counters

Counter Variations:
•NJ includes variations of CTU, CTD and CTUD
•Different Datatypes can be used
DINT
CTU
LINT
CTD _
UDINT
CTUD
ULINT
Example:

Automation Systems
Math Instructions

Automation Systems
Math Instructions

NJ Series support a wide range of Math Functions:

BASIC ARITMETIC POWER, ARRAY


LOGARITHMIC, MANAGEMENT
ADD (+)
RANDOM, FRACTIONS
AddOU (+OU) AryAdd
SQRT AryAddV
SUB ()
LN and LOG ArySub
SubOU (OU)
EXPT ArySubV
MUL (*)
Rand AryBCD
MulOU (*OU)
FMod AryBin
DIV (/)
Frac AryMean
MOD
FCChek ArySD
ABS
Inc and Dec

TRIGONOMETRIC
RadToDeg and DegToRad
SIN, COS, and TAN
ASIN, ACOS, and ATAN

Automation Systems
Math Instructions

BASIC ARITHMETIC
•Basic Arithmetic functions operate with ANY_ELEMENTARY Data types
•NJ will automatically perform any necessary Datatype conversion.

BASIC ARITMETIC
ADD (+) MulOU (*OU)
AddOU DIV (/)
(+OU)
MOD
SUB ()
ABS
SubOU (OU)
Inc and Dec
MUL (*)

Example (ADD):

Automation Systems
Math Instructions

BASIC ARITHMETIC

•Most of the BASIC Arithmetic functions support ANY_ELEMENTARY Datatype

BASIC ARITMETIC
ADD (+) : Addition
AddOU (+OU): Addition with OVEFLOW BIT
SUB (-): Substraction
SubOU (-OU): Substraction with NEGATIVE OVERFLOW BIT
MUL (*): Multiply
MulOU (*OU): Multiply with OVERFLOW BIT
DIV (/): Division
MOD: Modulo
ABS: Absolute Value
Inc* and Dec*: INTEGER Increment ++, and Decrement --

*Supports ANY_INT Datatype

Automation Systems
Math Instructions

TRIGONOMETRIC

TRIGONOMETRIC Example of SIN:


•RadToDeg: Radians to Degrees
•DegToRad: Degrees to Radians
•SIN Sinus
•COS Cosinus
•TAN Tangent
In Out
•ASIN Inverse Sinus
• ACOS Inverse Cosinus
•ATAN Inverse Tangent

Automation Systems
Math Instructions

POWER, LOGS, RANDOM, FRAC,…


POWER, LOGARITHMIC, RANDOM,
FRACTIONS
SQRT: RootSQUARE Example of EXPT
LN and LOG: Natural and Decimal Log
EXPT Exponential Power
Rand Random function
FMod Division Float reminder
Frac Fractional Part of Float
FCChek* Is a Number Check

*Returns a BOOL
Automation Systems
Math Instructions

ST or Ladder?

What’s the best Language for Programming: Ladder or ST?

It depends on the user and the application…

Some times… It would be perfect to


Combine Ladder and ST commands inside
the same program
This is possible with NJ’s Inline ST

InlineST is specially nice to implement


math algorithms that normally would take
several rungs in Ladder

No need to create FB in ST to be
instanced in Ladder, you can type
directy ST by using InlineST Function.

Automation Systems
Math Instructions: Ladder or ST ?

BASIC ARITHMETIC

Example of
Sum using ST
in Ladder

Automation Systems
Bit String Processing

Automation Systems
Bit String Processing

Following Instructions are used for Logic


processing of BOOL, BitStrings or Arrays (Ary)
of BOOL BitStrings:

•AND (&), OR, and XOR


•XORN
•NOT
•AryAnd,AryOr, AryXor, and Ary XorN

Note.- BitStrings DataTypes are: BYTE,


WORD,DWORD and LWORD.
Automation Systems
Bit String Processing

AND, OR, XOR XORN


These Instructions perform processing on Boolean
variables or individual bits in bit strings

Up to 5 Input parameters (In..N) can be operated


Automation Systems
Bit String Processing

AND, OR, XOR XORN


Tables of Truth:

AND OR

Automation Systems
Bit String Processing

AND, OR, XOR XORN


Tables of Truth:

XOR XORN

Automation Systems
Bit String Processing

AND, OR, XOR XORN

EXAMPLE

B1 1 0 1
B2 0 1 1
Result 0 0 1

Automation Systems
Bit String Processing

AND, OR, XOR XORN


When Number of Input parameters is greater than 2
processing is performed in the following way
(Example for 5 Input parameters):

In1
L
L Out
In2
L
In3
L
In4
L
In5

L= Logic Operation
Automation Systems
Bit String Processing

NOT
The NOT instruction reverses the value of a Boolean
variable or the individual bits in a bit string

0 0 1 0 0 0 1 1
1 1 0 1 1 1 0 0
Automation Systems
Bit String Processing

AryAnd, AryOr, AryXor, AryXorN


These Functions use Logical operation with Array of Bit
Strings.

A[0] OR B[0]  C[0]


A[1] OR B[1]  C[1]
A[..] OR B[..]  C[..]

Automation Systems
Bit String Processing

AryAnd, AryOr, AryXor, AryXorN

Example:

12 OR 2  14
17 OR 4  21
A[..] OR B[..]  C[..]

Automation Systems
Comparison Instructions

Automation Systems
Comparison

Following Instructions are used to compare:

•EQ(=), NE(<>), LT(<),LE(<=),GT(>), GE(>=)


•Cmp
•ZoneCmp
•TableCmp
•AryCmp*
•AryCmp*V

Note.-* can be EQ,NE,LT,LE,GT,GE


Automation Systems
Comparison

Simple Operators: EQ,NE,LT,LE,GT,GE

•EQ (=) Equal


•NE(<>) Not Equal
•LT(<) Less Than
•LE(<=) Less or Equal
•GT(>) Greater Than
•GE(>=) Greater or Equal

Automation Systems
Comparison

Simple Operators: EQ,NE,LT,LE,GT,GE


Example:

Automation Systems
Comparison

Cmp

Cmp: Generates All possible comparisons of two values.

Automation Systems
Comparison

ZoneCmp
ZoneCmp: Outputs True when condition :

MN<=In<=MX

Automation Systems
Comparison

TableCmp
•Tablemp performs a Zone Comparison of tabular data
•Tabular Data TABLE is defined in 2 dimension Array
•Output Data is set in 1 dimension Array

Table[0,n] <= In <= Table [1,n]  AryOut[n]


300 <= <= 999  FALSE
17 <= 120 <= 500  TRUE
T[..] T[..]  BOOL
<= <=

Automation Systems
Comparison

AryCmpqqq Comparison operation


•Compares two Arrays, In1[ ] , In2[ ] and sets the Boolean result in AryOut[ ]
•The number of elements to compare is determined by ‘Size’ parameter

In1[0..Size-1] qqq In2[0..Size-1]  AryOut[0..Size-1]


EQ (=)
NE(<>)
LT(<)
LE(<=)
GT(>)
GE(>=)

Automation Systems
Comparison

AryCmpqqq Comparison operation


•Example: AryCmpEQ

A[..] EQ B[..]  Bool


7 EQ 0  False

13 EQ 13  True

Automation Systems
Comparison

AryCmpqqqV Comparison operation


•Compares Arrays In1[ ] , with Value In2 and sets the Boolean result in
AryOut[ ]
•The number of elements to compare is determined by ‘Size’ parameter
In1[0..Size-1] qqq In2  AryOut[0..Size-1]
EQ (=)
NE(<>)
LT(<)
LE(<=)
GT(>)
GE(>=)

Automation Systems
Comparison

AryCmpqqqV Comparison operation


•Example: AryCmpEQV

A[..] EQ  Bool
7 EQ  False
13
13 EQ  True

Automation Systems
Data Transfer

Automation Systems
Data Transfer

•Data Transfer Instructions copy or move blocks of data.


•Data Transfer Includes:

•MOVE •AryExchange
•MoveBit •AryMove
•MoveDigit •Clear
•TransBits •Copy**ToNum
•MemCopy •Copy**To**
•SetBlock •CopyNumTo**
•ExChange

Automation Systems
Data Transfer

MOVE
•MOVE command can copy value from the In parameter to the Out
parameter.
•Element of Array, Structure and Union can also be used

Example: MOVE of an Struct

Automation Systems
Data Transfer

MoveBit
•MOVEBit command can copy the bit (InPos) from BitString In to the bit
(InOutPos) of the BitString InOut
InPos

Example: 5 4 3 2 1 0

In(34) 1 0 0 0 1 0

5 4 3 2 1 0

InOut(8) 0 0 1 0 0 0

InOutPos

Automation Systems
Data Transfer

MoveDigit
•MOVEDigit command copies one or more (Size) Digits, Starting in (InPos)
digit from BitString In to the digit position (InOutPos) of the BitString InOut
InPos
Example:
3 2 1 0

In 1 2 3 4

3 2 1 0

InOut 2 3 0 0

InOutPos

Automation Systems
Data Transfer

TransBits
•TransBits command copies one or more (Size) Bits, Starting in (InPos)
digit from BitString In to the Bit position (InOutPos) of the BitString InOut
InPos
Example: In
7 6 5 4 3 2 1 0

1 1 1 1 1 1 1 1

InOut
7 6 5 4 3 2 1 0

0 0 0 1 1 1 0 0

InOutPos

Automation Systems
Data Transfer

MemCopy
•MemCopy command copies two or more (Size) Array Elements From (In)
to (AryOut).
Example: Size=3
In[ ]
6 5 4 3 2 1 0
700 600 500 400 300 200 100

AryOut[ ]
6 5 4 3 2 1 0
0 0 300 200 100 0 0

Automation Systems
Data Transfer

SetBlock
•SetBlock Fills (Size) elements of (In) Array with (In) Value.

Example:

In
100

AryOut[ ]
6 5 4 3 2 1 0
0 0 100 100 100 0 0

Size=3

Automation Systems
Data Transfer

Exchange
•Values in InOut1 and InOut2 are exchanged

Automation Systems
Data Transfer

AryXChange
•Values in Arrays InOut1 and InOut2 are exchanged

Automation Systems
Data Transfer

AryMove
•MemCopy command copies two or more (Size) Array Elements From (In)
to (AryOut).
•In and AryOut can be different Datatypes
•When Datatype is same, MemCopy works faster.
Size=3
In[ ]
6 5 4 3 2 1 0
700 600 500 400 300 200 100

AryOut[ ]
6 5 4 3 2 1 0
0 0 300 200 100 0 0

Automation Systems
Data Transfer

Clear operation

•Cleans to zero the value contained in InOut.

Automation Systems
Data Transfer

Copy**To**
•The Family of Functions Copy**To** perform a BIT level copy

WORD
7 6 5 4 3 2 1 0

… 0 0 0 0 0 1 1 1
INT 7 6 5 4 3 2 1 0

… 0 0 0 0 0 1 1 1

LREAL … 0 0 0 0 0 1 1 1

Automation Systems

You might also like