Problem Description
Engineers integrating a Siemens SITRANS FM MAG 5000 electromagnetic flowmeter with a SIMATIC S7-1200 PLC frequently observe a perfectly matched instantaneous flow rate on the HMI, but a totalizer value that drifts away from the meter's faceplate reading over time. Typical signatures include:
- Flow rate (L/min or m3/h) on the HMI matches the MAG 5000 within ±0.5%.
- Totalizer on the HMI runs faster or slower than the MAG 5000 totalizer.
- Cumulative divergence grows with run time; rebooting the PLC brings both numbers back to the meter, but divergence re-accumulates within minutes.
- Discrepancy is more pronounced at low flow rates (below 10% of Qmax).
This is a classic analog-to-totalizer conversion error. The 4-20 mA current loop on the MAG 5000 carries an instantaneous flow value, not a volume integral. When the PLC tries to derive a totalizer from that mA signal, four classes of error appear simultaneously and stack up over the run.
Root Cause Analysis
The MAG 5000 outputs a 4-20 mA analog signal on terminals 31 (+) and 32 (−). This is a passive, loop-powered current output intended for instantaneous flow rate. Integrating that mA signal in the PLC over time to derive a totalizer introduces systematic error sources:
1. Analog-to-Digital Quantization
The S7-1200 SM 1231 analog input module has a resolution of 12 bits (SB 1231) or 13–16 bits depending on the variant. A 12-bit ADC over a 4-20 mA span (16 mA) gives a step size of 16 mA / 4096 = 3.9 µA per LSB. At low flow rates — say 2% of Qmax — the corresponding mA value is 4 + 0.02 × 16 = 4.32 mA, which is only 82 LSBs above zero. The ADC quantizes this to between 81 and 82 counts. The totalizer function multiplies each count by the engineering unit value, so a single LSB of ADC noise translates directly to volume error.
2. Sample-Rate Mismatch
The MAG 5000 current output update rate is approximately 0.5–1 second (verify against your firmware's output filter setting). If the PLC samples the mA signal faster than the meter updates, the same value is read multiple times, over-counting. If the PLC samples slower, transient flow peaks are missed, under-counting. Neither is correct for a totalizer.
3. Zero and Span Calibration Error
The 4 mA zero point and 20 mA span are user-scaled inside the MAG 5000. Any small offset between the analog range and the true flow calibration — or any drift in the analog loop (burden resistor tolerance, 24 V supply sag) — appears as a constant bias in the integrator. A 0.1 mA offset over an 8-hour shift at 50% flow produces a measurable totalizer error.
4. Output Resolution at Low Flow
Below 5% of Qmax, the 4-20 mA loop sits in the 4.0–4.8 mA region where loop noise, burden-voltage effects, and ADC offset combine to make the PLC read either 0 or 1 count when the true value is fractional. The totalizer either over-counts (jitter) or under-counts (zero-clamping) in this range.
The correct architecture is to use the MAG 5000's passive digital output on terminals 56/57, configured for volume pulse output. The meter generates the pulse train directly from its internal high-resolution volumetric accumulator; the PLC counts the rising edges to reproduce the meter's totalizer exactly, with no quantization, no scaling, and no integration error.
Hardware Topology
The MAG 5000 with the standard output module (and the HART variant) exposes the following terminals relevant to this fix:
| Terminal | Signal | Function | Notes |
|---|---|---|---|
| 31 | Current + | 4-20 mA passive analog output | Loop-powered, 24 VDC external required |
| 32 | Current − | 4-20 mA return | Connected to PLC analog input common |
| 33 | Ground | Reference | Bonded to panel ground |
| 56 | Pulse + | Passive digital output (P) | External 24 VDC pull-up required |
| 57 | Pulse − | Passive digital output (M) | Switches internally to terminal 56 |
Wiring the Pulse Path
- Connect the 24 VDC source positive rail to MAG 5000 terminal 56.
- Run a signal conductor from terminal 57 to a high-speed counter input on the S7-1200 CPU (e.g., I0.0 for HSC1 on a CPU 1214C).
- Bond terminal 33 to the panel protective earth at a single point (star-ground).
- Use shielded twisted pair for the pulse cable; ground the shield at the PLC end only.
- Do not route the pulse cable in the same conduit as VFD output cables or unfiltered AC power.
The MAG 5000 also retains its 4-20 mA analog output. Both outputs are driven from the same internal volumetric engine, so instantaneous flow (analog) and accumulated volume (pulse train) remain in lockstep. The analog path is preserved for SCADA trending, PID control, and the operator HMI; the pulse path supplies the authoritative totalizer to the PLC.
MAG 5000 Pulse Output Configuration
Use the MAG 5000's 6-key keypad and 3-line display to navigate the parameter tree. The relevant parameter block is in the output configuration menu (path varies by firmware revision; the standard menu structure is shown below).
| Parameter | Name | Setting for Volume Pulse | Notes |
|---|---|---|---|
| 410 | Output mode | PULSE (value 3) | Select pulse, not frequency or alarm |
| 411 | Volume per pulse | 0.1 / 1 / 10 / 100 (unit-dependent) | Choose so that max flow gives ≤ 50 Hz |
| 412 | Pulse width | 1–10 ms | Must be shorter than the period of the max frequency |
| 413 | Output polarity | Active LOW (NPN sinking) | Match the PLC input polarity expectation |
| 414 | Output filtering | Off (0) | Any filter adds latency that distorts volume |
Pulse-Rate Sizing Rule
The pulse frequency at any flow rate Q is f = Q / Vpulse. To keep the rate inside the PLC's reliable counting band, target a maximum of 50 Hz at Qmax. Worked example:
- MAG 5000 DN150 with Qmax = 200 m3/h = 55.6 L/s
- Volume per pulse options: 0.1 L → 556 Hz (too fast), 1 L → 55.6 Hz (marginal), 10 L → 5.56 Hz (safe), 100 L → 0.56 Hz (coarse)
- Recommended: 10 L/pulse → 5.56 Hz max → safe margin for S7-1200 HSC with input filter at 0.1 ms
For batch applications where high totalizer resolution matters more than count-rate margin, choose the smallest Vpulse that keeps the rate below the PLC's input filter limit. For long-running custody or inventory applications, a coarser pulse with 64-bit software accumulation is usually preferred.
S7-1200 High-Speed Counter Configuration
The S7-1200 CPU has integrated high-speed counters (HSCs) on the onboard digital inputs. The exact mapping depends on the CPU model:
| CPU Model | HSC1 | HSC2 | HSC3 | HSC4 | HSC5 | HSC6 |
|---|---|---|---|---|---|---|
| CPU 1211C / 1212C | I0.0 | I0.1 | I0.2 | I0.3 | — | — |
| CPU 1214C / 1215C | I0.0 | I0.2 | I0.4 | I0.6 | I1.2 | I1.4 |
| CPU 1217C | I0.0 | I0.2 | I0.4 | I0.6 | I1.2 | I1.4 |
Maximum count rates per HSC: 200 kHz single-phase, 80 kHz quadrature (verify against your CPU's firmware release notes). For MAG 5000 pulse output at ≤ 50 Hz, the HSC has substantial headroom and is the recommended approach over polling a standard DI in OB1.
TIA Portal Configuration Steps
- Open your TIA Portal project and select the S7-1200 CPU in the project tree.
- Double-click Device Configuration → select the CPU → Properties → Digital Inputs.
- Locate the input channel wired to MAG 5000 terminal 57 (e.g., channel 0 / I0.0 for HSC1).
- Set the input filter to 0.1 ms (or 0.0 µs in newer firmware) so narrow pulses are not rejected.
- Under High-Speed Counter (HSC), enable HSC1, type Count (not Measure or Motion).
- Set initial count value to 0 and let the counter increment freely.
- Set the maximum count value to 2 147 483 647 (DInt max) to avoid wraparound for typical applications.
- Assign a hardware interrupt to the HSC for SYNC/RESET events only; for plain counting the value is read on demand in the user program.
Sample Structured Text Logic
Direct pulse-to-volume conversion in the user program:
// Read HSC1 current value (DWord from hardware ID)
iRawCount := "HSC1_Count";
// Convert pulse count to engineering units (liters per pulse from MAG 5000 param 411)
rVolume_L := DWORD_TO_DINT(iRawCount) * diLitersPerPulse;
// Display on HMI tag
"Totalizer_L" := LREAL_TO_REAL(DINT_TO_LREAL(rVolume_L) / 1000.0);
For 64-bit accumulation (recommended for unattended operation):
// Persistent 64-bit totalizer in a global DB
IF bFirstScan THEN
lrTotalPulses := 0;
iLastRaw := 0;
bFirstScan := FALSE;
END_IF;
iRaw := "HSC1_Count";
diDelta := DWORD_TO_DINT(iRaw) - iLastRaw;
iLastRaw := DWORD_TO_DINT(iRaw);
// Accumulate (DInt delta is always small relative to LReal accumulator)
lrTotalPulses := lrTotalPulses + DINT_TO_LREAL(diDelta);
// Convert to volume and write to HMI
rTotalVolume_m3 := lrTotalPulses * rLitersPerPulse / 1000.0;
"Totalizer_m3" := rTotalVolume_m3;
Persisting lrTotalPulses in a retentive DB (or via the S7-1200's recipe/data log) ensures the totalizer survives a power cycle. Alternatively, write lrTotalPulses to the PLC's load memory on shutdown using a hardware interrupt on power-fail, or schedule periodic writes every 60 seconds.
Step-by-Step Migration from Analog Totalizer to Pulse Totalizer
- Stop the process flow, or document the current PLC totalizer value to add to the new pulse-based totalizer after cutover.
- On the MAG 5000, navigate to parameter 410 and set Output Mode to PULSE.
- Set parameter 411 (Volume per pulse) using the sizing rule above so peak flow yields < 50 Hz.
- Set parameter 412 (Pulse width) to 1 ms for short pulses, or 5–10 ms if you have a slow downstream counter.
- Wire terminal 57 of the MAG 5000 to the S7-1200 high-speed counter input (I0.0 for HSC1 on a CPU 1214C).
- Power terminal 56 from a 24 VDC supply rail. Use the same PLC 24 V or an isolated supply; add a 1 A fuse for short-circuit protection.
- In TIA Portal, configure HSC1 as described and download the program.
- Force the S7-1200's HSC count to zero and clear the retentive totalizer.
- Use the MAG 5000's Service → Test menu to inject a known number of pulses, or run a calibrated volume through the line.
- Compare the PLC totalizer with the MAG 5000's Totalizer A reading. They must match within ±1 pulse (i.e., within the chosen Vpulse resolution).
- Resume normal operation. Monitor for 24 hours and verify the PLC totalizer tracks the MAG 5000 totalizer within the pulse resolution.
Verification Procedure
After the migration, perform these checks before declaring success:
Functional Test
Run a known volume through the meter — for example, drain a calibrated tank of exactly 1000 L. The PLC totalizer must read 1000 L / Vpulse counts (i.e., 100 counts if Vpulse = 10 L), and the MAG 5000's Totalizer A must show 1000 L. If they differ by more than 1 pulse, re-check the wiring polarity and the HSC input filter time.
Rate Cross-Check
At a steady flow, multiply the measured pulse frequency (Hz) by Vpulse to obtain flow rate. Compare against the 4-20 mA-derived flow rate. They must match within 1%.
Long-Term Drift Test
Run the system for at least 24 hours at typical operating conditions. The PLC totalizer and the MAG 5000 totalizer must remain aligned within the pulse resolution. Any growing divergence indicates missed edges (pulse width too short), input filter misconfiguration, or HSC overflow.
Edge Capture Verification
Use the TIA Portal online monitor on the HSC hardware ID. Force the HSC value to 0, then inject 100 test pulses from the MAG 5000. The HSC must read exactly 100. If it reads 99 or 101, check the input filter setting.
Why Not Use Both Outputs?
The MAG 5000 supports concurrent analog and digital outputs. The 4-20 mA continues to drive the SCADA/HMI display and any PID control loops; the digital pulse output drives the PLC totalizer. This dual-output architecture is the recommended pattern because:
- The analog path remains available for trending and control without modification.
- The pulse path provides drift-free accumulation immune to ADC quantization.
- Each output can be scaled independently (different ranges for different consumers).
- The MAG 5000 has two internal totalizers (A and B) that can be assigned to different reset conditions or units, both fed from the same volumetric engine.
There is no firmware lockout that prevents simultaneous use. Refer to chapter 5 of the SITRANS FM MAG 5000/6000 Operating Instructions (A5E02338368) for the output module configuration block.
Calculating the Analog-Integration Error
For a quantitative view of the drift, consider a 50 mm MAG 5000 with Qmax = 16 m3/h (4.44 L/s). Operating at 1 L/s (22.5% of Qmax), the analog output is 4 + 0.225 × 16 = 7.6 mA. Over an 8-hour shift at 1 L/s, the true volume is 28 800 L. With a 12-bit ADC and 1-second sample rate, the per-sample error is ±0.5 LSB = ±0.5 × 0.0111 L = ±0.0056 L per sample. Across 28 800 samples, random errors average out but offset errors do not. A 0.05 mA calibration offset (just 0.3% of span) at 1 L/s produces 0.05/16 × 1 = 0.0031 L/s of systematic error, accumulating to 90 L over 8 hours — a 0.3% totalizer error.
For applications where totalizer accuracy matters — custody transfer, batch dosing, regulatory reporting — the pulse path is the only acceptable solution.
Troubleshooting Matrix
| Symptom | Likely Cause | Corrective Action |
|---|---|---|
| PLC totalizer reads 0 with flow present | HSC not enabled or wrong input mapped | Recheck device configuration and HSC channel assignment |
| Totalizer counts 1, 2, 3, ... but unrelated to volume | Volume-per-pulse set incorrectly | Re-enter parameter 411 with correct engineering units |
| Totalizer counts random bursts when pump is off | EMI pickup on long cable run | Use shielded cable, separate from power, add ferrite core |
| Totalizer stops at low flow, recovers at high flow | Pulse width too long for short intervals | Reduce parameter 412 to 1 ms |
| Totalizer runs at 2× expected rate | Double-edge counting in software | Configure HSC for rising-edge only; remove any redundant DI input in code |
| Totalizer drifts negative after long runtime | Wraparound not handled in software | Implement 64-bit accumulator or set HSC max to DInt maximum |
| MAG 5000 shows error code on display | Output wiring shorted or over-current | Verify 24 V polarity; check that load current is below 100 mA |
| Totalizer drift returns after PLC restart | Retentive totalizer not implemented | Persist lrTotalPulses in a retentive DB; reload on startup |
| PLC reads mA value but HSC counts 0 | Pulse output not configured; still in current output mode | Set MAG 5000 parameter 410 to PULSE |
| HSC counts every pulse at 0.1 L/pulse but jumps to wrong values at 10 L/pulse | Pulse width exceeds the period at high flow | Reduce parameter 412 to 1 ms; verify period = 1/f |
Alternative: HART-Based Totalizer Readback
If the application permits a slower update rate and the meter has the HART output module, the S7-1200 can read the MAG 5000's Totalizer A register directly over HART using a SM 1238 HART module or a third-party HART-to-Modbus gateway. This eliminates the wiring to terminals 56/57 entirely and is drift-free because the totalizer is read, not derived. The trade-off is HART latency (typically 0.5–2 s per variable), which makes this approach unsuitable for high-speed control but ideal for slow update SCADA totalization. Refer to the HART Communication Protocol Specification (HCF_SPEC-13) for the device variable 0 (PV = flow) and variable 9 (totalizer) mappings.
Edge Cases and Field-Proven Caveats
- Pulse output and totalizer reset interaction: When the MAG 5000's Totalizer A is reset via the keypad, the pulse output continues to fire from the running totalizer engine until the next 100 ms update cycle. If your PLC totalizer is synchronized to a reset, allow a 200 ms deadband after issuing the reset command before trusting the PLC count.
- Direction of flow: MAG 5000 supports bidirectional flow. The pulse output is signed only if reverse-flow is enabled; the firmware default is positive-only. Check parameter 420 (flow direction) on your unit.
- Empty pipe detection: The MAG 5000 outputs a configurable signal on empty-pipe detection. If the pulse output is wired and empty-pipe occurs, the meter outputs zero flow but the pulse output may be held at its last state depending on parameter 415. Verify the empty-pipe behavior on your firmware revision.
- Hot cutover: If the process cannot be stopped, perform the migration live: parallel-wire the pulse output, validate the PLC count against the analog-derived totalizer for 24 hours, then switch the HMI source from analog-derived to pulse-counted when parity is confirmed.
- Grounding: The MAG 5000 has separate protective earth (PE) and signal ground terminals. The pulse output is optically isolated, so grounding the 24 V supply return at the PLC cabinet is sufficient. Do not bond terminal 33 to terminal 56 or 57.
Related Parameters for Cross-Verification
To validate that the pulse output and the on-meter totalizer are derived from the same engine, read these MAG 5000 parameters during commissioning and record them in your PLC project documentation:
- Parameter 300: Qmax (full-scale flow)
- Parameter 311: 4 mA flow calibration
- Parameter 312: 20 mA flow calibration
- Parameter 410: Output 1 mode
- Parameter 411: Output 1 volume per pulse
- Parameter 412: Output 1 pulse width
- Parameter 700: Totalizer A engineering unit
- Parameter 701: Totalizer A reset enable
Capturing these as a parameter sheet ensures that the pulse rate, totalizer unit, and PLC scaling constant are all sourced from the same engineering decision and remain in lockstep during commissioning and audits.
Why does my S7-1200 totalizer drift even though the flow rate matches the meter?
The 4-20 mA analog signal from the MAG 5000 carries instantaneous flow, not volume. Integrating that signal in the PLC introduces quantization, sampling, and scaling errors that accumulate as drift. Use the passive digital output on terminals 56/57 configured for pulse output, and count pulses with a S7-1200 high-speed counter, to obtain a drift-free totalizer.
Can the MAG 5000 drive the 4-20 mA analog output and the digital pulse output at the same time?
Yes. The MAG 5000 standard output module provides one current output on terminals 31/32 and one passive digital output on terminals 56/57 that operate simultaneously. The pulse train is generated from the same internal volumetric engine that drives the analog output, so both signals remain in lockstep.
What pulse width and volume-per-pulse should I set on the MAG 5000 for an S7-1200 HSC input?
Set the pulse width to 1 ms for most applications. Choose volume-per-pulse so that Qmax divided by volume-per-pulse stays below 50 Hz. For example, 10 L/pulse at 500 L/min maximum flow gives 0.83 Hz. The S7-1200 onboard HSC counts up to 200 kHz, but slower rates reduce EMI sensitivity and simplify troubleshooting.
Which S7-1200 digital input should I use for the MAG 5000 pulse output?
Use a high-speed counter (HSC) input. On CPU 1214C, HSC1 maps to I0.0, HSC2 to I0.2, HSC3 to I0.4, HSC4 to I0.6, HSC5 to I1.2, HSC6 to I1.4. Standard digital inputs filtered at 6.4 ms will miss fast pulses; HSCs capture edges down to 1 µs when the input filter is set to the minimum value.
Do I need to set the DI filter time to zero on the S7-1200 for pulse counting?
Yes. The default input filter on the S7-1200 is typically 6.4 ms, which rejects pulses shorter than that. In TIA Portal set the filter time of the HSC input channel to 0.1 ms (or 0 µs depending on firmware) so the HSC sees every edge from the MAG 5000 pulse output.