Scale raw counts to engineering units

The Core Idea

An analog input card may report a measurement as raw counts. Scaling maps those counts into engineering units, using the readings that correspond to the configured low and high endpoints.

What you will learn

  • Identify the raw count at each end of a configured analog input range.

  • Turn a raw count into pressure in bar with a two-point scale.

  • Reuse the calculation when the card count span or transmitter pressure range changes.

Why it matters

Raw numbers mean little to an operator until they are tied to quantities such as pressure or level. The configured endpoints determine what each reading means.

The problem

A pressure transmitter measures 0–10 bar. One configured input card reports 0–32767 counts across a 0–10 V signal. A second example uses a 4–20 mA signal on a card with a 0–27648 count full scale. For this example, the second card's configured readings are 5530 counts at 4 mA and 27648 counts at 20 mA. Those count endpoints are illustrative; use the configured card's documentation or calibration readings on real hardware.

RAW_COUNT is the live input in counts. COUNT_LOW and COUNT_HIGH are the readings in counts at the signal endpoints. PRESSURE_LOW_BAR and PRESSURE_HIGH_BAR are the matching pressures in bar. PRESSURE_BAR is the calculated pressure in bar. It is unclamped: this lesson scales a valid input and does not diagnose failed or out-of-range signals.

You have already scaled a 4–20 mA value in Scale a 4–20 mA Signal. Now the input is the number supplied by an analog card.

Predict

With the first card, COUNT_LOW = 0 counts and COUNT_HIGH = 32767 counts. What pressure should the human-machine interface (HMI) show near 16384 counts? If you keep RAW_COUNT = 16384 counts but change only the high endpoint to 27648 counts, should the pressure stay the same?

Try it

The numeric HMI starts at 16384 counts on the 0–32767 count range. Change Raw card reading to 0 counts, 16384 counts, and 32767 counts. Watch Scaled pressure in bar. A whole-count midpoint is approximate when the span has an odd number of counts, so the HMI rounds the middle value to 5.00 bar.

Check your prediction

At 16384 counts on the first card, the display is about 5.00 bar. Changing only COUNT_HIGH to 27648 counts makes that same raw reading a larger fraction of the count span, so the pressure rises to about 5.93 bar. The card endpoints must match the signal configuration.

Look closer

Pause and step one scan after an HMI change. Follow OFFSET_COUNTS (counts above the low card point), SPAN_COUNTS (counts between card points), SPAN_BAR (bar between pressure points), and finally PRESSURE_BAR (bar). The first endpoint gives 0 bar and the high endpoint gives 10 bar. At each step, the output is a pressure, while the raw input remains a count.

Change it

Imagine switching to the second, illustrative input configuration. Set Low card point to 5530 counts, High card point to 27648 counts, and Raw card reading to 16589 counts. The low and high pressure fields stay at 0 bar and 10 bar. The HMI should show 5.00 bar. Then try 5530 counts and 27648 counts for 0 bar and 10 bar.

The guided program still divides by the first card's fixed span. Repair that one math block so the program uses the live SPAN_COUNTS tag. Run the checks after the edit.

Check yourself

Build the full scale in the challenge editor. It must report the right pressure at both endpoints and the midpoint for both card configurations. The hidden checks also change the pressure endpoints and the card span. You can retry without a limit; use the hints below if a check fails.

Hint 1: What should vary?Which two differences define the count span and the pressure span?

Hint 2: Check the offsetsSubtract COUNT_LOW from RAW_COUNT. Divide by COUNT_HIGH - COUNT_LOW, then apply the pressure span.

Hint 3: Build the final valueUse subtract, subtract, subtract, multiply, divide, then add. The last add uses PRESSURE_LOW_BAR so a shifted pressure range still works.

Show a worked solution

First subtract COUNT_LOW from RAW_COUNT to get OFFSET_COUNTS. Subtract COUNT_LOW from COUNT_HIGH to get SPAN_COUNTS. Subtract PRESSURE_LOW_BAR from PRESSURE_HIGH_BAR to get SPAN_BAR. Multiply OFFSET_COUNTS by SPAN_BAR, divide by SPAN_COUNTS, then add PRESSURE_LOW_BAR to produce PRESSURE_BAR. Use REAL (floating-point number) tags for the intermediate values and pressure so division keeps fractions.

What happened and why

The raw number has meaning only with its two configured card endpoints. The same 16384 counts can represent different pressures on different count spans. Subtracting the low endpoint first gives the distance into the input range; dividing by the span gives its fraction. That fraction selects the same position between the two pressure endpoints. This is the same idea as 4–20 mA scaling, applied to the values the card actually supplies.

Show the math

PRESSURE_BAR = PRESSURE_LOW_BAR + (RAW_COUNT - COUNT_LOW) × (PRESSURE_HIGH_BAR - PRESSURE_LOW_BAR) ÷ (COUNT_HIGH - COUNT_LOW)

For 16589 counts between 5530 and 27648 counts, the count offset is 11059 counts and the span is 22118 counts. The fraction is 0.5, so the pressure is 0 bar + 0.5 × 10 bar = 5 bar.

Common mistakes

  • Assuming every card starts at 0 counts. The 4 mA point can be nonzero. The symptom is a positive pressure at the true low endpoint; subtract the configured COUNT_LOW.

  • Keeping a fixed count span. One card passes while another reports the wrong midpoint. Calculate COUNT_HIGH - COUNT_LOW from the current endpoints.

  • Dropping the engineering offset. A transmitter measuring 2–12 bar reports 5 bar at its midpoint instead of 7 bar. Add PRESSURE_LOW_BAR after scaling the span.

Platform notes

Analog modules differ in their count ranges and in whether their configured counts represent 0–10 V, 0–20 mA, or 4–20 mA. The 0–32767 and 0–27648 count examples here are illustrative configurations, not universal card specifications. Record the actual low and high counts for the selected signal range before using the scale. Keep COUNT_HIGH different from COUNT_LOW; a zero count span cannot be scaled.

Enable JavaScript to run the embedded simulator and complete the interactive exercises.