Non-volatile storing of a counter value (L_TbCount)

Question:
Is it possible to store the counter output of the function block L_TbCount non-volatile?

Answer:
Yes. For storing the L_TbCount output non-volatile the following steps have to be applied:

1. Create a RETAIN variable of DINT type (in the example below this is the variable dnRetainStartValue). Insert this variable twice in the function block connection - once with an input and once with an output.
2. Connect the counter's output to the input flag of the RETAIN variable (L_TbCount.dnActualCount => dnRetainStartValue).
3. Connect the output flag of the RETAIN variable to the load input of the counter function (dnRetainStartValue => L_TbCount.dnStartValue).
4. Insert a function block L_TbTransition and call it at the beginning of the task cycle (sorting index 1). As the trigger edge select the positive edge. The switching time must be set to 1[ms]. The input of the positive edge trigger has to be put to a static TRUE level (bTRUE_b => L_TbTransition.bIn). Connect the output of the edge detection to the load input of the counter (L_TbTransition.bOut => L_TbCount.bLoadStartValue). The L_TbTransition will then output a TRUE pulse only during the first task cycle.
If you require the load function of the counter in addition you can modify the function block connection as follows (the normal load function will be operated in this example via the variables bLoadStartValue_b and dnLoadValue):

URL for linking this AKB article: https://www.lenze.com/en-de/go/akb/200907306/1/
Contact form