Scale a Sensor Bank
medium
Converts eight raw sensor readings into engineering units on request.
What it teaches
Extend Configurable Scaling to a whole bank of sensors owned by the program using this one. Preserve the raw measurements and write a separate result array. Validate the configuration before changing any results.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Scale | Input | BOOL | 0 | Request a conversion |
| Cfg_RawMin | Input | REAL | 4 | Raw lower endpoint |
| Cfg_RawMax | Input | REAL | 20 | Raw upper endpoint |
| Cfg_EUMin | Input | REAL | 0 | Engineering lower endpoint |
| Cfg_EUMax | Input | REAL | 100 | Engineering upper endpoint |
| Sts_Valid | Output | BOOL | 0 | Validity of the latest requested conversion |
| Ref_Raw | InOut | REAL[8] | — | Read-only raw values |
| Ref_Scaled | InOut | REAL[8] | — | Engineering values written on a valid request |
Required behavior
- A request acts once on a change from 0 to 1. Holding it high does not repeat the action.
- On a rising In_Scale, use Scaled = Cfg_EUMin + (Raw - Cfg_RawMin) * (Cfg_EUMax - Cfg_EUMin) / (Cfg_RawMax - Cfg_RawMin) for all eight elements.
- Values beyond the endpoints extrapolate; descending raw and engineering ranges are allowed.
- Equal raw endpoints reject the request: Sts_Valid = 0 and Ref_Scaled is unchanged. Otherwise Sts_Valid = 1.
- Without a new request, preserve results and status. Never change Ref_Raw; arrays are distinct.