IMDHMIControls LibraryShop main store

How-to

Scaling engineering units to raw counts on an AC500 analog output

PLC programming Published 5 min read By IMDHMI controls team

Short answer

Yes: scale the 0 to 130 degree demand to 0 to 27648 counts in the program and stop there. The AC500 analog output module turns counts into volts in its D/A hardware, so you never write volts or convert them in code. The raw span is printed in the module data sheet, not the CPU manual: 27648 on the 15-bit modules and 4096 on the 12-bit ones.

On this page
  1. Who converts what in the output chain
  2. Read the raw span off the module data sheet
  3. The scaling equation
  4. Code it in structured text
  5. Worked example and the proof
  6. Faults that look like scaling errors
  7. The decision for your channel
  8. Questions asked

Your chain is right, and you can stop after the second arrow. Scale the 0 to 130 degree demand to 0 to 27648 counts in the program and write the counts; the module's D/A converter produces the 0 to 10 V from them with no further code from you. What the AC500 does not do is the first step: a value written to an analog output channel is read as raw counts, whatever engineering range the tools display. The one number to confirm before you trust the code is the raw span, and it is printed in the data sheet of the analog output module, not in the CPU manual.

Who converts what in the output chain #

An analog output channel works in three stages:

  • Engineering units: the demand your program calculates, here a temperature of 0 to 130 degrees.
  • Raw counts: the integer your program writes to the channel, and the only thing the converter understands.
  • The physical signal: volts or milliamps, generated by the module's D/A converter in hardware.

The program owns the first arrow and the module owns the second. That last stage is the conversion described in how PLC analog input and output modules convert signals, so you never write volts and never convert counts to volts in code. The hardware configuration in Automation Builder selects each channel's signal type, but it does not rescale what the program delivers: the word arriving at the channel is taken as raw counts. Write 65 because the demand is 65 degrees and the converter sees 65 counts, not 65 degrees.

Read the raw span off the module data sheet #

The raw span belongs to the output module, which is why the CPU manual stays silent on it and the module data sheet for your exact catalog number prints it. The AC500 output modules fall into two families:

Module Converter Raw span Signal
DC532 15 bit + sign 0 to 27648 0-10 V
DC531 12 bit 0 to 4096 0-10 V
AC532 15 bit + sign 0 to 27648 4-20 mA
AC522 12 bit 0 to 4096 0-20 mA

With a 15-bit voltage channel, the DC532 being the usual choice for this output, the span in that table row is the constant your code needs, and your planned scaling is correct. On a 12-bit module the same code with the same constant is wrong: a full demand would write only 4096 counts and the output would sit far below full scale. So take the span from the data sheet for the catalog number in your cabinet and use that single constant everywhere in the program.

The scaling equation #

Scaling between two spans is one multiply and one divide:

raw = (demand - demand_low) × (raw_high - raw_low) / (demand_high - demand_low) + raw_low

With your numbers the slope is the count span divided by the demand span, about 212.677 counts per degree. Three details decide whether the code survives a real machine:

  • Clamp before scaling. A demand pushed past the top by a drifting sensor, say 140 degrees, would otherwise hand the converter counts beyond its span; a LIMIT at the demand range removes that whole class of fault.
  • Convert last, in REAL. The intermediate product of demand times span exceeds a 16-bit integer, and integer division truncates early, so do the arithmetic in REAL and round once at the end.
  • Accept the rounding. REAL_TO_INT is the IEC 61131-3 conversion and rounds to the nearest whole count; one count on the 10 V span is 10 / 27648 = 0.36 mV, invisible next to the module's own accuracy.

Run in reverse, the same equation turns an input channel's counts back into engineering units, which the walkthrough of PLC signal scaling from raw counts to engineering units covers.

Code it in structured text #

  1. Declare the variables. The names below are illustrative; the types and initial values are what matter.
VAR
    DemandDegC : REAL := 65.0;   (* demand in degrees, valid 0.0 to 130.0 *)
    DemandLim  : REAL := 0.0;    (* demand after clamping *)
    CountsOut  : INT  := 0;      (* value written to the channel *)
END_VAR
  1. Clamp, scale and round, in that order:
DemandLim := LIMIT(0.0, DemandDegC, 130.0);
CountsOut := REAL_TO_INT(DemandLim * 27648.0 / 130.0);
  1. Write CountsOut to the channel word the hardware configuration assigned to that terminal, by whatever path your program uses to reach the process image.
  2. Download with the machine safe: the channel takes whatever the new code writes on its first scan, so inhibit the actuator or hold the demand at zero until you have watched one scan go by.

