Skip to content

impulse-counter

Description

The impulse-counter block works as a simple integer counter controlled by impulses and by commands sent from the command block. It stores the current value defined by the “Start value” parameter or restored after a project restart, and then increments it, decrements it, or sets it directly based on input signals.

The block operates only within the configured range from “Value from” to “Value to”. Changes performed by the up and down commands from the command block or by a rising edge are limited to this range, so the counter never goes below the configured minimum or above the configured maximum.

The block has one input and three outputs. It does not require the use of inputs labeled using the tag block.

Configuration parameters

Parameter name Value
Name (name) Name displayed on the block in the editor. If left empty, impulse-counter is displayed.
Start value (start_value) Required parameter that defines the initial counter value. It must be an integer within the range from “Value from” to “Value to”. The set command from the command block always restores exactly this value.
Value from (value_from) Required parameter that defines the minimum allowed counter value.
Value to (value_to) Required parameter that defines the maximum allowed counter value. It must be greater than “Value from”.
Movement (movement) Required parameter that defines the step used by the up and down commands from the command block and by the false -> true rising edge. The value must be a positive integer greater than zero.
Restore state after power loss (persistent_state) Optional boolean parameter with the value true or false. When it is set to true, after restart the block attempts to restore the last persisted counter value. The value is not persisted immediately, but about 10 minutes after the last change. If a restart or power loss happens earlier, an older value may be restored. When it is set to false or the parameter is omitted, counting starts again from “Start value” after restart.

Input handling

The block requires at least one input connection. If its input is not connected to anything during initialization, the block switches to the Input disconnected. error state.

The following control methods are supported:

  • The set command from the command block sets the current value to “Start value”.
  • The reset command from the command block sets the current value to the minimum, that is “Value from”.
  • The up command from the command block increases the current value by “Movement”.
  • The down command from the command block decreases the current value by “Movement”.
  • The false -> true rising edge works the same way as the up command from the command block.
  • A numeric input value within the range from “Value from” to “Value to” sets the counter directly to that value.

Detailed operating rules:

  • for the up command from the command block and for the rising edge, the result is limited to “Value to”
  • for the down command from the command block, the result is limited to “Value from”
  • if a number outside the allowed range appears at the input, that message is ignored
  • logical values other than the false -> true edge are ignored
  • date and time values are ignored
  • text is accepted only if it can be parsed as an integer
  • values of type double, temperature, and percent are converted to an integer by truncating the fractional part when used for direct setting

The block does not require the use of inputs labeled using the tag block.

Block outputs

Output number and name Output description
1. Current value. Returns the current counter value as an integer.
2. Minimum reached. Returns true when the counter is at the minimum value “Value from”. In all other cases it returns false.
3. Maximum reached. Returns true when the counter is at the maximum value “Value to”. In all other cases it returns false.

Block status description

The description visible below the block shows the current counter value as text.

Examples:

  • 0
  • 12
  • -5

Errors visible to the user

The block can display the following error messages:

Error code Error description
Invalid start_value. The “Start value” parameter was not provided, is not an integer, or is outside the range from “Value from” to “Value to”.
Invalid value_from. The “Value from” parameter was not provided or is not a valid integer.
Invalid value_to. The “Value to” parameter was not provided or is not a valid integer.
Invalid from/to range. The range is invalid because “Value from” is greater than or equal to “Value to”.
Invalid movement. The “Movement” parameter was not provided, is not a valid integer, or has a value less than or equal to zero.
Input disconnected. No other block has been connected to the block input.

Examples

  • If “Start value” is set to 10, “Value from” is set to 0, “Value to” is set to 100, and “Movement” is set to 5, then the set command sent from the command block will set the counter to 10.
  • For the same configuration, the reset command sent from the command block will set the counter to 0.
  • If the current value is 10, then the up command sent from the command block or a false -> true edge will change it to 15.
  • If the current value is 98 and “Movement” is set to 5, then the up command sent from the command block will set the counter to 100, not to 103.
  • If the current value is 3 and “Movement” is set to 10, then the down command sent from the command block will set the counter to 0, not to -7.
  • If the value 42 is provided at the input, the counter will be set to 42 as long as it is within the configured range.
  • If the value 150 is provided at the input while the range is 0 ... 100, that message will be ignored.
  • If the value 18.9 is provided at the input, the counter will be set to 18.