IMDHMIControls LibraryShop main store

Troubleshooting

Why a smaller fixed step makes LibIsSampleHit unsupported

PLC programming Published 7 min read By IMDHMI controls team

Short answer

Reducing the model's fixed step below the Discrete Time Integrator's sample time turns the Controller subsystem into a 5:1 multirate model, and PLC Coder cannot schedule the LibIsSampleHit test that multirate execution needs. Set every block in the generated subsystem to one period, rerun Check Subsystem Compatibility, then compare the simulated controller response against a saved baseline before generating code.

On this page
  1. What does the LibIsSampleHit error actually tell you?
  2. Why does a smaller fixed step turn a passing model into a failing one?
  3. How do you align the sample times so the check passes?
  4. Which sample-time settings should you inspect before regenerating?
  5. How do you prove the corrected controller still controls?
  6. Which mistakes keep the LibIsSampleHit error coming back?
  7. Questions asked

The LibIsSampleHit error appears because shrinking the model's fixed step left the PID Controller's Discrete Time Integrator running five times slower than the base step: the Controller subsystem became a 5:1 multirate model, and PLC Coder cannot schedule the per-step hit test that multirate execution needs. Align the rates — restore the fixed step to 0.05 s to keep the demonstrated controller timing, or set the integrator sample time to 0.01 s to run the controller at the faster step — rerun Check Subsystem Compatibility, and compare the simulated response against a saved baseline before you generate code.

What does the LibIsSampleHit error actually tell you? #

It tells you that generated code would need LibIsSampleHit, a scheduling helper that tests whether a block is due to execute on the current step, and that the diagnostic names plcdemo_cruise_control/Controller/PID Controller as the block that needs it — it says nothing about your PID gains.

Read the diagnostic as a scheduling verdict, not a control verdict. PLC Coder translates a subsystem into logic that runs inside one PLC task, and when blocks in that subsystem execute at different rates, the translation machinery inserts the hit test so the slower block updates only on its own instants. The coder does not support emitting that function, so generation stops and names the block that triggered it.

Do not try to replace LibIsSampleHit with hand-written arithmetic. The function is internal scheduling machinery, not a control calculation, and a hand-built substitute sits outside everything the compatibility check covers.

Why does a smaller fixed step turn a passing model into a failing one? #

The Discrete Time Integrator keeps its 0.05 s sample time while the base step drops to 0.01 s, so the subsystem becomes multirate at a 5:1 ratio — one integrator update for every five base steps — and that schedule is exactly what PLC Coder cannot translate.

Work the rates out and the ratio falls straight out of the arithmetic:

  • Base rate: 1 / 0.01 s = 100 updates per second.
  • Integrator rate: 1 / 0.05 s = 20 updates per second.
  • 100 / 20 = 5, so the Discrete Time Integrator updates on one step in five and holds its stored state through the other four.

The scheduler has to tell the one update step apart from the four hold steps, and that distinction is the sample-hit requirement the checker reports. A faster base step does not make the integrator faster; it only multiplies the steps the scheduler has to classify.

The demo passed its check originally because both periods matched, and nothing about the controller logic changed when you edited the solver settings. The limitation is documented for R2010b, whose supported-feature list names multirate models, so commit to the single-rate architecture: it is what the checker accepts there, and it removes the scheduling question on any release.

How do you align the sample times so the check passes? #

Pick one period for the whole subsystem: restore the fixed step to 0.05 s to keep the demonstrated controller timing, or set the Discrete Time Integrator's sample time to 0.01 s to run the controller at the faster step — then rerun Check Subsystem Compatibility and read the full diagnostic list.

Which branch you take depends on the PLC task, not on the error: the generated code will be called at whatever period the task uses, so match the subsystem to that period and then work through this sequence.

  1. Save a baseline copy of the model and record its configuration — the demo opens with the Ode5 solver — together with the base step, the controller sample times, the gains and the initial conditions.
  2. Open the Controller subsystem and read the Discrete Time Integrator's sample time where it is actually set, rather than assuming it follows the solver dialog.
  3. Decide the intended PLC task period first, because every block in the generated subsystem should carry that one period.
  4. Change only the setting that creates the rate mismatch — the integrator sample time or the fixed step, never both at once — so the before-and-after comparison stays clean.
  5. Run Check Subsystem Compatibility on the Controller subsystem again and read the entire diagnostic list; clearing the sample-hit error does not clear unrelated restrictions.
  6. Generate code only after the check passes, then confirm the task that calls the generated function runs at the period you designed the subsystem for.

Which sample-time settings should you inspect before regenerating? #

Inspect six things before you regenerate: the speed reference, the measured-speed feedback, the controller output path, the fixed-step size, the Discrete Time Integrator's sample time, and the model's compiled sample-time display — one inherited or leftover rate anywhere reintroduces the multirate condition.

  • Speed reference — the signal entering the Controller subsystem; a wrong reference produces a correct-looking response aimed at the wrong target.
  • Measured speed — the feedback signal; a scaling or sign error distorts the control error and looks like poor tuning.
  • Controller output — the PID output and the command the plant model or final element receives; clipping or an unexpected hold hides timing effects.
  • Fixed-step size — in the solver configuration; this is the only setting you changed when the error appeared.
  • Discrete Time Integrator sample time — read it on the block inside the PID Controller, never infer it from the step.
  • Sample-time display — the model's compiled sample-time report; use it to find inherited or leftover rates anywhere inside the subsystem you generate from.

