FBD Examples

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

B Programming Examples

B.1 Overview of Programming Examples

Practical Applications
Each FBD instruction triggers a specific operation. When you combine these
instructions into a program, you can accomplish a wide variety of automation tasks.
This chapter provides the following examples of practical applications of the FBD
instructions:
• Controlling a conveyor belt using bit logic instructions
• Detecting direction of movement on a conveyor belt using bit logic instructions
• Generating a clock pulse using timer instructions
• Keeping track of storage space using counter and comparison instructions
• Solving a problem using integer math instructions
• Setting the length of time for heating an oven

Instructions Used

Mnemonik Program Elements Description


Catalog
WAND_W Word logic instruction (Word) And Word
WOR_W Word logic instruction (Word) Or Word
S_CD Counters Down Counter
S_CU Counters Up Counter
R Bit logic instruction Reset Output
S Bit logic instruction Set Output
P Bit logic instruction Positive RLO Edge Detection
ADD_I Floating-Point instruction Add Integer
DIV_I Floating-Point instruction Divide Integer
MUL_I Floating-Point instruction Multiply Integer
CMP >=I, CMP <=I Compare Compare Integer
& Bit logic instruction AND
>=1 Bit logic instruction OR
= Bit logic instruction Assign
JMPN Jumps Jump-If-Not
RET Program control Return
MOVE Move Assign a Value
SE Timers Extended Pulse Timer

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


A5E00068870-02 B-1
Programming Examples

B.2 Example: Bit Logic Instructions

Example 1: Controlling a Conveyor Belt


The following figure shows a conveyor belt that can be activated electrically. There
are two push button switches at the beginning of the belt: S1 for START and S2 for
STOP. There are also two push button switches at the end of the belt: S3 for
START and S4 for STOP. It it possible to start or stop the belt from either end.
Also, sensor S5 stops the belt when an item on the belt reaches the end.

Sensor S5

S1 O Start S3 O Start
S2 O Stop S4 O Stop
MOTOR_ON

Absolute and symbolic Programming


You can write a program to control the conveyor belt using absolute values or
symbols that represent the various components of the conveyor system.
You need to make a symbol table to correlate the symbols you choose with
absolute values (see the STEP 7 Online Help).

System Component Absolute Address Symbol Symbol Table


Push Button Start Switch I 1.1 S1 I 1.1 S1
Push Button Stop Switch I 1.2 S2 I 1.2 S2
Push Button Start Switch I 1.3 S3 I 1.3 S3
Push Button Stop Switch I 1.4 S4 I 1.4 S4
Sensor I 1.5 S5 I 1.5 S5
Motor Q 4.0 MOTOR_ON Q 4.0 MOTOR_ON

Function Block Diagram to control the Conveyor Belt


Network 1: Pressing either start switch turns the motor on.

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


B-2 A5E00068870-02
Programming Examples

I 1.1 >=1
Q 4.0

I 1.3 S

Network 2: Pressing either stop switch or the sensor at the end of the belt turns the
motor off.

I 1.2 >=1

I 1.4 Q 4.0
I 1.5 R

Example 2: Detecting the Direction of a Conveyor Belt


The following figure shows a conveyor belt that is equipped with two photoelectric
barriers (PEB1 and PEB2) that are designed to detect the direction in which a
package is moving on the belt. Each photoelectric light barrier functions like a
normally open contact.

Q 4.0 PEB2 PEB1 Q 4.1

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


A5E00068870-02 B-3
Programming Examples

Absolute and symbolic Programming


You can write a program to activate a direction display for the conveyor belt system
using absolute values or symbols that represent the various components of the
conveyor system.
You need to make a symbol table to correlate the symbols you choose with
absolute values (see the STEP 7 Online Help).

System Component Absolute Address Symbol Symbol Table


Photoelectric barrier 1 I 0.0 PEB1 I 0.0 PEB1
Photoelectric barrier 2 I 0.1 PEB2 I 0.1 PEB2
Display for movement to right Q 4.0 RIGHT Q 4.0 RIGHT
Display for movement to left Q 4.1 LEFT Q 4.1 LEFT
Pulse memory bit 1 M 0.0 PMB1 M 0.0 PMB1
Pulse memory bit 2 M 0.1 PMB2 M 0.1 PMB2

Function Block Diagram for Detecing the Direction of a Conveyor Belt


Network 1: If there is a transition in signal state from 0 to 1 (positive edge) at input
I 0.0 and, at the same time, the signal state at input I 0.1 is 0, then the package on
the belt is moving to the left.
M 0.0
I 0.0 P &
Q 4.1
I 0.1 S

Network 2: If there is a transition in signal state from 0 to 1 (positive edge) at input


I 0.1 and, at the same time, the signal state at input I 0.0 is 0, then the package on
the belt is moving to the right.
M 0.1
I 0.1 P &
Q 4.0
I 0.0 S

Network 3: If one of the photoelectric barriers is interrupted, this means that there
is a package between the barriers. The direction pointer shuts off.

