Hardware-in-the-Loop (HIL) Testing: How It Works, With a Real BMS Example

Hardware-in-the-loop test bench with real-time simulator and BMS boards
In this article

Cet article existe aussi en français. Lire en français →

Hardware-in-the-loop (HIL) testing connects a real controller — the hardware and software that will ship — to a real-time simulator that pretends to be everything around it: the battery, the motor, the vehicle, the other ECUs. The controller cannot tell the difference. It reads simulated sensors, drives simulated actuators, and the simulator answers in real time.

For four years I specified, commissioned and ran a dSPACE SCALEXIO HIL bench for battery management systems, with real BMS boards in the loop for a rail validation campaign. Here is how HIL works, and what it is really good for.

In short

  • HIL tests the real controller against a simulated plant, in closed loop and in real time.
  • It sits between software-in-the-loop and testing on the real system in the V-cycle.
  • Its main value is fault testing: things you cannot or should not do on a real high-voltage battery.
  • Fast physics (power electronics) runs on FPGA with microsecond steps; slower models run on CPU.
  • A HIL bench is only as good as its models, its I/O accuracy and its test automation.

HIL in the V-cycle: MIL, SIL, PIL, HIL

StageControllerPlantWhat it catches
MIL — model in the loopModelModelAlgorithm and requirement errors, early
SIL — software in the loopCompiled code on a PCModelCode generation and integration errors
PIL — processor in the loopCode on the target processorModelTiming and numerical issues on the real chip
HIL — hardware in the loopReal ECU, real softwareReal-time modelHardware, I/O, timing, diagnostics, fault handling
System testReal ECUReal systemFinal validation — expensive, slow, limited in faults

How a HIL bench works

Hardware-in-the-loop bench for a battery management systemTest automationsequences · fault scenarios · reportsReal-time simulatorBattery & cell models (CPU)Converter model (FPGA, µs step)Load / vehicle profileRestbus: CAN nodesI/O & emulationCell voltage emulatorsTemperature sensorsCurrent signalDigital I/O · CANFault insertionopen · short · driftDevice under testReal BMS boardsmaster + cell monitoring unitsproduction hardwareproduction softwareclosed loop, in real time
A BMS HIL bench: the real boards see emulated cells, sensors and CAN traffic; the simulator closes the loop in real time.

The real-time simulator

The simulator runs the plant model with a fixed time step and a hard deadline: every step must finish on time, every time. Battery and thermal models are slow enough to run on a CPU at a millisecond or sub-millisecond step. Switching power electronics is not: a converter model needs microsecond steps, which is why it runs on an FPGA. On my bench the battery model ran on CPU and the power converter on FPGA at 0.5 µs.

I/O and emulation

This is where most of the cost and most of the problems live. For a BMS, the bench needs precise cell voltage emulators — one programmable source per cell, accurate to the millivolt — plus emulated temperature sensors, the current-sensor signal, digital inputs and outputs, and a restbus simulation that plays the role of every other node on the CAN networks.

Fault insertion

A fault insertion unit sits between the I/O and the device under test. On command it opens a wire, shorts it to ground or to battery, or adds a resistance. This is how you prove that the BMS detects a broken sense wire or a drifting sensor — reproducibly, and without touching a real pack.

Test automation

Tests are written as sequences in tools such as dSPACE AutomationDesk, NI TestStand or Python, linked to requirements, and run unattended: nominal cases, fault cases and full non-regression campaigns overnight on every new software release.

Example: validating a BMS on HIL

A typical BMS campaign on HIL covers:

  • Measurement: cell voltages and temperatures read back against the emulated values, across the full range.
  • Protections: every threshold and every reaction time — over-voltage, under-voltage, over-current, temperature — with the expected graded response.
  • Contactor sequences: precharge, closing, opening, and what happens with a welded or slow contactor.
  • Estimation: SOC and SOP under realistic load profiles, including long drives that expose current-sensor drift.
  • Communication faults: lost frames, bus-off, a silent node, wrong values from another controller.
  • Combined faults: the cases that matter for safety, such as a sensor failure during a cold charge.

More on what the BMS itself has to do in the battery management system guide.

HIL vs PHIL

Classic HIL exchanges signals with the device under test. Power hardware-in-the-loop (PHIL) exchanges real power: a power amplifier or a regenerative source reproduces the simulated voltages and currents at full scale, so a real converter, charger or battery can be tested. PHIL is more representative and much harder to keep stable and safe. Use it when the power stage itself is under test; use signal-level HIL for control and protection logic.

What a HIL bench really costs

The purchase order is the visible part. The real cost is in the specification, the harness, the models, the calibration and the test library. A bench delivered on time but with unvalidated models produces results nobody should sign off. Budget engineering time for model validation against real measurements, and for the first months of test automation — that is where the return comes from.

Common HIL mistakes

  • Using plant models that were never compared with measurements on real hardware.
  • Ignoring I/O latency and accuracy, then debugging “software bugs” that are bench artefacts.
  • Designing the harness last, as an afterthought.
  • Running tests manually, so non-regression never happens in practice.
  • Measuring success in number of tests instead of requirement and fault coverage.

FAQ

What is HIL testing?

Testing a real controller — its hardware and production software — against a real-time simulation of the system it controls, in closed loop.

What is the difference between HIL and SIL?

In software-in-the-loop, the control software runs on a PC against a model. In hardware-in-the-loop, it runs on the real controller, with real I/O, against a real-time model.

Is dSPACE the only HIL option?

No. dSPACE, NI, Speedgoat, OPAL-RT, Typhoon HIL and Vector all offer HIL platforms, with different strengths in power electronics, automotive networks or cost.

Is HIL required for functional safety?

Standards such as ISO 26262 list HIL among the recommended test environments for integration and verification. They require evidence; HIL is often the most efficient way to produce it.

What does a HIL engineer do?

Specifies and builds the bench, develops and validates the real-time models, writes automated test sequences, runs campaigns and analyses failures with the software and hardware teams.

Learn it live

This topic is covered in depth, with industrial case studies, in the HIL validation with dSPACE program. Join the waitlist to hear first when it opens — or browse the 64 free guides in the meantime.

Mohamed Yasser El Mekadem, Technical Leader in battery systems and power electronics

Written by

Mohamed Yasser El Mekadem

Technical Leader on a 1500 V rail traction battery. Eight years in onboard railway energy: power converters, HIL validation, battery systems.

Waitlist

Learn this live, with industrial case studies.

Three programs — power electronics, battery systems & BMS, HIL validation. Join the list to hear first when one opens.

One email when a program opens. Unsubscribe in one click. Privacy policy.

Keep reading

Related articles

Drone batteries: LiPo vs Li-ion, specific energy, flight time and BMS
Batteries & BMS

Drone Batteries: LiPo vs Li-Ion, Wh/kg, C-Rate and BMS

A drone battery is the heaviest component in the aircraft and the one that sets its endurance. LiPo against Li-ion, the Wh/kg of real packs and cells, how flight time depends on battery mass, what C-rate a mission actually needs, and what the BMS of a flight battery does differently.

Read the article →