SCALE Instruction Tutorial: Sensor-to-Engineering Unit Conversion on IDEC FC6A
Key Takeaway
A deep tutorial on WindLDR's SCALE (Convert Analog Input) instruction for the IDEC FC6A, covering operand allocation, control-register layout, initialization behavior, dead-band filtering, boundary clamping, error handling, and a complete worked example scaling a 0–4095 ADC count to engineering units.
Overview
The SCALE (Convert Analog Input) instruction in WindLDR performs two-point linear scaling on raw analog readings to produce engineering-unit values. This tutorial covers every operand (S1/S2/S3/D1/D2), the control-register layout, initialization behavior, dead-band filtering, boundary clamping, error modes, and a complete worked example.
Prerequisites
- The analog value you want to scale must exist in a known register (typically a data register populated by an analog module or cartridge).
- You must reserve contiguous register blocks for the SCALE control registers (S2 uses 8 words) and output registers (D1 uses 6 words).
- A safe test harness: either WindLDR simulation/monitoring or an isolated test input source with bounded outputs.
What SCALE Does (and Does Not Do)
SCALE "scales the analog input value according to the coordinates between two specified points and outputs that result." When the instruction input is ON, it applies settings stored in a control-register block (S2) and writes the result to the output registers at D1.
In practical terms:
- Define an input range:
x_minandx_max(raw counts or signed integer). - Define an output range:
y_minandy_max(engineering units). - SCALE clamps out-of-range inputs to the configured min/max so results remain bounded.
Step 1 — Allocate Operands and Register Blocks
- Choose S1: a data register holding the raw analog value
(e.g.,
D0000). - Choose S2: base address of the SCALE control-register block. S2 stores input max/min, output max/min, and dead band — 8 consecutive words starting at S2.
- Choose S3: an initialization input (physical input or internal relay). When ON, the initial values configured in the SCALE settings dialog are stored in the control registers — potentially every scan unless you "one-shot" it. Use SOTU or SOTD to execute initialization only once.
- Choose D1: output-register base. Stores output value, output value (dead band), and amount of output change — 6 consecutive words starting at D1.
- Choose D2: an output relay (bit) used as the instruction's output/enable status.
Step 2 — Configure and Initialize SCALE Settings
- In the SCALE dialog:
- Set Data Type for the input value (S1) as either Word (W) or Integer (I).
- Configure initial values for: input max/min, output max/min, and dead band.
- Ensure initialization behavior is deterministic — use a one-shot relay
(e.g.,
M8120) for the initialization pulse.
Step 3 — Implement the Rung
The following canonical rung structure is derived from the IDEC manual's operation example, which converts a raw analog value from 0–4095 to 0–65535:
// Rung: Execute scaling when Enable_M is ON; initialization via S3.
// Use a one-shot for init if S3 isn't already a pulse.
Enable_M ----[ ]-------------- SCALE(*) --------------( )---- M_ScaleDone
S1 = D0000 // raw input
S2 = D0050 // control regs (8 words)
S3 = M8120 // init pulse
D1 = D0150 // output regs (6 words)
D2 = M0050 // output relay/status
Step 4 — Interpret Results and Handle Dead Band
- The scaled output is written to
D1+0andD1+1each scan the instruction executes. - Dead-band filtering (configured in
S2+6/S2+7) filters minute changes. The instruction maintains distinct "output value" and "output value (dead band)" concepts.
Error Handling and Constraints
- SCALE cannot be used in an interrupt program — doing so triggers a user program execution error.
- If S1 or S2 is out of range, a user program execution error occurs, an error code is stored in special data register D8006, and output values are not updated.
- Invalid parameter conditions (e.g.,
x_min ≥ x_max, negative dead band) also write an error code toD8006and stop output updates.
Worked Example: Scale 0–4095 ADC to 0.0–100.0%
| Parameter | Value |
|---|---|
| S1 (raw ADC) | D0100 |
| S2 (control regs) | D0200 (8 words) |
| D1 (output regs) | D0300 (6 words) |
| S3 (init pulse) | One-shot internal relay |
| D2 (output relay) | M0100 |
| x_min / x_max | 0 / 4095 |
| y_min / y_max | 0.0 / 100.0 |
| Dead band | Application-dependent |
The linear mapping formula behind SCALE is:
y = y_min + (x_eff - x_min) * (y_max - y_min) / (x_max - x_min)
Where x_eff is the clamped input value.
Structured Text Equivalent (for documentation and review)
(* ST: linear scaling with clamp.
This documents the math behind the SCALE instruction. *)
IF x > x_max THEN
x_eff := x_max;
ELSIF x < x_min THEN
x_eff := x_min;
ELSE
x_eff := x;
END_IF;
y := y_min + (REAL(x_eff - x_min) * (y_max - y_min)) / REAL(x_max - x_min);
SCALE Operand and Storage Reference
| Operand | Meaning | Storage Behavior | Documentation Note |
|---|---|---|---|
| S1 | Input value | Data register containing the raw value. Out-of-range values clamped to configured min/max. | Point S1 at the "raw" register from your analog module allocation. |
| S2 | Control registers | Input max/min, output max/min, dead band — 8 contiguous words from S2. | Reserve a contiguous block outside module-mapped ranges. |
| S3 | Initialization input | When ON, initial values are written into control registers. Use SOTU/SOTD for one-shot behavior. | Document your initialization strategy (startup pulse vs. manual re-init). |
| D1 | Output registers | Output value, output value (dead band), amount of change — 6 contiguous words from D1. | Label each word so maintainers know what changes. |
| D2 | Output relay | Status bit set by the instruction. | Use a dedicated internal relay for "ScaleDone/ScaleOK." |
Testing and Validation Procedure
- In WindLDR, drive S1 through a controlled sequence: min, mid, max, beyond-max, below-min.
- Verify:
- Output (
D1+0,D1+1) changes linearly in-range. - Out-of-range inputs clamp as specified.
- Invalid parameter conditions produce a user program execution error
in
D8006and outputs stop updating.
- Output (
- Capture a monitor view showing S1, the S2 block, D1 outputs, and
D8006for the error case.
Quick Checklist
- Allocate contiguous blocks: S2 = 8 words, D1 = 6 words.
- Use a one-shot init input (or a documented "re-init" action).
- Document clamp behavior in your project notes.
- Document constraints: not allowed in interrupt programs; invalid
conditions write error codes to
D8006. - Validate with a test matrix: min/mid/max and beyond-range points;
capture outputs +
D8006evidence.
Frequently Asked Questions
The SCALE instruction performs two-point linear scaling on a raw analog input value, converting it to engineering units. It uses configurable input and output min/max values, clamps out-of-range inputs, and supports dead-band filtering to suppress minor fluctuations.
SCALE uses 8 contiguous words for the control-register block (S2) storing input/output min/max and dead band, plus 6 contiguous words for the output-register block (D1) storing the scaled output, dead-band-filtered output, and amount of change. These blocks must not overlap with other allocations.
No. The IDEC manual explicitly states that SCALE cannot be used in an interrupt program. Attempting to do so triggers a user program execution error.
SCALE clamps out-of-range inputs to the configured boundaries. If the input exceeds the maximum, the maximum value is used for scaling. If it falls below the minimum, the minimum is used. Invalid parameter conditions (such as x_min >= x_max) trigger an error code in special data register D8006 and output values are not updated.
The dead band parameter, configured in control registers S2+6 and S2+7, filters minute changes in the scaled output. The instruction maintains both an unfiltered 'output value' and a 'dead-band output value' in the D1 register block, allowing you to choose the appropriate level of sensitivity for your application.