Navigation:  Programming > Variables >

Volatile and Retentive Instances

Previous pageReturn to chapter overviewNext page

Function Blocks (FBs)

 

The FBs have internal variables that store their data during the consecutive execution cycles. According to the application requirement, these FBs may have their instances configured as retentive (LOCAL_RETAIN or GLOBAL_RETAIN) or volatile (LOCAL_RETAIN or GLOBAL_RETAIN). The input and output variable associated to the FB can also be configured as retentive or volatile. The retentive variables retain their values after the device is shut down, whereas the volatile variables load their initial values after a reset.

 

When we want the FB to keep the values after the reset of the device, it is necessary that the FB instances and the variables associated to its inputs be configured as retentive. That will make the FB internal variables and the associated input variables keep the values previous to shutdown.

In the example below, we have the use of the TON block with retentive instances and variables:

 

Figure 1: TP block with retentive instance and variables before reset.

Figure 1: TP block with retentive instance and variables before reset.

 

Figure 2: TP block with retentive instance and variables one second after the setup.

Figure 2: TP block with retentive instance and variables one second after the setup.

 

When we want the FB to reset its values after the shutdown of the device, it is necessary that the FB instance and the variables associated to its inputs be configured as volatile. That will make the FB internal variables and the associated input variables reset the values previous to shutdown.

Below is an example of use of the CTU block with retentive instance and variables:

 

Figure 3: CTU block with volatile instance and variables before reset.

Figure 3: CTU block with volatile instance and variables before reset.

 

Figure 4: CTU block with volatile instance and variables after reset.

Figure 4: CTU block with volatile instance and variables after reset.

 

 

User’s Block (USERFB)

 

In the use of the USERFB, it is possible to define variables of LOCAL, LOCAL_RETAIN, VAR_IN, VAR_OUT and VAR_IN_OUT type. The internal variables defined as LOCAL will always be volatile, and the LOCAL_RETAIN ones will always be retentive. The internal variable defined as VAR_IN, VAR_OUT and VAR_IN_OUT will be volatile in case the instance of the USERFB is associated to the LOCAL or GLOBAL group and retentive in case it is associated to the LOCAL_RETAIN or GLOBAL_RETAIN group.