Introduction

During the edge recognition, a bit is monitored during a transition from 0 -> 1 (positive edge) or from 1 -> 0 (negative edge).

For this, the value of the bit in the previous cycle is compared to the value of the bit in the current cycle. In this case, not only the current value, but also the old value, are needed.

Instead of a bit, 2 bits are therefore needed for edge recognition (current value and old value).

Because the data type BOOL only offers one single bit (current value), there is another data type for edge recognition, EBOOL (expanded BOOL). In addition to edge recognition, the data type EBOOL provides an option for forcing. It must also be saved whether forcing the bit is enabled or not.

The data type EBOOL saves the following data:

  • the current value of the bit in Value bit

  • the old value of the bit in History bit

    (the content of the value bit is copied to the History bit at the beginning of each cycle)

  • Information whether forcing of the bit is enabled in Force-Bit

    (0 = Forcing disabled, 1 = Forcing enabled)

Restrictions for EBOOL

Using an EBOOL variable for contacts to recognize positive (P) or negative (N) edges or with an EF called RE or FE, you have to adhere to the restrictions described below.

EBOOL with %M not written inside program

An EBOOL variable with a %M address, which is not written inside your program but directly, for example by an animation table, an operator screen or an HMI, will not work in the expected way. The edge is TRUE infinitely because the %M is only written one time.

NOTE: To avoid this issue the %M has to be written at the end of the task to update the old value information.

The old value is only updated, when the %M bit is written, so if you write the bit only one time, the edge detection will be infinite.

Old Value

Current Value

Edge Detect

Description

0

0

0

state 0 (before writing the bit)

0

1

1

Write 1 in the bit (e.g. by animation table).

0

1

1

If you do not write again, the edge remains infinitely.

1

1

0

Write 1 again in the bit, the old value is updated and the edge detection is set to 0.

EBOOL with %M written inside program

For an EBOOL variable with a %M address, which is written inside your program, you have to adhere to the restrictions described below:

  • Do not use the bit with a SET or RESET coil. In this case the old value is not updated. So you can perform an infinite edge.

  • Do not write the bit conditionally. A simple logic as IF NOT %M1 THEN %M1 := TRUE; END_IF leads to an infinite edge, because it is written only one time.

EBOOL with %I

For an EBOOL variable with a %I address you have to adhere to the restriction described below:

  • When using multitasking the test of %I edge must be performed in the task where it is updated. The use of the edge detection of a %I scheduled in a task of higher priority must be avoided.

    Example: If you have a fast task, which updates a %I, do not use a edge detection in the mast task. Depending on the scheduling you can detect the edge or not.

Recognizing Positive Edges

A contact to recognize positive edges is used to recognize positive edges. With this contact, the right connection for a program cycle is 1 when the transition of the associated actual parameter (A) is from 0 to 1 and, at the same time, the status of the left connection is 1. Otherwise, the status of the right link is 0.

In the example, a positive edge of the variable A is supposed to be recognize and B should therefore be set for a cycle.

Anytime the value bit of A equals 1 and the history bit equals 0, B is set to 1 for a cycle (cycle 1, 4, and 9).

Recognizing Negative Edges

A contact to recognize negative edges is used to recognize negative edges. With this contact, the right connection for a program cycle is 1 when the transition of the associated actual parameter (A) is from 1 to 0 and, at the same time, the status of the left connection is 1. Otherwise, the status of the right link is 0.

In the example, a negative edge of the variable A is supposed to be recognize and B should therefore be set for a cycle.

Anytime the value bit of A equals 0 and the history bit equals 1, B is set to 1 for a cycle (cycle 2 and 8).

Forcing Bits

When forcing bits, the value of the variable determined by the logic will be overwritten by the force value.

In the example, a negative edge of the variable A is supposed to be recognized and B should therefore be set for a cycle.

Anytime the value bit or force bit of A equals 0 and the history bit equals 1, B is set to 1 for a cycle (cycle 1 and 8).

Using BOOL and EBOOL Variables

Edge recognition behavior using BOOL or EBOOL variables types can be different:

  • When using a BOOL variable, the system manages the history by allowing edge detection during the contact execution.

  • When using an EBOOL variable, the history bit is updated during the coil execution.

The following examples show the different behavior depending on the variable type.

Variable A is define as BOOL, whenever A is set to 1, %MW1 is incremented by 1.

Variable B is defined as EBOOL, the behavior is different when compared with variable A. While B is set to 1, %MW2 is incremented by 1 because the history bit is not updated.

Variable C is defined as EBOOL, the behavior is identical than variable A. The history bit is updated.

Forcing of Coils Can Cause the Loss of Edge Recognition

Forcing of coils can cause the loss of edge recognition.

In the example, when A equals 1, B should equal 1, and with a rising edge from A, the coil B will be set for a cycle.

In this example, the variable B is first assigned to the coil, and then to the link to recognize positive edges.

At the beginning of the second cycle, the value bit of B equals 0. When forcing B within this cycle, the force bit and value bit are set to 1. While processing the first line of the logic in the third cycle, the history bit of the coil (B) will also be set to 1.

Problem:

During edge recognition (comparison of the value bit and the history bit) in the second line of the logic, no edge is recognized, because due to the updating, the value bit and history bit on line 1 of B are always identical.

Solution:

In this example, the variable B is first assigned to the link to recognize positive edges and then the coil.

At the beginning of the second cycle, the value bit of B equals 0. When forcing B within this cycle, the force bit and value bit are set to 1. While processing the first line of the logic in the third cycle, the history bit of the link (B) will remain set to 0.

Edge recognition recognizes the difference between value bits and history bit and sets the coil (C) to 1 for one cycle.

Using Set Coil or Reset Coil Can Cause the Loss of Edge Recognition

Using set coil or reset coil can cause the loss of edge recognition with EBOOL variables.

The variable above the set/reset coil (variable C in the example) is always affected by the value of the left link.

If the left link is 1, the value bit (variable C in the example) is copied to the history bit and the value bit is set to 1.

If the left link is 0, the value bit (variable C in the example) is copied to the history bit, but the value bit is not changed.

This means that whatever value the left link has before the set or reset coil, the history bit is always updated.

In the example, a positive edge of the variable C should be recognized and set D for a cycle.

Code line

Behavior in LD

Corresponds to in ST

1

Original situation: C = 0, History bit = 0

A = 1,

B = 1,

C = 1, History bit = 0

IF A AND B

THEN C := 1;

ELSE C := C;

END_IF;

2

A = 1,

B = 1,

C = 1, History = 1

IF NOT(A) AND NOT(B)

THEN C := 0;

ELSE C := C;

END_IF;

3

C = 1, History = 1

D = 0, as the value bit and history bit of C are identical.

The rising edge of C, shown in code line 1, is not recognized by the code in line 2, as this forces the history bit to be updated.

(If the condition is FALSE, the present value of C is again assigned to C, see ELSE statement in code line 2 in ST example.)

-