IMDHMIControls LibraryShop main store

Explainer

Why a PLC tank simulation needs a plant model block

PLC programming Published 6 min read By IMDHMI controls team

Short answer

A PLC simulator runs your logic without hardware, so nothing converts the valve outputs back into level inputs and the feedback loop stays open. Add a plant-model code block that reads the output image, integrates the tank level with the real scan time, and writes the input image every scan, then prove it against a hand-computed fill time before connecting SCADA.

On this page
  1. Why the loop stays open without a plant model
  2. What the model block does every scan
  3. Constants to fix before you run
  4. Worked example: fill time for a 2 m tank fed at 12 L/min
  5. Hand checks that separate model faults from logic faults
  6. Connecting SCADA once the cycle runs
  7. Questions asked

A PLC simulator with no hardware attached executes your scan cycle but has nothing on the other side of the I/O: the valve bits your program writes never come back as level switches or an analog level word. The missing half is a plant model, a separate code block that runs every scan, reads the output image, and writes the input image from tank physics. Without it, forcing inputs by hand tests one scan at a time, and an animated tank graphic on an HMI proves nothing about the logic. Build the model beside the control logic, size it with numbers you can compute on paper, and connect SCADA only after the fill-and-drain cycle runs unattended. The worked example below sizes a 2 m tank fed at a fixed inflow and shows the two checks that matter: fill time and level rise per scan.

Why the loop stays open without a plant model #

A PLC simulator executes the same scan cycle as the controller, read inputs, solve logic, write outputs, but with no I/O modules attached the input image never changes. Your program switches the inlet valve output, and no level switch anywhere notices. Two shortcuts fail for specific reasons.

Forcing inputs by hand tests one scan at a time. It never shows what happens when the level keeps rising after the inlet opens, which is exactly where hysteresis, overflow and timing faults live. Letting the HMI or SCADA graphic animate the level proves nothing about the PLC: the output changes, no input responds to it, and the loop stays open. The control program is half of a feedback loop; the plant model is the other half.

What the model block does every scan #

Create two separate code blocks: the control logic and the process model. The control block must never write the level; the model block must never write the valve commands. Each scan the model block reads the output image, updates one level variable, and writes the input image: the analog level word and the discrete level-switch bits.

In words, conservation of volume says the level rises by inflow minus outflow, divided by tank area, times the elapsed time since the last scan. Explicit Euler, one step per scan, is enough for a tank because the step is tiny compared with how slowly a tank level moves. These are generic illustrative names, not documented ones; map them to whatever instruction set your simulator uses:

level_m  : REAL := 0.0;   // model state in metres, written only by this block
area_m2  : REAL := 0.5;   // tank cross-section, example value in m2
dt_s     : REAL;          // elapsed scan time in s, read from diagnostics
...
level_m := level_m + dt_s * (qin_m3s - qout_m3s) / area_m2;

Outflow through an open drain grows with level, so the tank self-regulates: with both valves held, the level settles where the outflow equals the inflow. Take the elapsed time from the simulator's own scan-time diagnostic each scan rather than typing a constant.

Constants to fix before you run #

Pick the tank numbers yourself in engineering units; take the scan time and the analog input range from the simulator's documentation and diagnostic displays.

Constant What it decides Where it comes from
Tank cross-section A Level ramp rate and fill time Your choice, in engineering units
Inlet flow Q_in Fill slope and equilibrium level Your choice; check the equilibrium against tank height
Switch levels and hysteresis band Clean cycling versus valve chatter Control logic constants
Analog full scale Counts per unit of level The simulator's analog input range in its I/O documentation
Elapsed scan time Integration step size The simulator's scan-time diagnostic display

Worked example: fill time for a 2 m tank fed at 12 L/min #

Inputs, with where each comes from:

  • Tank cross-section A = 0.5 m², a 1.0 m by 0.5 m rectangular tank, chosen by you.
  • Inlet flow Q_in = 12 L/min, which is 0.2 L/s or 0.0002 m³/s, chosen by you.
  • Switch levels h_low = 0.4 m and h_high = 1.6 m inside a 2 m tank, chosen by you.
  • Elapsed scan time dt = 10 ms, an example reading from the simulator's scan-time diagnostic.

The rule in words: with the drain closed, the level rises at Q_in divided by A, so the fill time between the two switches is the tank area times the level span, divided by the inflow.

The arithmetic: the volume to add is 0.5 m² × (1.6 m − 0.4 m) = 0.6 m³. The fill time is 0.6 m³ ÷ 0.0002 m³/s = 3000 s, which is 50 min.

The rise per scan is 0.010 s × 0.0002 m³/s ÷ 0.5 m² = 0.000004 m, about 4 µm per scan.

The equilibrium with the drain open: take an example orifice relation Q_out = k × √h with k = 0.0002 m^(5/2)/s. The level settles where k × √h equals Q_in, so h_eq = (Q_in ÷ k)² = 1.0 m.

