lm_counter_updowncounter

Up/Down Counter

The Up/Down Counter increases or decreases its internal counter according to rising edges received on the Increment and Decrement input connectors.
A rising edge on Increment increases the counter by one, while a rising edge on Decrement decreases it by one.

If the Reboot survive property is enabled, the current counter value is stored on the server and is preserved after a reboot. After the restart, subsequent increments or decrements continue from the last saved value.
If Reboot survive is disabled, the counter value is reset when the server reboots.

The Start Date output connector provides the date and time of the most recent reset operation.

When the Reset input receives 1, the counter is reset, Output goes to 0 and Start Date is updated. Counting can resume only after Reset returns to 0.

 Behaviour of Up/Down Counter

Behaviour of Up/Down Counter

Connector Type Description
Increment Input Increases the counter by one when a rising edge is received.
Decrement Input Decreases the counter by one when a rising edge is received.
Reset Input Resets the counter when set to 1.
Output Output Current counter value.
Start Date Output Date and time of the most recent reset operation.
Property Description
Reboot survive Defines whether the counter value is preserved after a server reboot. When enabled, the value is stored on the server and restored after restart.

The Up/Down Counter reacts to rising edges on the Increment and Decrement inputs.

A rising edge is the transition:

0 → 1

When a rising edge is detected on Increment:

Output = Output + 1

When a rising edge is detected on Decrement:

Output = Output - 1

The value is not continuously modified while an input remains at 1.
A new change occurs only when a new rising edge is received.

To generate another increment or decrement, the corresponding input must return to 0 and then change to 1 again.

Consider an initial counter value of:

Output = 0

The following sequence is applied:

Event Resulting Output
Rising edge on Increment 1
Rising edge on Increment 2
Rising edge on Increment 3
Rising edge on Decrement 2
Rising edge on Increment 3
Rising edge on Decrement 2

The counter therefore follows the sequence of increment and decrement commands received by the node.

The Increment input increases the current counter value by one whenever a rising edge is received.

For example:

Increment Output
0 5
1 6
1 6
0 6
1 7

Keeping Increment at 1 does not continuously increase the counter.

A new increment occurs only after the signal returns to 0 and another rising edge is generated.

The Decrement input decreases the current counter value by one whenever a rising edge is received.

For example:

Decrement Output
0 5
1 4
1 4
0 4
1 3

As with the Increment input, the signal must return to 0 before another rising edge can be detected.

The Reset input clears the current counter value.

When:

Reset = 1

the node performs the following operations:

  • the counter is reset;
  • Output is set to 0;
  • Start Date is updated with the current date and time;
  • increment and decrement operations remain disabled while Reset stays equal to 1.

Normal counting resumes only after:

Reset = 0

The Reset signal must return to 0 after the reset operation.
While Reset remains equal to 1, the counter does not resume normal operation.

The Start Date output indicates when the current counting period started.

Each time the Reset input is activated, Start Date is updated with the date and time of that reset.

For example:

Event Start Date
Initial reset 01/09/2026 09:00
Increment / Decrement operations 01/09/2026 09:00
New reset Updated to the new reset date and time

The value therefore identifies the beginning of the current counting cycle.

The Reboot survive property defines whether the current counter value is preserved when the Thinknx server restarts.

When Reboot survive is enabled:

  • the current counter value is stored on the server;
  • the value is preserved during a reboot;
  • after restart, the counter continues from the last saved value.

When Reboot survive is disabled:

  • the current counter value is not preserved;
  • the counter is reset when the server restarts.

Enable Reboot survive when the counter represents information that must be preserved across server restarts.

The Up/Down Counter is useful whenever events must be counted in both directions.

Typical applications include:

  • counting people entering and leaving an area;
  • tracking the number of active devices;
  • increasing or decreasing a logical quantity through push buttons;
  • tracking stock or item quantities;
  • counting generic events that can both increase and decrease a value;
  • maintaining an occupancy counter.

An entrance sensor is connected to Increment, while an exit sensor is connected to Decrement.

Each detected entry generates a rising edge on Increment:

Output = Output + 1

Each detected exit generates a rising edge on Decrement:

Output = Output - 1

The Output therefore represents the current number of people inside the monitored area.

If the counter must be cleared at the beginning of a new period, the Reset input can be activated.

The Up/Down Counter can be tested using the Logic Module simulation tools.

A typical test procedure is the following:

  • start with Increment = 0, Decrement = 0 and Reset = 0;
  • generate a rising edge on Increment and verify that Output increases by one;
  • keep Increment = 1 and verify that the value does not continue increasing;
  • return Increment to 0 and generate another rising edge;
  • generate a rising edge on Decrement and verify that Output decreases by one;
  • activate Reset and verify that Output returns to 0;
  • verify that Start Date is updated after the reset;
  • return Reset to 0 and verify that counting can resume.
  • Increment and Decrement react to rising edges, not to the duration of the input signal.
  • Make sure each command returns to 0 before generating another rising edge.
  • Use Reset when a new counting cycle must begin.
  • Make sure that Reset returns to 0 after the reset operation.
  • Enable Reboot survive when the counter value must be preserved after a server reboot.
  • Start Date can be used to identify when the current counting period started.
  • lm_counter_updowncounter.txt
  • Last modified: 2026/09/21 14:33
  • by francesco