&
I 0.0 Q 4.0
I 0.1 R
Q 4.1
R

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


B-4 A5E00068870-02
Programming Examples

B.3 Example: Counter and Comparison Instructions

Storage Area with Counter and Comparator


The following figure shows a system with two conveyor belts and a temporary
storage area in between them. Conveyor belt 1 delivers packages to the storage
area. A photoelectric barrier at the end of conveyor belt 1 near the storage area
determines how many packages are delivered to the storage area. Conveyor belt 2
transports packages from the temporary storage area to a loading dock where
trucks take the packages away for delivery to customers. A photoelectric barrier at
the end of conveyor belt 2 near the storage area determines how many packages
leave the storage area to go to the loading dock. A display panel with five lamps
indicates the fill level of the temporary storage area.

Display Panel

Storage area Storage area Storage area Storage area Storage area
empty not empty 50% full 90% full Filled to capacity

(Q 12.0) (Q 12.1) (Q 15.2) (Q 15.3) (Q 15.4)

Packages in I 12.0 I 12.1 Packages out


Temporary
storage area
for 100
packages

Conveyor belt 1 Conveyor belt 2


Photoelectric barrier 1 Photoelectric barrier 2

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


A5E00068870-02 B-5
Programming Examples

Function Block Diagram that Activates the Indicator Lamps on the Display Panel
Network 1: Counter C1 counts up at each signal change from “0” to “1” at input CU
and counts down at each signal change from “0” to “1” at input CD. With a signal
change from “0” to ”1” at input S, the counter value is set to the value PV. A signal
change from “0” to “1” at input R resets the counter value to “0”. MW200 contains
the current counter value of C1. Q12.1 indicates “storage area not empty”.
C1
S_CUD

I 12.0 CU

I 12.1 CD

I 12.2 S CV MW210

C#10 PVCV_BCD MW200 Q 12.1


=
I 12.3 R Q

Network 2: Q12.0 indicates ”storage area empty”.


Q 12.0
=
Q 12.1 &

Network 3: If 50 is less than or equal to the counter value (in other words if the
current counter value is greater than or equal to 50), the indicator lamp for “storage
area 50% full” is lit.
C MP
<= I
Q 15.2
50 IN 1
=
MW 200 IN 2

Network 4: Network 4: If the counter value is greater than or equal to 90, the
indicator lamp for “storage area 90% full” is lit.

CMP
>= I
Q 15.3
MW200 IN1
=
90 IN2

Network 5: If the counter value is greater than or equal to 100, the indicator lamp
for “storage area full” is lit.
CMP
>= I
Q 1 5 .4
M W 2 00 IN 1
=
100 IN 2

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


B-6 A5E00068870-02
Programming Examples

B.4 Example: Timer Instructions

Clock Pulse Generator


You can use a clock pulse generator or flasher relay when you need to produce a
signal that repeats periodically. A clock pulse generator is common in a signalling
system that controls the flashing of indicator lamps.
When you use the S7-300, you can implement the clock pulse generator function
by using time-driven processing in special organization blocks. The example shown
in the following FBD program, however, illustrates the use of timer functions to
generate a clock pulse. The sample program shows how to implement a free-
wheeling clock pulse generator by using a timer.

Function Block Diagram to Generate a Clock Pulse (pulse duty factor 1:1)
Network 1: If the signal state of timer T1 is 0, load the time value 250 ms into T1
and start T1 as an extended-pulse timer.
T1
SE
M0.2 &
S5T#250MS T
W

Network 2: The state of the timer is saved temporarily in an auxiliary memory


marker.
M0.2

T1 & =

Network 3: If the signal state of timer T1 is 1, jump to jump label M001.


M001

M0.2 & JMP

Network 4: When the timer T1 expires, the memory word 100 is incremented by 1.

ADD_I
??.? EN
MW100 IN1 OUT MW100
1 IN2 ENO

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


A5E00068870-02 B-7
Programming Examples

Network 5: The MOVE instruction allows you to output the different clock
frequencies at outputs Q12.0 through Q13.7.

M001

MOVE
??.? EN OUT QW12
MW100 IN ENO

Signal Check
A signal check of timer T1 produces the following result of logic operation (RLO) for
the negated input parameter of the AND logic operation (M0.2) in the clock pulse
example:

1
0
250 ms

As soon as the time runs out, the timer is restarted. Because of this, the signal
check produces a signal state of 1 only briefly.
The negated (inverted) RLO:

1
0
250 ms

Every 250 ms the RLO bit is 0. The jump is ignored and the contents of memory
word MW100 is incremented by 1.

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


B-8 A5E00068870-02
Programming Examples

Achieving a Specific Frequency


From the individual bits of memory bytes MB101 and MB100 you can achieve the
following frequencies:

Bits of MB101/MB100 Frequency in Hz Duration


