# LGF_Integration (FB / V3.0.2)

Author: Siemens Digital Industries

## Short description

The function approximately calculates the area under a function curve. The function curve is transferred as an analog `value` (LReal) which varies over time. The integral value is output on `integral`.
The implementation is based on the trapezoidal rule and uses [ms] as time base.

### Block Interface

| LGF_Integration (FB) |
--- | --- | ---
Bool |  |  | enable |  | integral |  |  | LReal
LReal |  |  | value |  | error |  |  | Bool
Bool |  |  | reset |  | status |  |  | Word
|  |  |  |  | subfunctionStatus |  |  | Word

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
enable | Bool | FALSE | Enables integral calculation If this input is set to the value `FALSE`, the integral calculation is stopped and the `integral` output shows the last calculated value.
value | LReal | 0.0 | Analog value of the continuous function curve, based on [ms], (e.g. [volume flow/ms])
reset | Bool | FALSE | Sets the output “integral” to “0.0”.

### Output parameter

Identifier | Data type | Description
--- | --- | ---
integral | LReal | Integral value
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_EXECUTION_FINISHED_NO_ERROR Status: No error in the function during execution
16#8600 | ERR_READ_SYS_TIME Error: System time FC `RD_SYS_T` returned an error when excuting - check `subFunctionStatus` code

## 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.

The integral calculation includes the summation of those trapezoidal areas that span between the last two function values on the “value” input and the time. The elapsed time is calculated via the system time of the CPU. This trapezoidal area is identical to the product of the mean value of the two process values and the time interval.

NOTE
  The calculation takes [ms] as time base. So the analoge value hase to use the same time base, e.g. [volume flow/ms].

A = \frac{1}{2} * (F_{t_1}+F_{t_0}) * (t_1-t_0) + \frac{1}{2} * (F_{t_2}+F_{t_1}) * (t_2-t_1) + ...

Figure: Principle of operation

Start the integral calculation for the inputvalue at the parameter `value`:

- Set the parameter `enable` to the value `TRUE`
- Set the parameter `reset` to the value `FALSE`

If the parameter `enable` is set to the value `FALSE`, the integral calculation is stopped and the output `integral` outputs the last calculated value.
If the parameter `reset` is set to the value `TRUE`, the output `integral` is reset to `0.0`

## Change log

Version & Date | Change description
--- | ---
| 01.00.00 | Siemens Industry Online Support
| 17.02.2017 | First released version
| 01.00.01 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 01.00.02 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 01.01.00 | Simatic Systems Support
| 12.11.2019 | Regions, comments and constants are added, code refactored
| 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
| 09.02.2021 | Insert documentation
| 03.00.02 | Simatic Systems Support
| 07.06.2021 | Fix bug - incompatibility with S7-1200 and LTIME