Skip to main content

SCALE Instruction Tutorial: Sensor-to-Engineering Unit Conversion on IDEC FC6A

By NFM Consulting 5 min read

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_min and x_max (raw counts or signed integer).
  • Define an output range: y_min and y_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

  1. Choose S1: a data register holding the raw analog value (e.g., D0000).
  2. 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.
  3. 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.
  4. Choose D1: output-register base. Stores output value, output value (dead band), and amount of output change — 6 consecutive words starting at D1.
  5. Choose D2: an output relay (bit) used as the instruction's output/enable status.

Step 2 — Configure and Initialize SCALE Settings

  1. 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.
  2. 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+0 and D1+1 each 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 to D8006 and stop output updates.

Worked Example: Scale 0–4095 ADC to 0.0–100.0%

ParameterValue
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_max0 / 4095
y_min / y_max0.0 / 100.0
Dead bandApplication-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

  1. In WindLDR, drive S1 through a controlled sequence: min, mid, max, beyond-max, below-min.
  2. 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 D8006 and outputs stop updating.
  3. Capture a monitor view showing S1, the S2 block, D1 outputs, and D8006 for 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 + D8006 evidence.

Frequently Asked Questions

Ready to Get Started?

Our engineers are ready to help with your automation project.