Example of calculating an equation - STEP 7

Creating FBD programs

ft:publication_title
Creating FBD programs
Product
STEP 7
Version
V20
Publication date
11/2024
Language
en-US
Example of calculating an equation

Calculating a complex equation

The following program example shows you how to solve equations of the following type with the FBD programming language:

X= ((A + B) x C) / D

You can always solve this equation with mathematical operations. To do so, you can use the instructions "ADD", "MUL" and "DIV". If you are using a CPU of the S7-1200 or S7-1500 series, you can also use the instruction "CALCULATE". Depending on the data type you choose, different mathematical operations are available for this instruction which can be combined with one another.

Implementation with the instructions "ADD", "MUL" and "DIV"

You want to calculate the following equation:

RESULT = ((A + B) x 15) / E

The following table shows the definition of the tags used:

Name

Data type

Comment

A

INT

First value for addition

B

INT

Second value for addition

C

INT

First intermediate result

15

INT

Multiplier

D

INT

Second intermediate result

E

INT

Divisor

RESULT

INT

End result

The following network shows the FBD programming for calculating the equation:

The value of operand "A" is added to the value of operand "B". The sum is stored in operand "C". The value of operand "C" is multiplied by "15". The multiplication result is stored in operand "D". The value stored in operand "D" is then divided by the value of operand "E". The end result is saved in the "RESULT" operand.

Implementation with the instruction "CALCULATE" (S7-1200/1500 only)

You want to calculate the following equation:

RESULT = ((5 + 10) x 4) / 6

The following table shows the definition of the tags used:

Name

Declaration

Data type

Comment

Value

A

Input

INT

First value for addition

5

B

Input

INT

Second value for addition

10

C

Input

INT

Multiplier

4

D

Input

INT

Divisor

6

RESULT

Output

INT

End result

10

To program the equation with the instruction "CALCULATE", follow these steps:

  1. Drag the instruction "CALCULATE" from the "Instructions" task card to an FBD network.

  2. You can select the data type INT for the instruction from the "<???>" drop-down list.

  3. Interconnect the tags declared in the block interface with the inputs and outputs of the instruction box.

  4. Click the "Calculator" icon on the top right corner of the instruction box to enter the equation to be calculated.

    The dialog "Edit 'Calculate' instruction" opens.

  5. Enter the following expression in the "OUT:=" field:

    ((IN1 + IN2) * IN4) / IN3

    The equation is displayed in the instruction box.

    The following network shows the result in the FBD programming language:

    If the "Tag_Input" has signal state "1", the instruction is executed. The value of operand "A" is added to the value of operand "B". The subtotal is multiplied by "C" and then divided by the value of the "D" operand. The end result is saved in the "RESULT" operand.