Worked example and the proof #

With DemandDegC at 65.0, half the demand span, the clamp passes it unchanged and the code evaluates 65.0 × 27648.0 / 130.0 = 13824.0, which REAL_TO_INT rounds to 13824 counts. Half the count span is half the volts, so the terminal should sit at 5.0 V. The test that proves the whole chain, with the program online and a meter on the channel:

  1. Demand 0: counts 0, meter 0.0 V.
  2. Demand 65: counts 13824, meter 5.0 V.
  3. Demand 130: counts at full scale, meter 10.0 V.

Watch the count in the online view while the meter is on the terminal; the two must move together. A constant factor between them means the code carries the wrong span for the module in the cabinet.

Faults that look like scaling errors #

  • Meter reads about 0.05 V at any demand: the program wrote the demand unscaled, and 130 counts is only 0.047 V.
  • Output stops near 1.48 V at full demand: the code scaled to a 12-bit span of 4096 counts on a 15-bit module.
  • Output pins at full voltage from a low demand upward: the reverse mix-up, the larger span written into a 12-bit module; every count from 4096 up is full scale, and a demand of about 19 degrees already reaches it.
  • Counts jump negative when a sensor fails low: there is no clamp ahead of the conversion; add the LIMIT line.
  • The demand arrives normalized 0.0 to 1.0 from a PID loop: multiply by the span first, so 0.73 gives 20183 counts, the same chain worked through in scaling a PID real output to analog output counts.

The decision for your channel #

  • 15-bit voltage module, DC532 class: your planned scaling is correct; the program ends at counts and the module produces the volts.
  • 12-bit module, DC531 or AC522: same code, span 0 to 4096.
  • Current channel: same counts, and the mapping to milliamps is the module's job.
  • Normalized PID source: multiply by the span before the clamp and the conversion.

Whichever case you are in, prove it with the three-point meter check before the loop drives anything expensive.

Questions asked

Where does the 27648 top count come from?

A 15-bit converter offers 32768 counts. The AC500 analog modules declare 27648 of them as nominal full scale and hold the other 5120 in reserve above it as overrange, so a slightly overscaled write does not immediately saturate. It is the same convention Siemens S7 analog modules use, which is why scaling code carries the same constant on both platforms and ports between them unchanged.

Does a 4-20 mA channel need different scaling code?

No. The counts and the code stay the same; the module maps zero counts to 4 mA and the full-scale count to 20 mA, so the live zero is built into the hardware. Only the signal type in the hardware configuration changes. One consequence worth knowing: a channel commanded to zero counts still drives 4 mA, so a loop-powered valve on it is not electrically off.

Why does the meter not match the calculated volts exactly?

REAL_TO_INT rounds to the nearest whole count, so the written count differs from the exact product by at most half a count, about 0.18 mV on a 10 V span. That is far below the module's own conversion accuracy, so the equation is not where accuracy is lost. Chase a visible error at the demand source, the wiring, or the module specification instead.

Where should the scaling code live?

Put the clamp and the conversion in one small function block with the demand range and the raw span as inputs, then call it once per channel. A constant retyped at each channel is the most common way two outputs on the same module end up on different spans. Keeping the clamp inside the block means no caller can skip it.

Keep reading

  • How-to

    Scale a PID real output to analog output counts

    Scale the PID's REAL output into the channel's documented count range with one linear equation, clamp to the endpoints, then convert with REAL_TO_DWORD. The 4294967295 value is only the DWORD type's maximum (2^32 - 1); a 16-bit channel tops out at 65535 counts, so the module datasheet is the only full scale to use.

    PLC programming

  • How-to

    How to assign V-memory values and scale analog in ladder

    A V-memory register holds the raw module count, not volts: on a 12-bit 0–10 V channel, 2048 counts is just over 5 V. Load your own constants with LD k2048 and OUT V2000 on an SP0 first-scan rung, scale with E = Elow + (R − Rlow) × (Ehigh − Elow) ÷ (Rhigh − Rlow), and keep constants, arithmetic, and comparisons in one data format.

    PLC programming

  • How-to

    Scaling a 4-20 mA analog input to engineering units in CPM2 ladder

    Scale with y = x × 120 / 9999 - 20: the raw analog word reads 0 at 4 mA and 9999 at the top of the loop, so DM1010 stores -20 °C and 100 °C at the ends of the loop. Multiply before dividing into a 32-bit-wide product that holds 1,199,880, drive the rung with the Always-On bit, and read the destination as signed. If DM1010 only needs 0-9999, MOVE the raw word and skip the math.

    PLC programming