# LGF_LimRateOfChangeAdvancedCI (FB / V3.0.1)

Author: Siemens Digital Industries

## Short description

The function `LGF_LimRateOfChangeAdvanced` limits the rate of change of an input variable. Jump functions become ramp functions. In addition, the block has various operating modes.

### Block Interface

| LGF_LimRateOfChangeAdvancedCI (FB) |
--- | --- | ---
LReal |  |  | autoValue |  | outputValue |  |  | LReal
LReal |  |  | manualValue |  | posUpRateLim |  |  | Bool
LReal |  |  | setPosUpRateLim |  | posDownRateLim |  |  | Bool
LReal |  |  | setPosDownRateLim |  | negUpRateLim |  |  | Bool
LReal |  |  | setNegUpRateLim |  | negDownRateLim |  |  | Bool
LReal |  |  | setNegDownRateLim |  | highLim |  |  | Bool
LReal |  |  | setHighLim |  | lowLim |  |  | Bool
LReal |  |  | setLowLim |  | error |  |  | Bool
LReal |  |  | defaultOutValue |  | status |  |  | Word
Bool |  |  | enDefaultOutValue |  | subfunctionStatus |  |  | Word
Bool |  |  | track |  |  |  |  |
Bool |  |  | manOp |  |  |  |  |
Bool |  |  | reset |  |  |  |  |
OB_CYCLIC |  |  | callOB |  |  |  |  |

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
autoValue | LReal | 0.0 | Signal to be processed and limited in its rate of change
manualValue | LReal | 0.0 | Manually controlled output value (`outputValue` = `manualValue`)
setPosUpRateLim | LReal | 0.0 | Rate of change per second for the rising ramp in the positive value range (1/second)
setPosDownRateLim | LReal | 0.0 | Rate of change per second for the falling ramp in the positive value range (1/second)
setNegUpRateLim | LReal | 0.0 | Rate of change per second for the rising ramp in the negative value range (1/second)
setNegDownRateLim | LReal | 0.0 | Rate of change per second for the falling ramp in the negative value range (1/second)
setHighLim | LReal | 0.0 | High limit value
setLowLim | LReal | 0.0 | Low limit value
defaultOutValue | LReal | 0.0 | Value for pre-assignment of the output variable (`outputValue` = `defaultOutValue`)
enDefaultOutValue | Bool | FALSE | Assign default output value (`outputValue` = `defaultOutValue`)
track | Bool | FALSE | Follow / tracking of Input variable (`outputValue` = `autoValue`)
manOp | Bool | FALSE | Manual mode on (`outputValue` = `manualValue`)
reset | Bool | FALSE | Complete restart of function
callOB | OB_CYCLIC | --- | Calling wake-alarm interrupt OB (cyclic interrupt OB)

### Output parameter

Identifier | Data type | Description
--- | --- | ---
outputValue | LReal | Output variable
posUpRateLim | Bool | Rise limitation in positive range tripped
posDownRateLim | Bool | Down rate limit in positive range reached
negUpRateLim | Bool | Up rate limit in negative range reached
negDownRateLim | Bool | Down rate limit in negative range reached
highLim | Bool | High limit reached
lowLim | Bool | Low limit reached
error | Bool | FALSE: No error TRUE: An error occurred during the execution of the FB
status | Word | 16#0000-16#7FFF: Status of the FB 16#8000-16#FFFF: Error identification (see following Table)
subfunctionStatus | Word | Status or return value of called FB's, FC's and system blocks

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_FINISHED_NO_ERROR Status: Execution finished without errors
16#8200 | ERR_NEG_RATE_LIM Error: High limit lower than low limit. The high limit `setHighLim` must be greater than the low limit `setLowLim`.
16#8202 | ERR_NEG_RATE_OF_CHANGE Error: Negative rate of change. The parameter for the change rate must not be negative.
16#8600 | ERR_QRY_CINT Error in `QRY_CINT` command - check `subFunctionStatus` code
16#8601 | ERR_OB_UNAVAILABLE Error: OB on input `callOB` is not configured / present. Interconnect the constant name of a configured cyclic interrupt OB at the input `callOB`.

## Functional description

NOTE
  The status of called commands is output in `subFunctionStatus`. In this case, the output value in `status` indicates which command caused the error. In this case, refer to the TIA Portal Online Help section for information on the respective commands.

For the positive/negative value range, two rates of change in each case for the ramp (rising and falling values) can be parameterized. The following operating modes can be selected via control inputs:

- Restart
- Pre-assigning an output
- Normal operation (automatic)
- Switch through controlled variable (manual)
- Tracking

The output variable can be limited through two parametrize able limits. An active limitation of the rate of change of a ramp, as well as an active limitation of the output variable are reported via outputs.

The time interval of the calling cyclic interrupt OB is determined by interconnecting the calling cyclic interrupt OB at the input parameter `callOB`.

###### Restart

At restart `reset = TRUE`, the output `outputValue` is reset to `0.0`.
If `enDefaultOutValue = TRUE` is set, `defaultOutValue` is output. All signal outputs are set to `FALSE`.

###### Pre-assigning an output

If `enDefaultOutValue = TRUE` is set, the value at `defaultOutValue` is output. When changing from `TRUE` to `FALSE`, `outputValue` is ramped from `defaultOutValue` to `autoValue`. When changing from `FALSE` to `TRUE`, the output `outputValue` immediately jumps to `defaultOutValue`.

###### Normal operation

The ramps are straight lines of limitation and are based on a rate of change per second; if, for example, the parameter `setPosUpRateLim = 10.0` is assigned, then at a sampling time of 1s/100ms/10ms, 10.0/1.0/0.1 will be added to `outputValue` at each block call, if `autoValue > outputValue`, until `autoValue` is reached.

The limitation of the rate of change can be parameterized in both positive and negative ranges for the increase and decrease.

Table: Marking of the ramps

Parameters | Ramp
setPosUpRateLim | `outputValue > 0.0` and `|outputValue|` rising
setPosDownRateLim | `outputValue > 0.0` and `|outputValue|` falling
setNegUpRateLim | `outputValue < 0.0` and `|outputValue|` rising
setNegDownRateLim | `outputValue < 0.0` and `|outputValue|` falling

If the ramps are not parameterized (`setPosUpRateLim`, `setPosDownRateLim`, `setNegUpRateLim`, and `setNegDownRateLim` equal `0.0`), the output remains at `0.0` and normal operation is disabled.

###### Tracking

If the input `track = TRUE` is set, the input variable `autoValue` is interconnected directly to the output variable `outputValue`. Thus, jumps of the input variable will also be output.

###### Switch through controlled variable

If `manOp = TRUE` is set, the controlled variable `manualValue` is interconnected directly to the output variable `outputValue`.

In this operating mode, the parameterization of the ramps or the high/low limitation of the output variable, and the pre-assignment of the output, are ineffective.

When changing from `TRUE` to `FALSE`, the output `outputValue` is ramped again after `autoValue`.

As soon as the value range between the low and high limits is reached, the high and low limits are reactivated.

Figure: Ramp function sequence, operating modes

## Change log

Version & Date | Change description
--- | ---
| 01.00.00 | Siemens Industry Online Support
| 21.06.2016 | First released version
| 01.00.01 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA Portal V14 Update 1
| 01.00.02 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 01.00.03 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 01.00.07 | Simatic Systems Support
| 15.11.2019 | Regions, comments and constants are added
| 03.00.00 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 03.00.01 | Simatic Systems Support
| 22.03.2021 | Insert documentation