Lemonergy · Studio block

Bounded counter

Counts at sample instants with explicit initial value, increment, limits and wrap or saturate behavior.

Implementation ID
native-counter
Reviewed
2026-10-27

Behavior

count[0] = initial; candidate = count[k−1] + increment. Saturate: count[k] = clamp(candidate, minimum, maximum). Wrap: count[k] = minimum + (candidate − minimum) modulo (maximum − minimum + 1).

Interface

Bounded counter interfaceInputs or arguments on the left, observed outputs on the right. Conserving terminals appear below the component. The tables give units and behavior.Bounded counterStudio blockout0
Original Lemonergy interface view. Lines identify ports; they are not a completed simulation circuit.
Ports and observed outputs
NameDirectionUnitMeaning
out0output1Signal; real scalar.

Parameters

Defaults are initial model values. Select values for your own model and operating conditions.

Configuration fields
ParameterUnitDefaultMeaning and limits
Sample period
sampleTimeS
s0.25Positive interval between sample instants. Values are held between samples.
Minimum 0
Initial count
params[0]
10Configured value for Initial count.
Increment
params[1]
11Configured value for Increment.
Minimum
params[2]
10Configured value for Minimum.
Maximum
params[3]
13Configured value for Maximum.
Boundary (0 saturate, 1 wrap)
params[4]
11Configured value for Boundary (0 saturate, 1 wrap).

Equations and rules

  • count[0] = initial; candidate = count[k−1] + increment
  • Saturate: count[k] = clamp(candidate, minimum, maximum)
  • Wrap: count[k] = minimum + (candidate − minimum) modulo (maximum − minimum + 1)

Worked example

Bounded counter — worked example

Use the configured source parameters. Signal at 0 s = 0; Signal at 0.75 s = 3; Signal at 1 s = 0.

Open Studio example after release →
Numerical checks for the bundled synthetic example
OutputTime (s)Expected valueUnitAbsolute tolerance
Signal
out0
0011e-08
Signal
out0
0.75311e-09
Signal
out0
1011e-09

Explore the recorded outputs

Bounded counter recorded example

Bounded counter
Bounded counter against timeRecorded synthetic simulation values. Time in seconds; output in —.-0.2400.630.251.50.52.370.753.241—Time (s)
Bounded counter: 0 — at 0 s

5 actual recorded samples. Lines are visual guides between samples. Synthetic example, not measured cell data.

Download the recorded samples (JSON) · Open this Studio example after release

Use in a workflow

Bounded counter — worked example

Counts at sample instants with explicit initial value, increment, limits and wrap or saturate behavior.

  1. Bounded counter: count[0] = initial; candidate = count[k−1] + increment. Saturate: count[k] = clamp(candidate, minimum, maximum). Wrap: count[k] = minimum + (candidate − minimum) modulo (maximum − minimum + 1).
    • Use the block reference for settings and connections.
    • Implementation tested locally; public release pending.
Open Studio example after release

Connected concepts

Limits and interpretation

  • Integer-valued scalar output stored as a real number; each limit and increment is bounded in magnitude by 4294967295.

Reference basis

This software operation is defined by its public contract and worked example; no external research result is claimed.

Implementation sources

This reference follows the public interface and locally verified numerical checks for an upcoming release.

Contract: Lemonergy Studio public contract · Verification record: verification-2026-10-27

  • docs/glossary/native-block-verification.json

This implementation and its workflow uses (JSON) · Knowledge graph (JSON-LD)