MIL, SIL, PIL and HIL Testing in Model-Based Design: What Runs Where
The V-model of model-based design and its four in-the-loop stages explained by what runs where: plant model, controller model, generated C code, target processor and real-time simulator. With a reproducible MIL-vs-SIL experiment on a PI cruise controller (max difference 5.9 mm/s), what a back-to-back tolerance means, MC/DC and ISO 26262 context, a worked 1 ms HIL frame budget, and the MBD jobs in India that test this.

MIL, SIL, PIL and HIL are the four "in-the-loop" test stages of model-based design, and the cleanest way to tell them apart is to ask what runs where. In MIL (model in the loop) the controller model and the vehicle plant model both run in Simulink on your PC. In SIL (software in the loop) the controller is replaced by the C code generated from it, compiled for the PC. In PIL (processor in the loop) that C code is cross-compiled and runs on the real target microcontroller while the plant stays on the PC. In HIL (hardware in the loop) the production ECU, flashed with the final binary, is wired to a real-time simulator that runs the plant model at a fixed step such as 1 ms. Each stage keeps the same test cases and catches a different class of error: MIL finds algorithm mistakes, SIL finds code-generation and data-type mistakes, PIL finds compiler and timing mistakes, and HIL finds I/O, wiring and real-time mistakes.
This guide is for engineering students and MBD freshers who know the acronyms but have never seen the numbers. We walk the V-model, draw the four loop configurations, then run a MIL-vs-SIL experiment on a PI cruise controller in plain Python (no Simulink licence needed, script kept with the post) so you can see exactly how big the difference is and what a back-to-back tolerance means. We finish with MC/DC coverage, the ISO 26262 link, a worked 1 ms real-time budget for HIL, the tools, and who tests this in India. Part 1 and Part 2 of our ADAS series (the V-model and ISO 26262 overview, an ACC example from MIL to HIL) are the companions to this post.
In short: the numbers to remember (sources dated; our experiment run 30 Nov 2026)
- What runs where: MIL = model vs model on the host; SIL = generated code compiled for the host; PIL = code cross-compiled and run on the target processor; HIL = real ECU wired to a real-time plant simulator. SIL and PIL "do not run in real time" (MathWorks Embedded Coder docs, R2026b).
- MIL vs SIL on a PI cruise controller (20 to 25 m/s step, our script): the fixed-point 10 ms controller differs from the float64 MIL controller by at most 0.00586 m/s (5.86 mm/s), 2 % settling time 8.85 s vs 8.87 s, overshoot 4.79 % vs 4.87 %. Switching float64 to float32 changes the result by only 5.81 × 10⁻⁷ m/s: the discretisation, not the arithmetic, dominates.
- Tolerance: with Simulink Test's default of 0 for every tolerance, even that 5.86 mm/s is a FAIL; with an absolute tolerance of 10 mm/s plus 0.1 % relative, the worst point uses 24 % of the band and the test passes.
- Coverage: LDRA's reading of ISO 26262-6:2018 Table 9: MC/DC is "recommended" for ASIL A to C and "highly recommended" for ASIL D; a decision with n conditions needs at least n + 1 test cases for MC/DC.
- HIL real time: at a 1 ms step a 10-minute test is 600,000 steps; in our illustrative budget the frame uses 750 µs (75 %) and a single step of 1,180 µs is a 180 µs overrun. Simulink Real-Time's default overload limit is 0, so the first overrun halts the run (MathWorks docs, R2026b).
- Jobs: 25 Skill-Lync placements in the MBD domain, median 5.0 LPA, middle half 4.25 to 5.0 LPA (snapshot 15 Nov 2026, n = 25); Expleo Engineering is the top hirer in that group with 12.
What is the V-model in model-based design?
The V-model is the development picture every MBD team draws: requirements, system design and software design flow down the left leg to implementation at the bottom, and the right leg climbs back up through unit test, integration test and system validation. Each test level on the right verifies the design level directly opposite it on the left. In model-based design the "implementation" step is code generation from the controller model, and the four in-the-loop stages sit on the right leg: MIL, SIL and PIL at the unit level, HIL at the integration level.
Why does the shape matter? Because the model is the single artefact that flows through it. The same Simulink model that you simulate in MIL is the source for the C code you test in SIL and PIL, and the same plant model that closed the loop on your laptop is compiled for the real-time simulator in HIL. Requirements are linked to the model and the tests (Requirements Toolbox), the test cases are written once (Simulink Test) and re-run at every stage, and coverage is measured on the model and on the code (Simulink Coverage). The V-model is also the frame ISO 26262 uses for software development, which is why functional safety audits ask for evidence at each level; see our ISO 26262 explainer.
What runs where at MIL, SIL, PIL and HIL?
At every stage there are two halves: the controller (the thing you are building) and the plant (the vehicle, motor, battery or driver it controls). The stage name tells you what the controller half is made of, and the practical questions are which machine each half runs on, whether the clock is real time, and which errors can therefore show up.
| Stage | Controller half | Plant half | Clock | What it catches | What it cannot see |
|---|---|---|---|---|---|
| MIL model in the loop | Simulink model, usually double precision | Simulink model, same PC | Simulation time (as fast as the solver runs) | Wrong control law, wrong gains, missed requirement, logic holes in Stateflow, saturation and wind-up behaviour | Anything to do with code, data types, compilers or hardware |
| SIL software in the loop | C code generated from the model, compiled for the host PC | Simulink model, same PC | Not real time | Code-generation mistakes, fixed-point scaling and overflow, single vs double differences, uninitialised state, code coverage gaps | Target compiler behaviour, word length of the real CPU, execution time |
| PIL processor in the loop | Same C code cross-compiled for the target processor, running on an evaluation board or instruction-set simulator | Simulink model on the host, talking to the board over a debug or serial link | Not real time (the loop waits for the link) | Target-compiler differences, 16-bit vs 32-bit arithmetic, memory use, measured execution time per step | Real I/O, wiring, bus timing, the production board |
| HIL hardware in the loop | Production ECU running the flashed binary with its real sensor inputs and actuator outputs | Plant model compiled onto a real-time simulator with I/O boards, at a fixed step such as 1 ms | Hard real time | I/O scaling, wiring, CAN/LIN timing, diagnostics, fault injection (open circuits, shorts), task overruns, long-duration and regression runs | The physics the plant model does not include; real vehicle dynamics |
MathWorks' own definitions are the ones interviewers quote: "A SIL simulation compiles and runs the generated code on your development computer. A PIL simulation cross-compiles source code on your development computer, and then downloads and runs the object code on a target processor or an equivalent instruction set simulator." The same page lists what SIL and PIL are for: test whether model and generated code are numerically equivalent, observe code coverage, and profile code execution, and it warns that a SIL simulation "does not test code compiled for target hardware because code is compiled for the development computer" (Embedded Coder documentation, R2026b).
HIL is where the vendor wording changes, because the unit under test is now a physical box. dSPACE puts it plainly: "Hardware-in-the-loop (HIL) testing means the tests of real ECUs (electronic control units) in a realistic simulated environment," with the simulator reproducing the bus traffic of the other ECUs ("complete restbus simulation" over CAN FD, LIN, FlexRay and Automotive Ethernet) and injecting faults. The ECU cannot tell the difference between the simulator and the car, which is why a HIL rig can run a brake-failure test a thousand times overnight that no test driver would run once.
Worked example: a PI cruise controller, MIL vs SIL without a Simulink licence
The experiment that makes the acronyms concrete is a back-to-back run of the same controller in two forms. We built one in Python (script mil_vs_sil.py, kept with the post, runs in under a second). The plant is a first-order vehicle model: mass kg, a linearised drag-plus-rolling coefficient N per m/s (so the open-loop time constant is 20 s) and a traction force limited to 0 to 3,000 N:
The controller is a PI law on the speed error with the integrator clamped and a simple anti-wind-up rule (stop integrating while the output is saturated):
with N per m/s and N per m/s per second. On the linear plant this gives a closed-loop natural frequency rad/s and damping ratio . The test is a set-speed step from 20 to 25 m/s (72 to 90 km/h). You can play with the same kind of loop in our mass-spring-damper PID calculator.
The plant is always integrated the same way (fourth-order Runge-Kutta at 1 ms, double precision), so every difference you see comes from the controller. Three controller builds drive it:
- MIL: the controller in double precision, evaluated at every 1 ms plant step. This is the "continuous" controller model you would simulate in Simulink.
- SIL, float32: the controller discretised at a 10 ms sample time with a zero-order hold on its output, arithmetic in single precision, which is what Embedded Coder would generate if you set the data types to
single. - SIL, fixed-point: the same 10 ms controller in integer arithmetic the way a cost-optimised ECU would run it: speed as a 16-bit Q8.8 number (1 LSB = 1/256 = 0.0039 m/s), the integrator state as a 32-bit Q16.16 number in newtons, gains as scaled integers, and the output saturated to a 16-bit force in newtons.
The script prints the comparison. Copied exactly:
MIL float64 continuous 2% settling 8.87 s | overshoot 4.87 % | saturated 6.9 % of time
SIL-f float32 Ts=10 ms 2% settling 8.85 s | overshoot 4.79 % | saturated 7.0 % of time
SIL-q fixed-point Ts=10 ms 2% settling 8.85 s | overshoot 4.79 % | saturated 7.0 % of time
Back-to-back comparison against MIL (speed signal, 20 s, 1 ms grid):
SIL-f float32 Ts=10 ms max |dv| = 0.00518 m/s at t = 4.055 s | rms 0.00232 m/s
SIL-q fixed-point Ts=10 ms max |dv| = 0.00586 m/s at t = 3.828 s | rms 0.00257 m/s
SIL-f vs SIL-d (float32 effect only) max |dv| = 5.81e-07 m/s
Three things worth reading off those lines. First, the responses are the same for any practical purpose: settling time within 20 ms, overshoot within 0.1 percentage points. Second, the largest difference, 5.86 mm/s, happens at 3.8 s, while the controller is coming out of saturation, not at steady state; that is typical, because discretisation and quantisation errors are largest where the signals change fastest. Third, float32 alone is invisible (5.81 × 10⁻⁷ m/s): the 5.18 mm/s between MIL and the float32 SIL build is almost entirely the 10 ms sample time and the zero-order hold, and the extra 0.68 mm/s in the fixed-point build is the Q8.8 quantisation of the speed signal. A 10 ms controller cannot react to what happened in the last 9 ms, so it lags the 1 ms MIL controller: the first crossing of 24.9 m/s comes at 4.353 s in MIL and 4.367 s in the fixed-point SIL build, a 14 ms lag.
Fixed-point conversion can also bite through coefficient rounding, which this particular gain set happens to avoid. With and s the integrator coefficient N per m/s scales to exactly 1,280 in our Q-format. Had the gains been , the coefficient 0.4 would be stored as 102/256 = 0.3984, 0.39 % low, and the integrator would be slightly slower than the model for ever. SIL is the stage that catches this; MIL cannot, because MIL never sees the integer.
What does a back-to-back test tolerance mean?
A back-to-back (equivalence) test runs the same inputs through two versions of the controller and passes only if every output sample agrees within a stated tolerance. Simulink Test's documentation describes it as testing "whether the generated code produces the same results as the model simulation", typically Normal mode against SIL, and warns that differences can come from "numerical differences, such as differences in tolerances when comparing floating-point values. Time delays or compiler issues might also cause differences." The tolerances you can set are relative, absolute, leading and lagging, and "each default tolerance is 0" (Simulink Test docs, R2026b).
A tolerance of zero means bit-for-bit identical, which a float64 model and a fixed-point build will never be, so the first job of the test engineer is to argue for a band. The criterion we apply in the script is the common form of an absolute-plus-relative band (our formulation; the Simulink page that gives MathWorks' exact combination is linked from their "Set Signal Tolerances" page):
where . With absTol = 0.01 m/s and relTol = 0.001 the band is 20 to 25 mm/s wide across this run (the relative term dominates at these speeds). Both SIL builds pass with the worst sample using 21 % (float32) and 24 % (fixed-point) of the band, which is the kind of margin you want: a tolerance a build only just scrapes through is a tolerance that will fail on the next gain change. The leading and lagging tolerances are in seconds and exist for exactly the lag we measured: if a signal crosses a threshold 14 ms late because of the sample time, a 20 ms lagging tolerance lets you compare the shapes instead of failing on the phase.
What should the band be in a real project? It is a requirement, not a preference: it comes from what the downstream function can tolerate (a 0.1 % speed error is irrelevant to cruise control but a 0.1 % current-sensor scaling error may matter to a battery management system), and it is written into the test specification before anyone looks at the results. A back-to-back test that passes because someone widened the tolerance after seeing a failure is worthless as safety evidence. Our adaptive cruise control walkthrough shows how such test cases are written from requirements.
What is MC/DC coverage, and what does ISO 26262 ask for?
MC/DC (modified condition/decision coverage) is the strictest structural coverage metric used in automotive and aerospace software. It is satisfied when every decision in the code has been tested so that each condition inside it has "been shown to independently affect that decision's outcome" (LDRA). For a decision with n Boolean conditions this needs at least n + 1 test cases, far fewer than the 2ⁿ of exhaustive testing. For if (brake_pressed && speed > 5 && !fault) you need four cases, each flipping one condition while the others are held at values that let the flip change the result. Simulink Coverage measures MC/DC on the model (a block achieves it "when a change in one input, independent of any other inputs, causes a change in the block output") and the same metric is collected on the generated code in SIL and PIL runs (MathWorks docs, R2026b).
Where does ISO 26262 come in? Part 6 (software) of the 2018 edition requires structural coverage at the software unit level to be measured against the metrics in its Table 9: statement, branch and MC/DC coverage, with the required strength rising with the ASIL. LDRA, whose tools are used for the measurement, summarise the MC/DC row as "recommended" for ASIL A to C and "highly recommended" for ASIL D. In practice that means an ASIL D unit (a brake-by-wire arbiter, say) needs MC/DC evidence on the code, and the SIL or PIL run is where that evidence is generated, because it executes the real C code with instrumentation. The standard also expects the code to be shown equivalent to the model it came from, which is why the back-to-back test above is not an optional nicety on a safety project. MathWorks ships an IEC Certification Kit (separate licence) that references ISO 26262-6, IEC 61508-3 and other standards for exactly this tool chain; Embedded Coder's product page lists support for ISO 26262, IEC 61508 and DO-178 development and for MISRA C and AUTOSAR. How ASILs are assigned in the first place is in our ISO 26262 post.
What is the real-time constraint in HIL? A 1 ms worked budget
The thing that separates HIL from the three stages before it is the clock. SIL and PIL run as fast or as slow as the host and the debug link allow; the ECU on a HIL rig does not wait for anyone. If the simulator computes the plant at a 1 ms step, then every millisecond it must read the ECU's outputs (PWM duty cycles, CAN frames, digital pins), advance the plant model one step, write the new sensor voltages and CAN messages back, and log, all before the next tick. MathWorks' definition of the failure case is exact: "A CPU overload indicates that the CPU is unable to complete processing a model time step before restarting for the next time step" (Simulink Real-Time docs, R2026b).
Put numbers on it (ours, illustrative): reading the I/O boards takes 80 µs, the plant model step 520 µs, writing outputs 60 µs and logging 90 µs. The task execution time (TET) is 750 µs, 75 % of the frame, leaving 250 µs of headroom. A 10-minute drive-cycle test is 600,000 such frames and every one of them must fit. Now suppose one plant step hits a slow path (a lookup table interpolation at a corner, a solver iteration that needs an extra pass, an I/O call that blocks) and takes 950 µs: the TET becomes 1,180 µs, 180 µs past the tick. That is an overrun. On Simulink Real-Time the default overload limit is 0, so the real-time OS halts the application and reports it, for example "Overload limit (0) exceeded in 0.02s rate with 1 overloads"; the docs let you raise the limit with an Overload Options block but say that is for diagnosis, not for running tests. If you did let it continue, "the time step lasts as long as the time required to finish the execution", so the ECU would receive its next sensor update late and your test would be measuring the simulator, not the ECU.
This is why HIL teams spend so much time on the plant model: it must be good enough physics to fool the ECU yet cheap enough to finish in a fraction of a millisecond, every time, with no variable-step solver. It is also why PIL profiling matters before HIL: MathWorks says SIL profiling on the host "can give an indication about performance trends" while "you get more accurate results with PIL profiling", and that is how you learn the controller's own TET before you put it on a bench. Faster physics, such as switching-level power electronics, moves to FPGA: Simulink Real-Time's product page offers "higher sample rates with FPGA hardware and HDL Coder" on Speedgoat machines, and dSPACE describes SCALEXIO's I/O as FPGA-based.
Which tools do companies use for MIL, SIL, PIL and HIL?
Most Indian automotive MBD teams run the MathWorks chain for MIL to PIL and one of two HIL ecosystems. From the vendors' own pages (read 30 Nov 2026):
| Stage | Tool | What the vendor says it does |
|---|---|---|
| MIL | MATLAB, Simulink, Stateflow; Simulink Test; Simulink Coverage; Requirements Toolbox | Model, simulate, write and manage test cases, measure model coverage (execution, decision, condition, MC/DC, lookup-table, signal-range and more), link requirements to model and tests. Data management across the model set is handled by the Simulink data dictionary. |
| SIL / PIL | Embedded Coder (with Simulink Coder) | Generates "readable, compact, and fast C and C++ code for embedded processors used in mass production", with "built-in support for AUTOSAR, MISRA C, and ASAP2"; runs SIL and PIL simulations, numerical equivalence tests, code coverage and execution-time profiling (R2026b). |
| HIL | Simulink Real-Time on Speedgoat target computers | "Simulink Real-Time and Speedgoat take you from simulation to rapid control prototyping (RCP) and hardware-in-the-loop (HIL) testing in a single click"; I/O for CAN, EtherCAT, Modbus, ARINC, SPI; Simulink Test cases written for MIL and SIL move to HIL execution on the same hardware. |
| HIL | dSPACE SCALEXIO | "A modular and scalable real-time platform" for ECU validation; signal-level and power-level HIL, rapid control prototyping and mechanical test benches; FPGA-based I/O; FMI support for third-party models; LabBox, off-the-shelf and turnkey system variants. |
| HIL | NI VeriStand on PXI / CompactRIO | "Real-time testing software for configuring and deploying hardware-in-the-loop (HIL) systems"; runs compiled Simulink models, LabVIEW models, FMUs and C/C++ code on "NI PXI and CompactRIO targets running NI Linux Real-Time". |
Two practical notes. Vendor pages are light on hard numbers (none of the three HIL pages states a guaranteed minimum step size), so a HIL engineer sizes the rig by measuring the plant model's TET on the actual target, which is the budget exercise above. And the HIL rig is also where the ECU's diagnostics are exercised, because the simulator can send the same requests a workshop tester would; see our UDS (ISO 14229) byte-level explainer. As vehicles move to zonal controllers and over-the-air updates, the same four stages are being applied to much larger software stacks, which we cover in what a software-defined vehicle is.
Who tests this in India, and what are MBD freshers offered?
In India the MIL-to-HIL workflow is day-to-day work at engineering service providers and automotive suppliers that build and validate ECU software for OEMs. A fresher's role is usually "MBD engineer" or "MBD / controls engineer": building Simulink models from requirements, writing Simulink Test cases, running MIL and SIL back-to-back comparisons, checking modelling guidelines, and reporting coverage. HIL bench work (dSPACE or NI) is often a separate validation role, and a common next step for an MBD engineer.
Skill-Lync's own placement records give a picture of the entry point. Based on 3,711 Skill-Lync placement records up to 7 Nov 2026 (data snapshot of 15 Nov 2026), the 25 placements filed under the MBD domain had a median offer of 5.0 LPA, a middle half of 4.25 to 5.0 LPA and a 90th percentile of 6.1 LPA (n = 25). Expleo Engineering is the largest hirer in that group with 12 placements at a median of 5.0 LPA. Across all domains, the "MBD / Controls Engineer" job title appears 118 times with a median of 3.5 LPA and a 75th percentile of 4.28 LPA (n = 118), which shows how much the offer depends on the employer. Caveats, in plain words: this is a self-selected sample of Skill-Lync learners who reported a placement, mostly starting offers, most of them from 2021 to 2023, and groups under 10 people are not shown. The full breakdown by employer and year, with the same caveats, is on our MBD engineer salary page.
If you want to build the skills in the order the V-model uses them: Introduction to Model-Based Development using MATLAB and Simulink covers modelling and MIL, Software Verification, Validation and System Testing for Model-Based Development covers the test side (MIL, SIL, back-to-back, coverage), Introduction to the Future of Vehicle Validation - ADAS covers HIL and vehicle validation, and Automotive Systems and Controls using MATLAB/Simulink covers the control design that the experiment above only touches.
Frequently asked questions
What is the difference between MIL, SIL, PIL and HIL in one line each?
MIL: controller model vs plant model, both in simulation. SIL: the generated C code, compiled for your PC, vs the plant model. PIL: the same code running on the real target processor, plant model still on the PC. HIL: the real ECU wired to a real-time simulator that runs the plant model. Each adds one piece of reality and keeps the same tests.
Do I have to do all four stages?
On a safety-relevant project, yes: SIL or PIL provides the code coverage and model-to-code equivalence evidence ISO 26262-6 asks for, and HIL is where the integrated ECU is validated before a vehicle. MathWorks notes that PIL is needed for full compliance because SIL does not test code compiled for the target. On a student project, MIL plus SIL already teaches most of the lessons, including fixed-point effects.
Why does the SIL result differ from MIL if the code was generated automatically?
Because the code is discrete and the model usually is not. In our experiment the 10 ms sample time and zero-order hold accounted for about 5.2 of the 5.9 mm/s maximum difference; the fixed-point quantisation added the rest; float32 arithmetic contributed under a millionth of a metre per second. Differences larger than that usually mean a data-type or scaling mistake, which is exactly what SIL is for.
What is a sensible back-to-back tolerance?
The one the downstream function can live with, written down before the test. Simulink Test's defaults are 0 for all four tolerances; for our cruise controller 10 mm/s absolute plus 0.1 % relative left both builds using under a quarter of the band. For a safety signal the tolerance is derived from the requirement, and a 20 ms lagging tolerance can be justified by the sample time rather than guessed.
What happens if the HIL simulator overruns?
The step did not finish before the next tick, so the ECU's inputs arrive late and the test is no longer testing the ECU. Simulink Real-Time halts the application by default (overload limit 0) and reports the rate and count; you then speed up the plant model, raise the step size, or move the fast physics to an FPGA. Allowing overruns is a diagnostic setting, not a way to pass a test.
Can I practise MIL and SIL without a MATLAB licence?
Yes. The Python script with this post reproduces the whole MIL-vs-SIL comparison, including a fixed-point controller, in under a second, and our ACC walkthrough shows the same ideas inside Simulink Test for when you do have a licence.
Sources and further reading
- MathWorks, SIL and PIL Simulations, Embedded Coder documentation, R2026b (read 30 Nov 2026).
- MathWorks, Back-to-Back Equivalence Testing, Simulink Test documentation, R2026b.
- MathWorks, Set Signal Tolerances, Simulink Test documentation, R2026b.
- MathWorks, Compare Simulation Data, Simulink documentation, R2026b.
- MathWorks, Types of Model Coverage, Simulink Coverage documentation, R2026b.
- MathWorks, Execution-Time Profiling for Generated Code, Embedded Coder documentation, R2026b.
- MathWorks, Troubleshoot Overloaded CPU from Executing Real-Time Application, Simulink Real-Time documentation, R2026b.
- MathWorks, Apply Real-Time Simulation and Testing Operations, Simulink Real-Time documentation, R2026b.
- MathWorks, Simulink Real-Time and Embedded Coder product pages (read 30 Nov 2026).
- dSPACE, SCALEXIO and HIL Testing for Electronic Control Units (read 30 Nov 2026).
- NI, What Is VeriStand? (read 30 Nov 2026).
- LDRA, MC/DC coverage and ISO 26262 capability pages (read 30 Nov 2026).
- Hayhurst, Veerhusen, Chilenski and Rierson, A Practical Tutorial on Modified Condition/Decision Coverage, NASA/TM-2001-210876, May 2001.
- Skill-Lync placement records, snapshot 15 Nov 2026 (placements up to 7 Nov 2026, 3,711 records with salary); summary on the MBD engineer salary page.
- Our MIL-vs-SIL script
mil_vs_sil.pyand its printout, kept in the post's run folder (Skill-Lync Engineering Desk, 30 Nov 2026).


