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
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 Required parameter that defines the minimum allowed counter value.
value_to Required parameter that defines the maximum allowed counter value. It must be greater than value_from.
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.
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 from the value_from ... value_to range 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 = 10, value_from = 0, value_to = 100, and movement = 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 = 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 = 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.