5.5.22 · D5Embedded Systems & Real-Time Software

Question bank — Software-in-the-Loop (SIL) simulation — all software, simulated hardware

1,628 words7 min readBack to topic

True or false — justify

Is SIL "hardware-free" because no chip is present?
False in spirit — the target microcontroller is absent, but SIL still models the hardware's behaviour (dynamics, limits). No physical part, but the hardware's role is very much simulated.
The software under test knows it is running in a simulation.
False — a core SIL property is that the code is unaware; it calls the same HAL functions and receives numbers, so it "thinks" it is driving real hardware. That obliviousness is what makes the test faithful.
Passing SIL proves the code is bug-free.
False — SIL only exercises what you modelled. Unmodelled effects (ADC delay, EMI spikes, voltage sag, timing jitter) are invisible, so SIL proves logical correctness only, never real-world survival.
SIL is a replacement for Hardware-in-the-Loop (HIL).
False — they answer different questions. SIL asks "is my algorithm logically right?"; HIL asks "does it survive real I/O timing and electrical reality?" SIL comes first and cheaper; HIL cannot be skipped.
A higher-fidelity plant model is always the better choice for SIL.
False — a low-fidelity linear model runs faster and still catches unit, polarity, and sign errors. Fidelity should be just enough to invalidate bad software; excess fidelity costs speed and dev time for no extra bug-catching.
The plant model must be numerically accurate to be useful.
False — you need enough realism to fail bad software, not perfect physics. A bug giving 10% overshoot in a crude model would give more on real hardware; SIL flags it either way.
SIL and Unit Testing for Embedded Systems are the same activity.
False — unit tests check isolated functions against fixed expected outputs; SIL runs the whole controller closed-loop against an evolving plant, catching feedback-and-timing bugs a static unit test never sees.
Because SIL is all software, it always runs faster than real time.
False — if is tiny (needed for stiff dynamics), the simulation can run slower than real time, defeating the rapid-iteration purpose. Speed depends on the solver and step size, not on "software" alone.
Reducing can never make a simulation worse.
False — shrinking improves accuracy but slows the run, and past a point buys negligible accuracy. Too large a causes divergence; the goal is the sweet spot, not the smallest value.

Spot the error

"We used the same C algorithm code in SIL and on the MCU, so the HAL doesn't matter."
The error: the HAL is exactly why the same core logic can compile for both. In SIL the HAL routes to the plant model; on the MCU it maps to memory-mapped I/O. Swapping only the HAL is the whole trick.
"Our plant model uses Gaussian sensor noise, so we've covered noisy inputs."
The error: real noise has outliers (EMI spikes), not just clean Gaussian scatter. A bug that crashes on one wild reading stays hidden — this is an abstraction error, not a fixable numeric detail.
"SIL failed to reproduce a motor vibration, so SIL is broken."
The error: SIL isn't broken — the model omitted cogging torque ( ignored it). This is model error: SIL can only catch effects you chose to represent.
"We saw oscillation only on real hardware; SIL must have been run wrong."
The error: the real ADC had a 2-cycle conversion delay feeding stale data to the loop; SIL never modelled that latency. The tool was fine — the timing abstraction was incomplete.
"Euler and RK4 give the same answer, so we always pick Euler for speed."
The error: Euler carries local error and can miss fast transients or diverge; RK4 is more accurate per step. They agree only when is small enough for your dynamics — not universally.
"Our controller runs at 100 Hz, so we simulate the plant only at 100 Hz too."
The error: the real plant evolves continuously; sampling it only at controller ticks can alias fast dynamics with time constants under 10 ms. The plant often needs finer internal integration than the control rate.
"We only integrated a sensor-fusion module in SIL, so field behaviour is guaranteed."
The error: SIL validates the fusion logic against modelled sensor streams, but real multi-sensor drift, dropout, and clock skew are abstraction gaps. SIL is necessary, not sufficient, for deployment confidence.

Why questions

Why call it "in-the-loop" rather than just "software test"?
Because the software is closed-loop with the model: its outputs feed back into the plant, which produces the next inputs. It's a feedback cycle, not a one-shot input/output check.
Why must the plant be discretized in SIL when the real physics is continuous?
The digital controller only acts at discrete instants (), and a computer can only advance the plant in finite steps (). Discretization is how continuous physics is stepped forward on a finite machine.
Why is fixing a bug in SIL so much cheaper than fixing it in the field?
Later stages add irreversibility (PCBs, deployed units) and coordination overhead (manufacturing, recalls). SIL fixes are just "edit code, recompile, re-run" — minutes, no physical artifacts, hence the exponential cost curve.
Why separate core logic from the HAL at all?
So one portable y = f(x, state) compiles unchanged for both host and target; only the thin HAL implementation swaps. Without the split you'd rewrite hardware-touching logic for every platform.
Why does the Real-Time Operating Systems (RTOS) scheduling behaviour often not show up in SIL?
SIL typically models data flow and idealised timing, not real task preemption, priority inversion, or jitter under an RTOS. Those are runtime scheduling effects that need PIL/HIL on real silicon to expose.
Why is SIL described as "necessary but not sufficient"?
Necessary: it catches algorithm/logic bugs earliest and cheapest. Not sufficient: prediction error also includes model, discretization, and abstraction gaps, so passing SIL cannot certify real-world robustness alone.
Why intercept HAL calls rather than modify the algorithm to read the model directly?
Interception keeps the algorithm byte-identical to production. If you edited the algorithm to talk to the model, you'd be testing different code than you ship — invalidating the whole exercise.

Edge cases

What happens at the very first tick, , before any plant update?
The plant must be initialised to a defined starting state (e.g. speed and distance) before the software's first read; an uninitialised or garbage initial state makes the whole closed-loop run meaningless from line one.
What if is set so large the simulated state grows without bound?
That's numerical instability (divergence): the solver amplifies error each step. It's a simulation artifact, not a real controller failure — you must shrink or use a stabler solver like RK4 before trusting results.
What if the plant model has a time constant much shorter than ?
The fast transient lives and dies between controller samples and gets aliased or missed. You need finer internal plant integration (sub-stepping) than the control period, or SIL will silently hide those dynamics.
What does SIL say about a bug that only triggers on a single corrupt sensor reading?
Usually nothing — if your noise model has no outliers, that code path is never exercised. This is a classic abstraction-error blind spot; add fault-injection or move to HIL to reach it.
What is the limiting behaviour as plant fidelity increases toward "perfect"?
Model error shrinks toward zero, but simulation cost rises and you still carry discretization and abstraction error. The prediction error is floored by those, so "perfect plant" never buys "perfect prediction."
What if a saturation limit (e.g. max_rpm) is omitted from the plant model?
Then controller pathologies that only appear under saturation — like integrator windup — stay hidden, because the simulated actuator never hits its ceiling. High-fidelity models add these limits precisely to expose such bugs.
If SIL and HIL disagree on the same scenario, which is "right"?
Neither is automatically right — the disagreement localises the gap. HIL includes real I/O and timing SIL abstracted away, so the mismatch tells you which unmodelled effect matters and must be added or accepted.