IMDHMIControls LibraryShop main store

Troubleshooting

Why a TM221 analog input reads counts and not volts

Controllers and I/O Published 6 min read By IMDHMI controls team

Short answer

The word %IW0.0 on a TM221 is an integer count on the channel's configured scaling range, 0 to 10000 for 0 to 10 V, so 1000 counts represent 1 V. A straight copy keeps counts, and a straight move into a %MF fails on type; convert with INT_TO_REAL, then divide by 1000.0. Setting the channel minimum and maximum to 0 and 1000 makes the count hundredths of a volt instead.

On this page
  1. What %IW0.0 actually holds
  2. Where the meter and the table disagree
  3. Convert the count to a real, then divide
  4. Set the channel range to hundredths of a volt
  5. What ten-bit resolution decides
  6. Fix it in this order
  7. Questions asked

Your copy did its job — the units are not what you expect. On a Modicon TM221, the analog channel A0 reports its signal as the integer word %IW0.0, scaled across the range configured for that channel. In the project behind this fault that range is 0 to 10000 over a 0-10 V input, which puts 1000 counts on every volt. %MW0 := %IW0.0 moves that integer faithfully, so the animation table shows whole counts while the multimeter shows volts with decimals.

The type error is a separate matter: %IW0.0 is an integer, %MF5 is a floating-point word, and a direct move between the two is refused. The fix is one operate block with an explicit conversion:

%MF5 := INT_TO_REAL(%IW0.0) / 1000.0

The sections below verify the count against the meter, show the arithmetic, and end with the decision for each channel configuration.

What %IW0.0 actually holds #

The M221 hardware guide documents two analog inputs embedded on the controller; channel 0 — the A0 terminal — appears in the program as %IW0.0. The addressing comes from the IEC 61131-3 model these controllers program in: %IW is a directly represented input word, %MW an integer memory word, %MF a floating-point memory word, and the INT and REAL types are distinct, which is why the controller refuses to move one into the other without a conversion.

What the number means is set by the channel's scaling configuration, its minimum and maximum. Read those two values before any arithmetic: families pick their own endpoints, and the S7-300 convention of 0 to 27648 counts across the span is a different mapping for the same kind of input.

Where the meter and the table disagree #

Work down this list before touching the program:

  • The copy is not the fault. %MW0 := %IW0.0 moves the integer count faithfully; it was never volts. Expect a mismatch of units, not yet of wiring.
  • Redo the meter reading in counts. With the default 0-10000 scaling, a meter reading of 0.445 V should show about 0.445 × 1000 = 445 counts. A table value of 40 computes to 0.040 V, so 40 against 0.445 V points at wiring or channel mapping, not at decimal places.
  • Measure at the input terminals. Probe between the A0 input terminal and the analog reference the controller's wiring diagram gives, not across the potentiometer's outer legs. If the terminal voltage does not follow the wiper, fix the wiring first.
  • Sweep and watch. Move the potentiometer through several stable positions, let the meter and the animation table settle, and confirm %IW0.0 rises smoothly with the terminal voltage toward the top of the scale.
  • Check for a second writer. Another rung that assigns %MW0 can mask the input; the animation table shows both words, so compare them live.
  • Stay inside the range. Keep the track voltage within the channel's input span: a potentiometer fed from a 24 V supply overranges the input, so feed it from a source that cannot exceed the range maximum.

Convert the count to a real, then divide #

The compile error on %IW0.0 into %MF5 is the typed system working as intended: an integer needs an explicit conversion before it can land in a floating-point destination. SoMachine Basic — the current releases carry the name Machine Expert Basic, and the conversion is documented for SoMachine Basic V1.5 SP1 — provides INT_TO_REAL for use in an operate block, in the form %MF10 := INT_TO_REAL(%MW2). Applied to channel 0, the whole conversion is:

%MF5 := INT_TO_REAL(%IW0.0) / 1000.0

Two details decide whether the digits come out right. Convert first and divide second: an integer divided before conversion truncates the fraction before it can reach the real. And divide by a real literal — 1000.0, decimal point included — so the division itself runs in floating point. Give %MF5 backing memory that no other logic overwrites; an overlapping word variable is a common way a real comes out garbled.

Worked example: 1.546 V from the meter to the table #

The multimeter across A0 reads 1.546 V.

  1. Expected count on the 0-10000 scale: 1.546 × 1000 = 1546 counts.
  2. The converter has 1024 codes across the 10 V span, so one code spans about 10000 / 1024 ≈ 10 counts on this scale; expect the table to settle on a nearby multiple of ten, 1550 rather than exactly 1546.
  3. With %IW0.0 = 1550, the program computes 1550 / 1000.0 = 1.55.
  4. Verdict: 1.55 V against 1.546 V on the meter is agreement — the 4 mV gap is smaller than one code step, so nothing is wrong and there is nothing to tune.

Set the channel range to hundredths of a volt #

