Count Up Down with Bounds
medium
Bidirectional counter with upper and lower bounds, and flag outputs when the limits are hit.
What it teaches
A bidirectional counter that respects a Min and Max. Hit the top — the count pins to Max and the at-max flag turns on. Hit the bottom — pins to Min and the at-min flag turns on. Useful when a tracked balance needs both directions and known boundaries.
Inputs and outputs
| Tag | Type | Default | Description |
|---|---|---|---|
| In_CountUp | BOOL | — | Count up pulse |
| In_CountDown | BOOL | — | Count down pulse |
| Cfg_Min | DINT | 0 | Lower limit for the count |
| Cfg_Max | DINT | 3 | Upper limit for the count |
| Out_Count | DINT | — | Current bounded count |
| Sts_AtMax | BOOL | — | At maximum limit flag |
| Sts_AtMin | BOOL | — | At minimum limit flag |
Required behavior
- Out_Count increments by 1 on the rising edge of In_CountUp.
- Out_Count decrements by 1 on the rising edge of In_CountDown.
- Out_Count is unconditionally bounded between Cfg_Min and Cfg_Max.
- Sts_AtMax is 1 when Out_Count is greater than or equal to Cfg_Max.
- Sts_AtMin is 1 when Out_Count is less than or equal to Cfg_Min.