Problem Overview
A Schneider Electric Telemecanique XX-series ultrasonic distance sensor with a 4-20 mA analog output is wired into a Siemens LOGO! 8 base module or AM2 expansion module. The sensor's published physical range is 105 mm to 1000 mm (an 895 mm span). The user expects the LOGO! display or process value tag to read in millimeters, but the engineering-unit conversion is wrong by hundreds of millimeters. Field measurements show that 500 mm physical distance produces a raw LOGO! value of 645, 110 mm produces 992, and 270 mm produces 908. The mapping is clearly non-trivial because the sensor output is inverted: smaller physical distance corresponds to a higher raw value, not a lower one.
The objective of this procedure is to derive a single linear scaling equation that maps the LOGO! raw integer (0-1000) directly to a 0-1000 mm engineering range, implement it with the LOGO! 8 Gain/Offset (formerly "Analog Amplifier") function block, calibrate it with two known targets, and verify linearity at a third target. After implementation, the LOGO! display or process value tag should report physical distance in millimeters to within the sensor's published accuracy band, typically ±0.5 % of full scale plus the acoustic-resolution floor of the XX-series transducer.
Sensor Signal Chain and I/O Configuration
Industrial ultrasonic distance sensors in the Schneider Electric XX family (XX5, XX6, XX9 prefixes) are two-wire loop-powered devices in their 4-20 mA variant. They drive 24 VDC across the loop and modulate the current proportional to the measured acoustic time-of-flight. The 4 mA lower endpoint corresponds to one extreme of the configured measurement window, and 20 mA corresponds to the other. The polarity of that mapping (which extreme is 4 mA and which is 20 mA) is configured either by a teach-in pushbutton, by wiring convention, or by the order code of the specific XX model.
The signal chain into the LOGO! is therefore:
- Sensor head emits a 200-500 kHz burst, receives the echo, and converts the time-of-flight to a loop current.
- Two-wire loop carries 4-20 mA into the LOGO! AM2 analog expansion module (catalog designation 6ED1055-1MA00-0BA2 for the 12/24 V version, 6ED1055-1MA00-0BA8 for the 24 V version). See the LOGO! 8 System Manual, Edition 04/2023 for the module's input ranges and jumper positions.
- The AM2's ADC resolves the current to a 10-bit signed integer that LOGO! Soft Comfort surfaces as a 0-1000 raw value when the module's jumper is in the 0-20 mA position, or as a 0-1000 raw value when the jumper is in the 4-20 mA position (the jumper selects the electrical range, not the engineering scaling).
- LOGO! Soft Comfort ladder/FBD logic applies the Gain/Offset math block to translate the raw integer into a millimeters engineering value.
For a more general treatment of sonar signal-chain conditioning (analog front-end, gain stages, ADC selection, and noise floor) see the Analog Devices Sonar Signal Chains reference design overview. The general principle that an analog current or voltage front-end must be conditioned to match the ADC input span applies identically to industrial ultrasonic sensors as it does to hydrophone arrays, and a description of the underlying direct-conversion analog processing is given in the ScienceDirect Direct Analogs overview.
Understanding the Telemecanique XX Series Output Polarity
The user-reported raw values (645 at 500 mm, 992 at 110 mm, 908 at 270 mm) are monotonically decreasing as the physical distance increases, which is the diagnostic signature of a reverse-acting analog output. In this configuration, 20 mA corresponds to the near end of the measurement window (105 mm) and 4 mA corresponds to the far end (1000 mm). This is the most common default for diffuse-reflective ultrasonic sensors used for liquid level or bulk-material level, because the loop current then increases as the material rises toward the sensor (and operators expect the current to "go up" as the level rises).
If your specific XX model has been re-taught to invert this mapping, the slope sign in the formula below flips, and the procedure is otherwise identical. To confirm the polarity in the field, place a flat target at a known near distance (e.g., 150 mm) and a known far distance (e.g., 800 mm). If the higher raw integer corresponds to the nearer target, the configuration is reverse-acting and you should use the formula in this article as written.
| Test Condition | Physical Distance | Expected Raw (Reverse-Acting) | Expected Raw (Direct-Acting) |
|---|---|---|---|
| Target at near limit | 105 mm | ≈ 1000 | ≈ 0 |
| Target at midrange | 500 mm | ≈ 645 | ≈ 355 |
| Target at far limit | 1000 mm | ≈ 0 | ≈ 1000 |
The user's 645 at 500 mm matches the reverse-acting column, which confirms the polarity assumption used in the rest of this procedure.
The Scaling Mathematics: 4-20 mA → 0-1000 raw → mm
The conversion has two linear stages. The first stage is electrical: the AM2 module in 0-20 mA mode maps the loop current to a raw integer with the relation
mA = raw × 0.020
The second stage is the sensor's own transfer function. For a reverse-acting 4-20 mA ultrasonic sensor with a 105 mm to 1000 mm window, the engineering-unit mapping is
Distance (mm) = 1000 − ((mA − 4) / 16) × 895
Substituting the first stage into the second and simplifying yields a single linear equation in raw:
Distance (mm) = 1223.75 − raw × 1.11875
Validate this against the user's three field samples:
| Reported Physical (mm) | Reported Raw | Formula Output (mm) | Error (mm) |
|---|---|---|---|
| 500 | 645 | 502.2 | +2.2 |
| 110 | 992 | 114.0 | +4.0 |
| 270 | 908 | 208.0 | −62.0 |
The 500 mm and 110 mm samples are within the sensor's typical ±1 % linearity band; the 270 mm sample is off by 62 mm, which is outside linearity for a properly aimed XX-series transducer and is most often caused by acoustic reflections off the mounting bracket, a non-perpendicular target, or air-temperature-induced sound-velocity error. The procedure's verification step is designed to catch this kind of systematic error using a third known target.
LOGO! 8 Implementation: Gain/Offset Block
The Gain/Offset block (BF: "Math") in LOGO! Soft Comfort implements the linear function
Q = a × (Ax − b) + c
where Ax is the raw analog input (0-1000), Q is the engineering output, and a, b, c are user-entered constants. To realize the formula Distance = 1223.75 − 1.11875 × raw, set:
| Parameter | Value | Purpose |
|---|---|---|
| Gain (a) | −1.11875 | Slope of mm/raw |
| Offset (b) | 0 | No input offset; raw is already 0 at 0 mA |
| Offset (c) | 1223.75 | Engineering y-intercept (mm at raw = 0) |
Block programming steps in LOGO! Soft Comfort (V8.3 or later):
- Open your project and locate the AM2 input tag in the I/O list, e.g.
AI1(this is the raw 0-1000 integer). - From the instruction palette, drag the Math (BF) function block onto the FBD sheet.
- Double-click the block. In the properties dialog, set the operation mode to Gain/Offset (not "PID" or "Addition").
- Assign the input:
Ax = AI1(the AM2 raw input). - Enter Gain:
a = −1.11875. Enter the input-side offset:b = 0. Enter the output-side offset:c = 1223.75. - Set the output
Qto a new tag, e.g.Distance_mm. - Enable block output to the LOGO! display (Tools → Message Text) and set the display format to integer with one decimal place suppressed:
Distance_mm / 1mm. - Compile and download to the LOGO! base module.
The Gain/Offset block runs every LOGO! scan cycle (typical 10-50 ms depending on program size), and the result is updated at the same rate. The AM2 conversion itself runs at the module's configured sample rate (default 50 ms; configurable to 12.5 ms, 25 ms, 50 ms, or 100 ms via the parameter dialog in LOGO! Soft Comfort).
Alternative: Two-Stage mA-to-mm Conversion
If the AM2 module is set to 4-20 mA jumper mode instead of 0-20 mA mode, the raw integer is mapped over the 4-20 mA span, so:
mA = 4 + (raw / 1000) × 16
The engineering formula then collapses to a much simpler form:
Distance (mm) = 1000 − (raw / 1000) × 895
which is directly realizable in the Gain/Offset block with:
| Parameter | Value | Purpose |
|---|---|---|
| Gain (a) | −0.895 | Slope of mm/raw |
| Offset (b) | 0 | No input offset |
| Offset (c) | 1000 | Distance in mm at raw = 0 |
This form is preferable if you have physical access to the AM2 jumper, because the integer-to-millimeter ratio is friendlier for HMI scaling and alarm thresholds. However, in 4-20 mA jumper mode the AM2 reports 0 for currents below 4 mA (open-loop or broken wire), which gives the same 0-1000 mm reading as the far limit. To distinguish "out of range low" from "open loop," wire a broken-loop diagnostic: if the raw integer ever reads exactly 0 while the sensor is supposed to be within range, the LOGO! logic should raise a Sensor Open Loop alarm. With 0-20 mA jumper mode, open-loop reads 0 mA, which is also raw 0; the diagnostic is identical.
Calibration Procedure
The scaling constants derived above are theoretical, based on the published sensor window and the AM2 jumper mode. Real-world installation introduces mounting-angle error, target reflectivity error, and acoustic-noise error, so two-point calibration is mandatory before the distance reading is used in any control loop.
- Mechanical setup. Mount the XX-series sensor to a rigid bracket with its acoustic axis perpendicular to a flat reference target. The target should be at least the diameter of the transducer face (typically 25-30 mm for the XX5, 50 mm for the XX6) and made of a material with diffuse-reflective acoustic properties (bare plywood, MDF, or rough concrete). Mirror-finish metal targets cause specular reflection and will produce non-repeatable readings.
-
Establish the near target. Position a flat target at a precisely known distance within 10 % of the published near limit. For a 105-1000 mm sensor, set the target at 150 mm measured with a calibrated steel rule or laser rangefinder (±1 mm). Note the LOGO! raw value displayed in the online monitor (Tools → Online → AI1 in LOGO! Soft Comfort). Call this
raw_near. -
Establish the far target. Move the same target to a precisely known distance within 10 % of the published far limit, e.g. 900 mm. Note the LOGO! raw value. Call this
raw_far. - Re-derive the gain and offset. The two known (raw, distance) pairs give a least-squares-trivial exact linear fit. Using the two-point form
a = (D_near − D_far) / (raw_near − raw_far)c = D_near − a × raw_near
enter these recalculated a and c into the Gain/Offset block, recompile, and re-download. The slope a will typically land within ±5 % of the theoretical −1.11875 (0-20 mA mode) or −0.895 (4-20 mA mode), confirming that the wiring polarity and jumper mode are correct.
- Verify the dead zone. Slowly move the target from 150 mm toward the sensor face. The XX-series has a published blind zone (typically 0-105 mm for the XX5, 0-100 mm for the XX6) inside which the sensor output is undefined. Confirm that the LOGO! distance reading saturates or pegs to the near-limit value when the target enters the blind zone, and that it tracks linearly once the target is outside it. If the LOGO! reads a non-saturating value inside the blind zone, the sensor is ringing on the transducer face and the target should be backed off to at least 1.2 × the published blind-zone distance.
Verification and Acceptance Criteria
After calibration, place the target at three independent verification points (for example 250 mm, 550 mm, and 800 mm) and record the LOGO! distance reading against the reference measurement. The acceptance criteria for industrial use are:
| Acceptance Tier | Acceptable Error at Verification Points | Typical Application |
|---|---|---|
| Level indication only (operator display) | ±1.5 % of full scale (±13.4 mm over 895 mm span) | Material-level HMI readout |
| Process control (pump on/off, alarm trip) | ±0.5 % of full scale (±4.5 mm over 895 mm span) | Sump pump control, high-level interlock |
| Closed-loop regulation | ±0.2 % of full scale (±1.8 mm over 895 mm span) | Web tensioning, position control |
If the verification points fail the relevant tier, do not adjust the gain to "bandage" the error at one point. Instead, repeat the calibration with fresh near and far measurements and inspect the mechanical mounting for skew, standoff-distance error, or acoustic interference from adjacent surfaces. A 2° mounting angle can produce a 5-10 mm ranging error at the far end of a 1000 mm sensor.
Common Pitfalls and Troubleshooting Matrix
| Observed Symptom | Likely Root Cause | Diagnostic Step | Corrective Action |
|---|---|---|---|
| Distance reading is stuck at 0 mm (or near 1000 mm) regardless of target position | Wiring polarity reversed at AM2 input, or 4-20 mA sensor wired to a 0-10 V AM2 input by mistake | Measure voltage across the AM2 input terminals with a multimeter; should be 0.8-5.0 VDC through the internal 250 Ω shunt, or 0-5 VDC across an external 250 Ω | Swap the two-wire polarity at the AM2 input, or replace the AM2 with the correct 0/4-20 mA version (catalog 6ED1055-1MA00-0BA2 or 6ED1055-1MA00-0BA8) |
| Distance reading is inverted (closer target reads larger mm value) | Sensor is in direct-acting mode instead of reverse-acting | Hold the target at 150 mm and 800 mm; the near target should give the higher raw value if reverse-acting | Either re-teach the sensor per the XX datasheet teach procedure, or flip the sign of the Gain parameter in the LOGO! block (change −1.11875 to +1.11875 and adjust c to 105) |
| Reading is noisy by ±10-30 mm | Acoustic reflections from nearby surfaces, mounting bracket ringing, or air turbulence in the beam path | Look along the acoustic axis with a flashlight; any surface within 0.5× the target distance and within the 5° beam cone is a likely reflector | Re-locate the sensor or add an acoustic absorber (felt, foam) to the offending surface; add a 4-sample moving-average filter in the FBD |
| Reading drifts with time of day | Temperature-dependent sound velocity, especially if the sensor is in direct sunlight or near a heater | Measure air temperature at the sensor face with a contact probe at 30-minute intervals and plot LOGO! distance vs. temperature | Add a 10 kΩ NTC thermistor and a second analog input, then apply a temperature-correction multiplier to the Gain parameter, or upgrade to an XX model with internal temperature compensation |
| Reading saturates before the published far limit (e.g., pegs at 950 mm when target is at 1000 mm) | Sensor's learn range is narrower than the published full scale, or the AM2 is in 4-20 mA mode and the far target is outside the configured window | Consult the sensor's teach-in LED status; re-teach the far limit per the XX datasheet | Perform a fresh teach-in with the actual far target at the actual operating distance |
| Distance reading is correct at one verification point but off by 30-60 mm at another | Target not perpendicular to the acoustic axis, or target is too small for the beam cone at that distance | Use a machinist's square to verify perpendicularity; check the target diameter against the published beam-spread table in the XX datasheet | Use a larger target (50-80 mm flat plate) or angle the sensor so its axis is normal to the target |
| AM2 reports 0 raw even though current loop measures 12 mA at the terminals | AM2 jumper is in 0-10 V position and the 4-20 mA signal is being read on a voltage input through the internal 250 Ω | Open the AM2 housing and inspect the jumper position per the LOGO! 8 System Manual | Move the jumper to the 0/4-20 mA position; power-cycle the LOGO! base module |
Wiring, Grounding, and EMC Notes
Two-wire 4-20 mA loops are sensitive to ground loops, especially when the sensor and the LOGO! are fed from different 24 VDC supplies. The recommended practice is to power the sensor from the same 24 VDC bus that feeds the LOGO! AM2 module, with the supply common tied at a single point. If separate supplies are unavoidable, use an isolated loop isolator (e.g., Phoenix Contact MACX MCR-EX-SL) between the sensor and the AM2 input. Shielded cable is required for runs longer than 5 m, with the shield grounded at the LOGO! end only. Routing the analog cable parallel to VFD output cables or servo motor leads will inject common-mode noise that the AM2's 10-bit resolution cannot reject, producing a 2-5 LSB jitter in the raw integer. Cross such cables at 90° and maintain a 200 mm separation.
The LOGO! base module's analog inputs on the unit itself (not the AM2 expansion) are 0-10 V only and cannot read 4-20 mA directly. Attempting to wire a current-output sensor to a voltage input without the 250 Ω shunt will produce a near-zero reading and may damage the AM2 input stage. Use the AM2 expansion (catalog 6ED1055-1MA00-0BA2 for 12/24 V units or 6ED1055-1MA00-0BA8 for 24 V units only) for all 4-20 mA inputs.
Expanding the Function: Hysteresis, Alarms, and Display
Once the Gain/Offset block produces a clean Distance_mm tag, the natural next steps are:
- Hysteresis on alarm thresholds. Use a LOGO! Schmitt-trigger (block BH) or threshold-trigger (block B2) with a configurable hysteresis (e.g., 5 mm) to debounce a high-level alarm. The hysteresis prevents the alarm from chattering when the target surface is rippling or when the acoustic echo is at the resolution floor of the sensor.
-
Out-of-range diagnostics. Add a comparison block (block B2 or B3) that asserts when
Distance_mm < 110(target in the blind zone) orDistance_mm > 1000(target beyond the far limit). The latter condition, combined with a raw integer still between 0 and 1000, indicates a sensor that has lost its echo and is reading its last valid value, not a true out-of-range. Flag this distinction in the HMI message text. -
HMI display formatting. In LOGO! Soft Comfort, drag a Message Text block to the FBD sheet and select the
Distance_mmtag as the bar-graph or numeric display. Use a 4-digit integer format and a 1-decimal suppressed layout; the LOGO!'s built-in display is 4 lines × 12 characters, and a clean "D = 532 mm" string fits comfortably. -
Retentive storage. If the LOGO! powers down and restarts, the AM2 will lose its last reading for one scan cycle. Use a retention-enabled tag for
Distance_mmif the downstream control logic cannot tolerate a single-cycle zero.
Cross-Platform Notes: Migrating the Formula to Other Small PLCs
The same scaling logic applies, with the constants unchanged, to other small PLCs that read 4-20 mA on a 0-1000 raw scale:
| Platform | Analog Input Block | Equivalent Gain | Equivalent Offset (c) |
|---|---|---|---|
| LOGO! 8 (AM2, 0-20 mA mode) | Math / Gain-Offset | −1.11875 | 1223.75 |
| LOGO! 8 (AM2, 4-20 mA mode) | Math / Gain-Offset | −0.895 | 1000 |
| Zelio SR3B261BD (4-20 mA extension) | Analog scaling function | −0.895 | 1000 |
| Siemens S7-1200 SM1231 (0-20 mA mode) | CALCULATE or NORM_X / SCALE_X | −1.11875 | 1223.75 |
| Siemens S7-1200 SM1231 (4-20 mA mode) | CALCULATE or NORM_X / SCALE_X | −0.895 | 1000 |
| Schneider Electric M221 TM3AI4 (4-20 mA) | SCALE function in EcoStruxure | −0.895 | 1000 |
For the S7-1200 specifically, the standard idiom is to wire the AI module's INT output to NORM_X (normalizing the raw integer 0-27648 to a real 0.0-1.0 floating-point), then to SCALE_X (scaling 0.0-1.0 to the engineering range 0-1000 mm), with a sign-flip handled by reversing the MIN and MAX parameters of SCALE_X. The result is a LREAL in millimeters that can feed directly into a PID_Compact process variable.
Field-Proven Caveats from Industrial Deployments
Several issues recur across multiple XX-series deployments that are worth flagging before commissioning:
- Mounting standoff. The transducer face should protrude at least 5 mm past the mounting bracket surface to avoid bracket-induced acoustic reflection. A flush-mounted XX6 will produce a 20-50 mm bias error at distances below 300 mm.
- Beam cone interference. The XX5 has a 5° beam cone and the XX6 a 7° cone; at 1000 mm the beam footprint is 90-120 mm in diameter. Sidewalls within this footprint, even at oblique angles, can produce secondary echoes that bias the reading by 10-30 mm. Coning the inside of an enclosure with acoustic foam eliminates this.
- Target material. Soft materials (foam, fabric, granular bulk solids) absorb ultrasound and reduce the effective measurement range by 20-40 %. Hard, dense, flat surfaces (water, metal plate, concrete) give the cleanest readings.
- Power supply noise. A switching 24 VDC supply with 200 mV peak-to-peak ripple will inject 1-2 LSB of noise into the AM2 ADC. Linear regulation or a pi-filter on the 24 V rail feeding the sensor loop reduces this to a sub-LSB level.
- Sensor warm-up. XX-series sensors need 200-500 ms after power-up to stabilize the analog output. The LOGO! AM2 will read whatever the sensor presents during that window, including the initial 0 mA power-on pulse some units emit. A 1-second startup delay in the FBD logic (using a TON timer) suppresses this.
FAQ
Why does my LOGO! raw value increase when the physical target gets closer, and what does that mean for the scaling equation?
The XX-series sensor is in reverse-acting output mode: 20 mA corresponds to the near limit (105 mm) and 4 mA corresponds to the far limit (1000 mm). The scaling equation must therefore have a negative slope. For an AM2 module in 0-20 mA jumper mode, use Distance (mm) = 1223.75 − raw × 1.11875. For an AM2 in 4-20 mA jumper mode, use Distance (mm) = 1000 − raw × 0.895.
What AM2 jumper position do I need for a 4-20 mA sensor?
Either position works electrically because the AM2's internal 250 Ω shunt converts current to voltage before the ADC. The 0-20 mA position gives a 0-1000 raw span over 0-20 mA and uses constants a = −1.11875, c = 1223.75. The 4-20 mA position gives a 0-1000 raw span over 4-20 mA and uses constants a = −0.895, c = 1000. The 4-20 mA position gives cleaner out-of-range detection because 0 mA (broken loop) reads 0 raw just like the far limit, and a broken-loop alarm block can flag that exact value. The 0-20 mA position requires a separate diagnostic input to distinguish broken loop from far limit. Refer to the LOGO! 8 System Manual for the jumper location.
Can I wire the sensor directly to the LOGO! base module's analog input (AI1-AI4) instead of the AM2 expansion?
No. The LOGO! 8 base module's on-board analog inputs are 0-10 V only, and they will read near 0 V when fed a 4-20 mA current signal, producing a 0 mm reading regardless of distance. The 0/4-20 mA current inputs are available only on the AM2 analog expansion module (catalog 6ED1055-1MA00-0BA2 for 12/24 V units or 6ED1055-1MA00-0BA8 for 24 V units only). The AM2 RTD module (6ED1055-1MD00-0BA2) is for PT100/PT1000 temperature sensors and cannot be used for 4-20 mA current loops.
My distance reading is off by 30-60 mm at the middle of the range but correct at the endpoints. Is the gain wrong?
Do not adjust the gain to compensate. A nonlinear error that is zero at the endpoints and large in the middle usually indicates either target skew (the acoustic axis is not perpendicular to the target surface) or acoustic multipath from a nearby reflector. Check the mounting with a machinist's square and inspect the area within 0.5× the target distance along the beam axis for any flat surface. The XX-series published linearity is ±0.5 % of full scale, so a 60 mm error at midrange is a mechanical or acoustic problem, not a calibration problem.
How do I add a high-level alarm at 800 mm and a low-level alarm at 200 mm to the scaled distance value?
Add a LOGO! Threshold Trigger (block B2) or Schmitt Trigger (block BH) downstream of the Gain/Offset block. For a high-level alarm, set On threshold = 800, Off threshold = 795 (5 mm hysteresis). For a low-level alarm, set On threshold = 200, Off threshold = 205. Wire the trigger output to a relay output (Q1 or Q2) for the alarm light or horn, and to a Message Text block for the HMI display. The 5 mm hysteresis prevents alarm chattering when the target surface ripples or when the acoustic echo is near the sensor's resolution floor.
Can I apply the same formula to other XX-series models with different ranges (e.g., 50-500 mm or 200-2000 mm)?
Yes, but the constants change. For a reverse-acting sensor with near limit N (mm) and far limit F (mm), on an AM2 in 0-20 mA mode the formula is Distance (mm) = (F + 1.11875 × N) − raw × 1.11875 × (F − N) / 895. On an AM2 in 4-20 mA mode the formula is Distance (mm) = F − (raw / 1000) × (F − N). Always confirm the published near and far limits from the specific XX model's datasheet, because some XX9 heads have a 0-10 V output option with a different scaling entirely.