impulse-generator
Description
The impulse-generator block generates a sequence of timed impulses consisting of alternating working and sleeping phases. It can be started by a command sent from the command block, by an edge, by a logical level, or automatically after project initialization if its input is not connected to anything.
While running, the block provides separate outputs that indicate the working phase, the sleeping phase, and whether the generator is currently active. If the impulses parameter is 0, the generator keeps running until it receives the reset command from the command block. For a finite number of impulses, the generator also goes through the sleeping phase after every impulse and returns to the idle state only after the final sleeping phase ends.
Configuration parameters
| Parameter name | Value |
|---|---|
input_edge |
Required parameter that defines the trigger condition for working modes that react to input events. Supported values: rising, falling, both, true, false, null, none. In practice, rising, falling, and both are used most often. |
impulses |
Required parameter that defines the number of impulses to generate. Allowed values are from 0 to 18446744073709551615. The value 0 means continuous operation without automatic stop. |
working_time |
Required parameter that defines the duration of the working phase of a single impulse in milliseconds. Allowed range: from 100 ms to 1209600000 ms (14 days). |
sleeping_time |
Required parameter that defines the duration of the pause between consecutive impulses in milliseconds. Allowed range: from 100 ms to 1209600000 ms (14 days). |
working_mode |
Optional parameter that defines the input control mode. Supported values: dlatch, oneshot, edgereset, leveldriven. |
Input handling
The block supports two commands from the command block regardless of the configured working_mode:
- The
setcommand from thecommandblock starts the generator. If the generator is already running, the sequence restarts from the working phase and the impulse counter is initialized from the beginning. - The
resetcommand from thecommandblock stops the generator and switches it to the idle state.
If no other block is connected to the block input, the generator starts automatically after project initialization is complete.
In the dlatch, oneshot, and edgereset modes, the input reaction depends on the input_edge parameter:
rising: react to afalse -> truechangefalling: react to atrue -> falsechangeboth: react to every logical value changetrue: react to every message whose new value is logical truefalse: react to every message whose new value is logical falsenull: react to every message whose new value isnullnone: no reaction to regular input events
Input values other than those supported by the selected trigger condition are ignored. In particular, for rising, falling, both, true, and false, the block requires values that can be interpreted logically, while for null it reacts only to the null value.
Other input signals are handled according to the working_mode parameter:
| Working mode | Description |
|---|---|
Edge started and stopped (dlatch) |
Every event matching the input_edge condition toggles the generator between start and stop. When the generator is stopped, such an event starts it. When the generator is already running, the same event stops it. |
Edge triggered (oneshot) |
An event matching the input_edge condition starts the generator only when it is idle. Input events received while the generator is running are ignored. |
Extended by the edge (edgereset) |
An event matching the input_edge condition starts the generator if it is stopped. If the generator is already running, the next event does not restart the current phase and does not reset the current timer, but it restores the remaining impulse counter to the value from the configuration, so the generator runs longer. |
State driven (leveldriven) |
Logical true starts the generator if it is not already active. Logical false stops the generator. In this mode, the input_edge parameter does not affect the start and stop decision, and non-logical values are ignored. |
The block does not require the use of inputs labeled using the tag block.
Block outputs
| Output number and name | Output description |
|---|---|
| 1. Working phase. | Returns true only when the generator is in the working phase of an impulse. In all other states it returns false. |
| 2. Sleeping phase. | Returns true only when the generator is in the sleeping phase between impulses. In all other states it returns false. |
| 3. Generator active. | Returns true when the generator is active, meaning it is either in the working phase or in the sleeping phase. In the idle state it returns false. |
The relationship between the outputs is as follows:
- in the
idlestate all three outputs are false - in the working phase the outputs are: true, false, true
- in the sleeping phase the outputs are: false, true, true
Block status description
The description visible below the block has one of two values:
idlemeans that the generator is stoppedactivemeans that the generator is currently in the working phase or in the sleeping phase
The active status does not distinguish between the working phase and the sleeping phase. Use the block outputs to tell them apart.
Errors visible to the user
The block can display the following error messages:
| Error code | Error description |
|---|---|
Invalid edge configuration. |
The input_edge parameter is invalid or was not provided. |
Invalid impulses number configuration. |
The impulses parameter has an invalid value. |
Invalid working_time configuration. |
The working_time parameter is outside the allowed range from 100 ms to 14 days. |
Invalid sleeping_time configuration. |
The sleeping_time parameter is outside the allowed range from 100 ms to 14 days. |
Invalid working_mode configuration. |
The working_mode parameter has a value other than dlatch, oneshot, edgereset, or leveldriven. |
Failed to create timer. |
The internal timer used to measure time could not be created while starting the generator. |
Failed to start timer. |
The timer could not be started when the generator started or when switching between the working and sleeping phases. |
Failed to stop timer. |
The timer could not be stopped while turning the generator off. |
Messages starting with Failed to ... indicate an internal problem with the block rather than an invalid value provided by the user. If such a problem occurs repeatedly, it is worth checking the project configuration and the block connections, and then reporting the issue.
Examples
- For
impulses = 1,working_time = 1000, andsleeping_time = 500, after being started the generator will go through a working phase lasting about 1 s, then a sleeping phase lasting about 0.5 s, and then return to theidlestate. - For
impulses = 3, the generator will execute three working phases separated by three sleeping phases and will stop only after the final sleeping phase ends. - For
impulses = 0, the generator will alternate between the working phase and the sleeping phase indefinitely until it receives theresetcommand from thecommandblock or a stop signal consistent with the selected working mode. - In
dlatchmode withinput_edge = rising, the first rising edge will start the generator and the next rising edge will stop it. - In
oneshotmode withinput_edge = rising, a rising edge will start the generator only when it is in theidlestate. Further rising edges received while it is running will be ignored. - In
edgeresetmode withimpulses = 5andinput_edge = rising, the next rising edge received while the generator is already running will not restart the current phase, but it will extend the total run time by restoring the remaining impulse counter. - In
leveldrivenmode, true starts the generator and false stops it. Values other than logical values are ignored in this mode. - If nothing is connected to the block input, the generator starts automatically after project initialization is complete.