M 101.0 2.0 0.5 s (250 ms on / 250 ms off)
M 101.1 1.0 1s (0.5 s on / 0.5 s off)
M 101.2 0.5 2s (1 s on / 1 s off)
M 101.3 0.25 4s (2 s on / 2 s off)
M 101.4 0.125 8s (4 s on / 4 s off)
M 101.5 0.0625 16 s (8 s on / 8 s off)
M 101.6 0.03125 32 s (16 s on / 16 s off)
M 101.7 0.015625 64 s (32 s on / 32 s off)
M 100.0 0.0078125 128 s (64 s on / 64 s off)
M 100.1 0.0039062 256 s (128 s on / 128 s off)
M 100.2 0.0019531 512 s (256 s on / 256 s off)
M 100.3 0.0009765 1024 s (512 s on / 512 s off)
M 100.4 0.0004882 2048 s (1024 s on / 1024 s off)
M 100.5 0.0002441 4096 s (2048 s on / 2048 s off)
M 100.6 0.000122 8192 s (4096 s on / 4096 s off)
M 100.7 0.000061 16384 s (8192 s on / 8192 s off)

Signal states of the Bits of Memory MB 101

Scan Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Time Value
Cycle in ms
0 0 0 0 0 0 0 0 0 250
1 0 0 0 0 0 0 0 1 250
2 0 0 0 0 0 0 1 0 250
3 0 0 0 0 0 0 1 1 250
4 0 0 0 0 0 1 0 0 250
5 0 0 0 0 0 1 0 1 250
6 0 0 0 0 0 1 1 0 250
7 0 0 0 0 0 1 1 1 250
8 0 0 0 0 1 0 0 0 250
9 0 0 0 0 1 0 0 1 250
10 0 0 0 0 1 0 1 0 250
11 0 0 0 0 1 0 1 1 250
12 0 0 0 0 1 1 0 0 250

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


A5E00068870-02 B-9
Programming Examples

Signal state of Bit 1 of MB 101 (M 101.1)


Frequency = 1/T = 1/1 s = 1 Hz

T
1
M 101.1 0
Time
0 250 ms 0.5 s 0.75 s 1 s 1.25 s 1.5 s

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


B-10 A5E00068870-02
Programming Examples

B.5 Example: Integer Math Instructions

Solving a Math Problem


The sample program shows you how to use three integer math instructions to
produce the same result as the following equation:
MW4 = ((IW0 + DBW3) x 15) / MW0

Function Block Diagram


Network 1: Open Data Block DB1.

DB1
OPN

Network 2: Input word IW0 is added to shared data word DBW3 (data block must
be defined and opened) and the sum is loaded into memory word MW100. MW100
is then multiplied by 15 and the answer stored in memory word MW102. MW102 is
divided by MW0 with the result stored in MW4.

ADD_I
??.? EN

IW0 IN1 OUT MW100


MUL_I
DBW3 IN2 ENO EN

MW100 IN1 OUT MW102


DIV_I
15 IN2 ENO EN

MW102 IN1 OUT MW4

MW0 IN2 ENO

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


A5E00068870-02 B-11
Programming Examples

B.6 Example: Word Logic Instructions

Heating an Oven
The operator of the oven starts the oven heating by pushing the start push button.
The operator can set the length of time for heating by using the thumbwheel
switches shown in the figure. The value that the operator sets indicates seconds in
binary coded decimal (BCD) format.

Thumbwheels for setting BCD digits

Oven

4 4 4

Heat 7.... ...0 7... ...0 Bits


Q 4.0
XXXX 0001 1001 0001 IW0

IB0 IB1 Bytes


Start push button I 0.7

System Component Absolute Address


Start Push Button I 0.7
Thumbwheel for ones I 1.0 to I 1.3
Thumbwheel for tes I 1.4 to I 1.7
Thumbwheel for hundreds I 0.0 to I 0.3
Heating starts Q 4.0

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


B-12 A5E00068870-02
Programming Examples

Function Block Diagram


Network 1: If the timer is running, then turn on the heater.
Q 4.0

T1 & =

Network 2: If the timer is running, the Return instruction ends the processing here.

T1 & RET

Network 3: Mask input bits I 0.4 through I 0.7 (that is, reset them to 0). These bits
of the thumbwheel inputs are not used. The 16 bits of the thumbwheel inputs are
combined with W#16#0FFF according to the (Word) And Word instruction. The
result is loaded into memory word MW1. In order to set the time base of seconds,
the preset value is combined with W#16#2000 according to the (Word) Or Word
instruction, setting bit 13 to 1 and resetting bit 12 to 0.

WAND_W
??.? EN

IW0 IN1 OUT MW1


WOR_W
W#16#FFF IN2 ENO EN

MW1 IN1 OUT MW2

W#16#2000 IN2 ENO

Network 4: Start timer T1 as an extended pulse timer if the start push button is
pressed, loading as a preset value memory word MW2 (derived from the logic
above).
T1
I 0.7 & SE

MW2 TV

Function Block Diagram (FBD) for S7-300 and S7-400 Programming


A5E00068870-02 B-13

You might also like