You can make the integer itself read in hundredths instead. In the analog channel configuration, set the scaling minimum and maximum — the mini and maxi fields — to 0 and 1000: the channel then maps the input span onto 0-1000 counts and each count is a hundredth of a volt. The conversion keeps its shape and changes only its divisor:

%MF5 := INT_TO_REAL(%IW0.0) / 100.0

At 1.546 V the table now reads about 155, and 155 / 100.0 = 1.55. The setting changes the arithmetic, not the hardware: 1000 counts spread across the converter's codes is roughly one count per code, so this configuration tracks the converter more closely than the default scale does.

Channel minimum–maximum The integer reads as Divide the real by
0-10000 thousandths of a volt 1000.0
0-1000 hundredths of a volt 100.0

Any other endpoints follow the same linear rule, volts = volts_min + (count - count_min) * (volts_max - volts_min) / (count_max - count_min), and the walkthrough on converting 0-10000 counts to engineering units works that arithmetic step by step. The same math runs backwards when you drive an output: scaling a PID real output to analog output counts covers the engineering-units-to-counts direction.

What ten-bit resolution decides #

The converter behind both configurations is 10-bit: 1024 codes across the input span works out to about 9.8 mV per code, the ±10 mV quantization quoted for this input. No divisor, no scaling choice and no extra decimal place in %MF5 changes that — a real can carry six decimals, but the converter only ever delivers about a hundredth of a volt per step. Make one code step the pass criterion at commissioning: agreement inside it means the conversion is right, and a difference beyond it means wiring, channel mapping or the wrong scaling endpoints.

Fix it in this order #

  1. Measure at the A0 input terminal against its analog reference and sweep the potentiometer, keeping the voltage inside the channel's input range.
  2. Open the analog channel configuration and write down the scaling minimum and maximum you find there.
  3. Watch %IW0.0 in the animation table and check it against the expected count: terminal voltage times counts-per-volt for your configured range.
  4. Add the conversion with INT_TO_REAL and the divisor the table above gives for your range; compile, download and run.
  5. Compare %MF5 with the meter. Agreement within one code step finishes the job; a larger difference sends you back to wiring, mapping or the configured endpoints.

The decisions, one per case: with the default 0-10000 scaling, convert with INT_TO_REAL and divide by the thousandths divisor. With mini 0 and maxi 1000, divide by the hundredths divisor. A refused direct move into %MF5 is not a fault — add the typed conversion. A table value that misses the meter by more than a code step is a wiring or mapping fault, and no divisor will fix it.

Questions asked

Can a TM221 read a 4-20 mA transmitter on its built-in inputs?

The embedded analog inputs expect a voltage signal within the 0 to 10 V range. For a current loop, the TMC2AI2 analog cartridge adds two input channels to the controller for exactly that case. Configure the cartridge channel for the current range, then read its integer input word, convert it with INT_TO_REAL and divide by the divisor the configured range implies.

Why does the animation table value step by about ten counts instead of moving smoothly?

The converter has 1024 codes over the full span. On the default 0 to 10000 integer scale, one converter code spans roughly ten counts, so the displayed integer moves in steps of about ten. Setting the channel maximum to 1000 gives close to one count per code, so the same hardware reads as single-count steps.

Is SoMachine Basic still the software to use for this?

The software has been renamed Machine Expert Basic and is the same tool line; it opens the same projects. Menu names move between versions, so if you cannot find a setting, look for the analog channel configuration with its scaling minimum and maximum fields, and for the animation table used to watch %IW0.0 live.

Why does an input on a TM3 expansion module read zero with the transmitter wired?

TM3 analog input modules do not supply power to the input loop. A two-wire transmitter needs its own loop supply or must be self-powered before the module can read it. The controller's embedded inputs expect the voltage to already be present at the terminals, so an unpowered or disconnected transmitter reads stuck near zero in either case.

Keep reading

  • Troubleshooting

    CODESYS analog inputs read 0 on an I2C ADC: where the chain breaks

    Relays that switch and an i2cdetect entry at 16#68 prove the I2C bus is sound, and raw bytes that track the input prove the MCP3422 converts. The zero therefore sits in the UniPi_AI driver layer or the I/O mapping. Poll the chip with a raw read to confirm the split, then fix the mapping, the bus-cycle task and the Always update variables flag instead of the bus.

    Controllers and I/O

  • Troubleshooting

    Fix a DL-06 4-20 mA reading that drops to half

    When the raw input word holds steady while the scaled value falls, the fault is in the ladder conversion path, not the 4-20 mA signal. On a DL-06 whose module setup returns binary counts, delete the BIN instruction that assumes BCD, and the reading comes back correct.

    Controllers and I/O

  • Troubleshooting

    Fix small nonzero counts at zero flow on a DVP04AD-E2 input

    Counts of 20-30 at 4 mA on a 0-32000 span are 0.06-0.09% of span, about 10-15 µA of loop error: that is normal converter offset and jitter. Verify the loop with a calibrator, calibrate measured endpoints per channel, then filter. A reading of 100 counts on another channel is a wiring or channel-offset clue, not a scaling error.

    Controllers and I/O