How-to
Scaling a 4-20 mA analog input to engineering units in CPM2 ladder
Short answer
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.
On this page
- What the analog word already contains
- The exact equation, and why 83 counts per degree is wrong
- Drive the math with the Always-On bit, not a one-shot
- The ladder chain, step by step
- Prove the scaling at three loop points
- When DM1010 reads wrong
- Resolution limits, tenths of a degree, and a broken loop
- The decision for DM1010
- Questions asked
Scale the channel with y = x × 120 / 9999 - 20. The CPM2 analog word x reads 0 at 4 mA and 9999 at 20 mA, so the equation lands DM1010 at -20 °C and 100 °C at the ends of the loop and tracks every scan between them. Multiply before you divide, keep the product in a result area at least 32 bits wide, because 9999 × 120 = 1,199,880, and run the rung on the Always-On bit. MOVE cannot do this job alone: it copies a word, it does not convert units. If DM1010 only needs the normalized 0-to-9999 value, MOVE the raw word there and stop.
What the analog word already contains #
The 4-20 mA signal never reaches ladder logic as a current. The analog hardware converts it to a numeric word at a PLC memory location fixed by the hardware configuration, and that word is the only source your MOVE, multiply and divide instructions ever see. Before any math, watch that word online while the current changes: a word that tracks the signal proves wiring, conversion and addressing in one step.
The configured conversion for this channel gives these endpoints:
| Applied signal | Raw word | DM1010 after scaling |
|---|---|---|
| 4 mA (bottom of range) | 0 | -20 °C |
| 12 mA (mid-scale) | 4999 or 5000 | 39 or 40 °C |
| Full scale (top of range) | 9999 | 100 °C |
If your converter reports a different full-scale count, substitute it for 9999 everywhere below. If the word does not move with the current, fix wiring, channel configuration and the input word address first - arithmetic cannot repair a dead channel.
The exact equation, and why 83 counts per degree is wrong #
The engineering span is 100 - (-20) = 120 °C and the raw span is 9999 - 0 = 9999 counts, so the slope is 120/9999 = 0.012 °C per count, or exactly 9999/120 = 83.325 counts per °C. The scaling is the straight line:
y = x × 120 / 9999 - 20
Both endpoints come out exact. At x = 0, y = -20 °C. At x = 9999, y = 9999 × 120 / 9999 - 20 = 120 - 20 = 100 °C.
The common shortcut of dividing the raw word by 83 uses a rounded slope. At full scale it computes 9999/83 - 20 = 100.47 °C before truncation. Keep the ratio 120/9999 in the chain and let the divide land where it lands.
Drive the math with the Always-On bit, not a one-shot #
For a live temperature, the arithmetic executes every scan, so the execution condition is the Always-On bit. Its address comes from the CPM programming manual for your CPU - no address can be derived from the signal range. DIFU is the trap here: DIFU produces a one-scan pulse on an OFF-to-ON transition, so a DIFU contact between the condition and the math freezes DM1010 until the next transition. That pattern is correct only when you want one captured sample per trigger. Confirm the choice by ramping the current: DM1010 must move scan by scan, not once per trigger.
The ladder chain, step by step #
RAW, PRODUCT and QUOT below are illustrative names for words you choose; DM1010 is the destination from the original question. The steps are operation-level - enter them with the arithmetic instructions your Syswin 3.4 ladder provides, in this order:
- Find the input word. Note the word the channel writes, from the hardware configuration or the analog unit's documentation. Watch it online while the current changes.
- MOVE the raw word each scan into RAW: 16-bit unsigned, range 0 to 9999, initial value 0.
- Multiply RAW × 120 into PRODUCT: 32-bit unsigned, range 0 to 1,199,880, initial value 0. A 16-bit result area stops at 65,535, which holds RAW only to 546 (65,520), about -14 °C; every reading above that overflows.
- Divide PRODUCT ÷ 9999 into QUOT: integer, 0 at the bottom of the loop, 120 at full scale. Integer division drops the fraction, so between the endpoints the result can read up to 1 °C low.
- Subtract 20 and store into DM1010, interpreted as a signed word: -20 to 100 °C.
- Keep one number representation end to end. If the analog word is BCD while the arithmetic expects binary, or the reverse, the bottom of the range can look right while the middle is wrong; the mid-scale check in the next section exposes the mismatch.
Prove the scaling at three loop points #
- Bottom of range: RAW = 0, PRODUCT = 0 × 120 = 0, QUOT = 0 ÷ 9999 = 0, DM1010 = 0 - 20 = -20 °C.
- Mid-scale: the ideal raw value is 4999.5, so the converter reports 4999 or 5000. With 4999: 4999 × 120 = 599,880; 599,880 ÷ 9999 = 59 (59.99 exact); DM1010 = 59 - 20 = 39 °C. With 5000: 600,000 ÷ 9999 = 60; DM1010 = 40 °C. Accept 39 or 40 °C.
- Full scale: RAW = 9999, PRODUCT = 9999 × 120 = 1,199,880, QUOT = 1,199,880 ÷ 9999 = 120, DM1010 = 120 - 20 = 100 °C.
- Ramp across the whole loop and watch DM1010 step monotonically, one degree per 83.325 raw counts. A value that jumps or stalls points back at the execution condition or the product area.
When DM1010 reads wrong #
| What you see | Cause | Correction |
|---|---|---|
| Raw word wrong or frozen at the endpoints | Wiring, channel or input-type configuration, wrong input word | Fix the conversion path before touching the math |
| Raw word moves, DM1010 frozen | A one-shot such as DIFU in the chain | Drive the math with the Always-On bit |
| Low readings scale, high readings fail | 16-bit product area; overflow above RAW 546 | Use a 32-bit area for the 1,199,880 product |
| -20 °C shows as 65,516 | DM1010 read as an unsigned word | Read and consume DM1010 as signed |
| Slope drifts near full scale | Divide-by-83 shortcut in place of the ratio | Restore × 120 ÷ 9999 |
When the raw word itself wanders or steps instead of tracking the current, the scaling is not the fault; that class of failure is covered in troubleshooting non-linear 4-20 mA readings on an S7-1200 analog input.
Resolution limits, tenths of a degree, and a broken loop #
Whole-degree output is the limit of this chain: the quotient is already in °C, so the division's truncation costs up to just under 1 °C. When that is too coarse, scale in tenths. Multiply RAW by 1200 instead of 120 and subtract 200, and read DM1010 as tenths of °C from -200 to 1000. The product peak becomes 9999 × 1200 = 11,998,800, still a 32-bit job, and the mid-scale check gives 4999 × 1200 = 5,998,800 ÷ 9999 = 599, so DM1010 = 599 - 200 = 399, or 39.9 °C.
The 4-20 mA loop is a live-zero scheme under IEC 60381-1, the standard for direct-current process-control signals: 4 mA is the bottom of the measured range, so a healthy loop never signals below it. Outside those two loop currents this arithmetic extrapolates beyond -20 to 100 °C. Record what your channel actually reports with the loop open - whether the word can fall below 0 depends on the configured input range - and alarm on that condition instead of displaying an extrapolated temperature. A broken transmitter must never display as a real one.
The decision for DM1010 #
If DM1010 needs only the normalized value, MOVE the raw word into it and stop; no arithmetic is required. If it needs temperature in whole degrees, run the four-operation chain with a 32-bit product area, the Always-On bit as condition and a signed destination. If whole degrees are too coarse, run the tenths variant with × 1200 and a 200 offset. And if divide-by-83 is offered as a shortcut, decline it: the rounded slope fails the endpoint math shown above.
Questions asked
Why not just use the SCL instruction instead of manual math?
SCL is the scaling instruction documented in the CPM programming manual, and its help section shows the same straight-line formula, so it is a legitimate one-instruction answer. Manual MOVE, multiply, divide and subtract wins when you must control the size of the intermediate product, when you want tenths of a degree, or when other logic already expects your word layout. Both paths must pass the same three-point test.
What if my analog input uses a different full-scale count than 9999?
Substitute the documented count for 9999 and keep the same order of operations. Resolution varies across analog hardware: a current CP2E datasheet lists 1/4000 on voltage inputs and 1/2000 on 0 to 20 mA current inputs, so a channel can legitimately span 0 to 4000 or 0 to 2000 counts. Over the same 120 °C span, 0 to 4000 counts means 0.03 °C per count and a product peak of 4000 × 120 = 480,000, still too large for a 16-bit area.
How large is the error if I divide by 83 counts per degree?
The exact ratio is 9999/120 = 83.325 counts per °C, so dividing by 83 makes the slope 0.39% shallow and the untruncated error grows linearly to 0.47 °C at full scale. Truncation can hide that at the two endpoints you are most likely to test, while readings between them sit roughly a degree off, which is why the shortcut survives a two-point check and fails a ramp.
Why multiply before dividing - can I divide the raw word by 9999 first?
In integer arithmetic, RAW ÷ 9999 truncates to 0 for every raw value below 9999, so dividing first would store -20 °C across almost the whole span and jump to 100 °C only at full scale. Multiplying first carries the fraction through the division; the price is the 1,199,880 product that forces a result area wider than 16 bits.