← All exercises

Clamp with Overflow

medium

Constrains a numeric input between Min and Max bounds and raises flags when limits are hit.

What it teaches

A clamp that also reports when its limits engage. Pin the value to Max (and raise a 'too high' flag) or to Min (and raise a 'too low' flag); inside the range, the value passes through with both flags off. Useful when downstream logic needs to know the rail was hit.

Inputs and outputs

TagTypeDefaultDescription
In_ValueREALInput value to clamp
Cfg_MinREAL10Lower bound limit
Cfg_MaxREAL90Upper bound limit
Out_ClampedREALConstrained output value
Sts_TooHighBOOLToo high flag
Sts_TooLowBOOLToo low flag

Required behavior