Integrators, filters and timer blocks all carry their period into the generated code, and the guide to using the PLC Coder timer block correctly in TIA Portal covers the timer side of that dependency.

How do you prove the corrected controller still controls? #

Run two acceptance tests: the compatibility check proves the subsystem is translatable, and a simulation comparison against the saved baseline proves the control response survived — compare measured speed, error, controller output and integrator state over identical intervals with identical references and initial states.

The timing correction is not behaviorally neutral. A discrete integrator adds its input multiplied by its own sample time at every update, so moving it to the faster period changes the discrete implementation even when every displayed gain is unchanged. Examine transient response, steady-state error, output limiting and any oscillation, and confirm from logged execution data — not from a visually smooth trend — that the integrator now updates on every base step.

A pass says nothing about closed-loop performance; the two verdicts come from different tests. And verify the command actually delivered to the plant interface, limits and hold behavior included: the actuator sees the controller output, not your solver settings.

On the target PLC, confirm the task period equals the period the subsystem was designed for; how generated code competes for time inside the task follows the same mechanics compared in the structured text versus function blocks scan-time article.

One safety note: generated code drives a real actuator, so give it the same verification you would give hand-written logic before it runs a machine — the checklist for verifying generated PLC code before you trust it fits this step exactly.

Which mistakes keep the LibIsSampleHit error coming back? #

The trap is changing only the solver: explicit block sample times stay where they are, so the subsystem still contains two rates after the step shrinks — correct the rate mismatch itself, and change one timing setting at a time so the before-and-after comparison stays readable.

  • Hand-gating the slower block with a counter rebuilds the multirate schedule the coder declined to generate, outside the toolchain the compatibility check describes.
  • Editing gains while chasing the error cannot help; the diagnostic is about scheduling, and no gain value clears a rate mismatch.
  • Changing several settings at once destroys the comparison; the failure followed one solver change, and only a single-variable change identifies causes.
  • Calling the generated function from a task at a period it was not designed for updates the discrete states at the wrong instants, even when the code compiles and transfers cleanly.

The decision, case by case: if the PLC task must run at the slower demonstrated period, restore the original fixed step and you are back to the configuration that passed; if the task must run at the faster period, set every block in the generated subsystem — the Discrete Time Integrator first — to that period, rerun the compatibility check, compare the simulated response against your baseline, and only then generate and transfer the code.

Questions asked

Why did the model simulate correctly at the smaller step if the timing is unsupported?

Simulink's solver schedules multiple rates natively, so simulation runs each block at its own instant and produces correct trends. Code generation faces a different constraint: the PLC target has one task period, and the coder must express every block rate against it. When it cannot, it reports the scheduling helper it would need, LibIsSampleHit, as unsupported. Simulation success and generation compatibility are independent tests.

Can I keep the slower integrator and call the generated controller only every fifth scan?

That rebuilds, outside the toolchain, exactly the multirate schedule the coder declined to generate: you would own the gating counter, and a compatibility pass would no longer describe the code you run. The supported architecture is one rate for the whole subsystem. If the process genuinely needs a slower loop, make that slower period the base step and generate the entire subsystem at it.

Does moving the integrator to the faster period change PID behavior with unchanged gains?

Yes. A discrete integrator adds its input multiplied by its own sample time at every update, so the period change alters the discrete implementation even when displayed gains are untouched. Compare error, controller output and integrator state traces between the baseline run and the corrected run; shifts in transient shape, settling or steady-state error tell you the loop response moved, not just the schedule.

What does the single-rate fix cost on the PLC?

The generated controller then executes on every scan of the task it is called from, so CPU load rises roughly in proportion to the rate increase you collapsed. Check the task's load margin after regeneration, and confirm the configured task period equals the period the subsystem was designed for before the code runs a live process.

Keep reading

  • Explainer

    How the PLC scan services NETRX and NETWX network reads and writes

    NETRX and NETWX never stall the ladder. The CPU services communications at the start of each scan and runs about one communication instruction per port per scan, so a one-scan pulse every second starts your six reads and writes but proves nothing about completion. Sequence the transfers on the port busy and comm-error SP bits and count completed cycles against the pulse count.

    PLC programming

  • Troubleshooting

    Use the PLC Coder timer block correctly in TIA Portal

    A Stateflow delay generated with PLC Coder follows wall-clock time only when the timing implementation and the PLC task call interval agree with the model sample time. Pick the target IDE timer for real elapsed time; use the Target-Independent Counter only when the generated code runs at a fixed periodic interval equal to the model step.

    PLC programming

  • Troubleshooting

    Why PLC Coder reports update diagram not possible with a clean model

    PLC Coder raises the update diagram not possible error because generation runs a stricter diagram update than your simulation: an input or output port on the subsystem selected for STEP 7 generation is unconnected, and that fault surfaces only as a warning. Trace both sides of the generation boundary, connect or deliberately terminate every port, rerun the generation, and read the newest attempt's diagnostics; a clean simulation is a separate check, not a clearance.

    PLC programming

Why STEP 7 V5.7 SP1 setup stops on Windows 10 Pro