Hardware-in-the-loop testing

Hardware-in-the-loop testing

How a real controller is connected to a real-time simulation of the machine it will control, so its software can be tested safely and repeatably before the real hardware exists.

What it is

Hardware-in-the-loop (HIL) testing connects a real embedded controller, such as an engine control unit, a battery management system, a flight computer or a motor drive, to a real-time computer that simulates the plant the controller will control. The controller “thinks” it is operating the real machine: it reads simulated sensor signals and sends actuator commands, and the simulator responds with the resulting behavior, updated many thousands of times per second. Because the plant is simulated, tests can include dangerous or rare conditions (sensor faults, short circuits, extreme weather, crashes) without risk or damage, and they can be automated and repeated exactly. HIL is standard in automotive, aerospace, rail, power electronics and robotics.

It answers questions such as: Does the controller software behave correctly across thousands of operating cases? How does it respond to sensor failures or a wire short? Does it meet timing requirements? Does it pass regression tests after a software update? HIL sits between pure simulation and testing on the real system, finding faults early when changes are cheap.

Fundamentals

Where HIL fits: the X-in-the-loop family

In the V-model of development, testing is done in stages. Model-in-the-loop (MIL) tests the controller model against the plant model in simulation; software-in-the-loop (SIL) runs the generated controller code on a PC with the plant model; processor-in-the-loop (PIL) runs the code on the target processor; hardware-in-the-loop (HIL) runs the final controller hardware and software against a real-time simulation; and vehicle- or system-in-the-loop tests with real mechanical parts. At each stage more reality is included, and faults are found at lower cost earlier. Power hardware-in-the-loop (PHIL) adds a power amplifier so real power flows between the device under test and the simulation, which is used for inverters, motors and batteries; controller HIL (CHIL) uses only low-level signals.

Architecture of a HIL system

  • Real-time simulator: a computer running a plant model with a fixed time step and deterministic execution (dSPACE SCALEXIO, NI/VeriStand, OPAL-RT, Speedgoat, Typhoon HIL, or Simulink Real-Time). The model must finish every step within the step time (for example, 1 ms for vehicle dynamics and about 1 µs or less for power electronics, which may need FPGA solvers).
  • I/O interfaces: analog outputs to mimic sensors, analog and digital inputs for actuator signals, PWM capture, encoders, and communication buses (CAN, LIN, FlexRay, Ethernet, SPI).
  • Signal conditioning and load simulation: circuits that scale voltages and currents, and electronic loads that imitate solenoids, injectors or motors so the controller sees realistic loads.
  • Fault insertion unit (FIU): switches that create open circuits, shorts to ground or battery and cross-connections on the wiring.
  • Test automation software: scripts, test sequencers and requirement-based test management, with data logging.

Real-time behavior and plant models

The plant model is typically a set of differential equations, such as an engine or vehicle dynamics model, a battery model (equivalent circuit with open-circuit voltage and RC pairs, V = Voc − I R0 − Σ VRC), a power converter model or a flight model. It is discretized with a fixed-step solver, for example forward Euler, xk+1 = xk + Δt · f(xk, uk), where the step size must be small compared with the fastest dynamics (a rule of thumb is at least ten steps per the shortest time constant or period) while model complexity must allow completion in real time. A step that misses its deadline is an overrun, which breaks the test. Tradeoffs between model fidelity and speed are managed through reduced-order models, lookup tables and multi-rate partitioning, with fast parts on FPGAs. The I/O loop adds latency (sampling, computation and output delay), which must be small compared with the controller’s own period. Model validation against measurements from the real plant is essential, since a controller tuned on a poor model gives false confidence.

Test design and standards

Tests derive from requirements: nominal operation, boundary values, diagnostic coverage (injected faults should trigger the right error codes and safe states), and timing behavior. Scenario-based tests include driving cycles and grid disturbances. Test cases are automated and run overnight in regression, and results are traced to requirements. Functional safety standards such as ISO 26262 (automotive), DO-178C and DO-254 (airborne software and hardware), IEC 61508 and IEC 62304 expect verification at hardware and system level, where HIL is a recognized method. Limits include cost of the equipment, effort to develop and validate plant models, the fact that a simulated plant cannot represent all real-world effects (wear, electromagnetic interference, mechanical noise), and I/O latency. Real tests remain needed at the end.

Typical applications and limits

Applications include engine and transmission controllers, ADAS and autonomous driving functions, battery and charger systems, grid inverters and protection relays, flight control and satellite attitude control computers, and medical devices such as insulin pumps.

Basic operation

  1. Define test goals. Choose requirements and fault cases to verify and the needed model fidelity.
  2. Build the plant model. Develop and validate a model of sensors, actuators and the plant.
  3. Configure the simulator. Set the fixed step size, map I/O channels and compile the model to the real-time target.
  4. Connect the controller. Wire the real controller through signal conditioning, loads and the fault insertion unit.
  5. Check timing. Run a dry test and confirm that no overruns occur and latency is acceptable.
  6. Run test sequences. Execute automated nominal and fault scenarios and log signals.
  7. Evaluate results. Compare measured behavior with pass/fail criteria and requirements.
  8. Collect the output. You obtain test reports and logged data; scenario design and automation are covered in the video.

Good practice

  • Validate the plant model. Compare it with measured data before trusting results.
  • Monitor real-time performance. Watch for overruns and keep margin on step time.
  • Automate and version tests. Keep scripts and configurations under version control.
  • Test faults systematically. Cover sensors, wiring and communication failures.
  • Trace tests to requirements. Keep a record of coverage.
  • Observe electrical safety. Use proper isolation, current limits and emergency stops when handling battery packs, high-voltage and power-hardware setups, and follow site safety rules.

Key terms

  • Real-time simulation — a simulation that finishes each time step within the real step duration.
  • Plant model — the model of the physical system being controlled.
  • Fault insertion — deliberately creating electrical faults to test controller diagnostics.
  • Overrun — a time step that takes longer than allowed.
  • PHIL — power hardware-in-the-loop, exchanging real power with the simulation.
  • SIL / PIL — software-in-the-loop and processor-in-the-loop, earlier test stages.
  • Regression test — a repeated test run to check that changes caused no new faults.

Video coming soon

About five minutes on Hardware-in-the-loop testing: how it works in detail, how the data is acquired, and how it is analyzed.

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping