# TrigGen

## `TrigGen` (FB)

FUNCTION\_BLOCK TrigGen

### Short description

> Pulse generation with adjustable time interval.

### Representation

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-c052abd659a5ccb668ac2b651868bf338fdc1abb%2FTrigGen_FB.png?alt=media" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name        | Data type | Value range | Initial value | Function                     |
| ----------- | --------- | ----------- | ------------- | ---------------------------- |
| *xEn*       | BOOL      |             |               | Enable input                 |
| *wInterval* | WORD      |             |               | Time value for time interval |
| *eTimeBase* | eTimeMS   |             |               | Time base for time interval  |
| *xEnImp*    | BOOL      |             |               | Option enable 1st pulse      |

#### Outputs

| Name       | Data type | Value range | Initial value | Function                            |
| ---------- | --------- | ----------- | ------------- | ----------------------------------- |
| *xTrig*    | BOOL      |             |               | Pulse output                        |
| *tNextImp* | TIME      |             |               | Remaining time until the next pulse |

### Function description

#### General

At the pulse output *xTrig* pulses with a duration of one program cycle and a time interval of (*wInterval* multiplied by *eTimeBase*) are generated cyclically if the enable input *xEn* is active.

> **Limitation of the maximum time interval**
>
> The time interval is limited to a maximum of 48 days to avoid an internal value overflow.
>
> **Example for calculating the time interval**
>
> *wIntervall* = 1000, *eTimeBase* = Millisecond, pulses are generated at a time interval of 1000 ms.

#### Enable 1st pulse *xEnImp*

When the option is active (*xEnImp* = TRUE) the 1st pulse is generated immediately after the enable. *xEn* is generated.\
If the option is not active (*xEnImp* = FALSE) the 1st pulse is generated after the enable *xEn* after the expiry of a time interval.

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-fbaab3bcd573cbd00bfe4f4a6b642469dbc5c427%2FTrigGen_Bild_1.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Remaining time until the next pulse *tNextImp*

At this output the remaining time until the next pulse is shown if the enable input (\*xEn = TRUE) is active.\
In all other situations the constant 0.0 is shown.

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-c2fb61201db44dee9dbcf30fa0623414ba7efa27%2FTrigGen_Bild_2.png?alt=media" alt=""><figcaption></figcaption></figure>

### Codesys

InOut:

| Scope  | Name        | Type    |
| ------ | ----------- | ------- |
| Input  | `xEn`       | `BOOL`  |
| Input  | `wInterval` | `WORD`  |
| Input  | `eTimeBase` | eTimeMS |
| Input  | `xEnImp`    | `BOOL`  |
| Output | `xTrig`     | `BOOL`  |
| Output | `tNextImp`  | `TIME`  |