The decision these numbers drive: a timer instruction in the PLC must measure close to the computed fill time, within a few percent on a 50-minute fill, the remainder being scan quantization. Any practical hysteresis band, millimetres wide, dwarfs the 4 µm rise per scan, so chatter is not a risk at this tank size; the band starts to matter when you shrink the tank or raise the inflow. And 1.0 m of equilibrium in a 2 m tank means a stuck-on inlet cannot overflow on its own, so to test the high-level switch and alarm you force the fault rather than wait for the level to arrive there.

One safety note: keep a clamp in the model that pins the level at the tank top, so a bug under test cannot silently walk past the level that would overflow real hardware.

Hand checks that separate model faults from logic faults #

  • Level never moves: a model fault. Check that the valve command bit actually reaches the model's inflow term and that the elapsed time is nonzero.
  • The valve flips every few scans: a logic fault. The hysteresis band is narrower than the level change per scan.
  • Fill time off by a constant ratio: the model's time step does not match the real scan time. Read the scan time live each scan, or run the model in a fixed-interval task and use that interval as its step.
  • Settled level wrong: the outflow coefficient does not match; recompute the equilibrium from the coefficient you actually coded and compare.
  • Step too coarse: halve the scan time or the model step and re-run. If the measured fill time changes beyond rounding, the step is too large for how fast this tank actually responds.

Connecting SCADA once the cycle runs #

Run the fill-and-drain cycle unattended through at least one complete cycle before adding screens. The HMI or SCADA then reads tags such as level, valve states and alarms, and writes command bits such as auto/manual and manual valve requests, which the control logic arbitrates. Never let a screen write the level tag itself: the model overwrites it on the next scan, or the level stops reflecting what the PLC decided, and either way the test is void.

For connecting a SCADA package to a simulator with no hardware, see Connecting Vijeo Citect SCADA to PLCSIM without a PLC (article:connecting-vijeo-citect-scada-to-plcsim-without-a-plc); for controlling what SCADA may write into output registers, see Safe Modbus writes to PLC output registers from SCADA (article:safe-modbus-writes-to-plc-output-registers-from-scada). Once the loop closes, the HMI side deserves its own test, and testing an HMI simulation against a live PLC walks through that comparison.

Questions asked

Why does my simulated tank fill at the wrong speed even though the logic is correct?

The most common cause is a time step stored as a constant that does not match the real scan time; every ramp then scales by the ratio of the two. Read the elapsed scan time from the simulator's diagnostic each scan, or run the model in a fixed-interval task and use that task's interval as the step. Also confirm the valve command bit actually reaches the model's inflow term.

Can I force the input values by hand instead of writing a plant model?

Forcing works for one scan at a time: you can toggle a low-level switch and watch a rung fire, but the level never keeps rising after the inlet opens, so hysteresis, overflow behavior and fill timing stay untested. A plant model closes the loop automatically every scan and exposes those faults without any hardware on the bench.

How much detail should the tank model include?

Start with the level integration and the switch outputs only. Once the fill-and-drain cycle runs unattended, add disturbances a few counts at a time: noise on the analog level word, a level switch stuck at one state, or an extra leak term in the outflow. Each addition forces the control logic to handle a fault rather than only the nominal cycle.

What does the model block write back to the PLC?

It writes the same image real I/O would: the analog input word scaled to the simulator's counts-per-unit range, and the discrete level-switch bits at their thresholds. It must never write the output image; only the control logic drives the valves. Keeping that direction fixed makes a later swap to real I/O a wiring change rather than a program change.

Keep reading

  • Troubleshooting

    Why a pick-and-place rung needs sequence state, not one condition

    A rung that combines case detected AND conveyor running drives Robot Ready, Robot Pick and Robot Place on in the same scan, because a PLC re-evaluates the condition every pass. Split the transfer into stored steps that advance on robot acknowledgment and gripper or part-present feedback, hold each request until the robot accepts it, and prove the case with a sensor that detects the case material.

    PLC programming

  • How-to

    How to build ladder logic practice projects in STEP 7

    Get STEP 7 ladder practice projects from the vendor's own support portal and from the samples the installer already placed on your PC, not from a copy of a book's bundled disk. Then rebuild three circuits yourself: a start/stop latch with overload interlock, an on-delay timer sequence, and an up/down counter.

    PLC programming

  • Explainer

    Unity Pro system bits %S0 and %S1 for Grafcet startup initialization

    Unity Pro has no OB100: the hooks are the %S0 cold-restart and %S1 warm-restart system bits. Wire both in parallel on one rung, SET the initial Grafcet step bit and RESET every other step bit; for a native Grafcet chart call INITCHART from the same condition instead.

    PLC programming

What a browser PLC simulator can and cannot teach