Hardware-in-the-loop testing puts real control hardware inside a simulated world so engineers can test how it behaves before connecting it to the real machine.

That simulated world might be:

  • A car
  • An aircraft
  • A robot
  • A battery system
  • A wind turbine
  • An industrial machine
  • An electric motor
  • A power converter

The controller is physically real.

The environment around it is simulated.

Hardware-in-the-loop testing with a real ECU connected to a simulated vehicle

NI describes HIL similarly: a real device under testโ€”often an embedded controllerโ€”is surrounded by a virtual environment that behaves like the physical system it will eventually control.

That gives engineers a wonderfully useful capability:

They can make terrible things happen to the product without making terrible things happen to an actual vehicle, aircraft or human being.


HIL Testing in Plain English

Suppose you are developing the electronic controller for an electric vehicle.

Eventually, that controller will receive information from things such as:

  • Wheel-speed sensors
  • Brake sensors
  • Battery sensors
  • Motor controllers
  • Steering systems
  • Other ECUs
  • Vehicle networks

It will make decisions based on those inputs.

Then it will send commands back out.

Testing it in the completed vehicle would certainly be possible.

But imagine trying to test:

What happens if the left rear wheel-speed sensor fails while the vehicle is traveling 70 mph, the battery voltage suddenly drops and CAN communication becomes intermittent?

You could attempt that in a prototype vehicle.

Or you could connect the ECU to a HIL simulator and make the simulated vehicle experience exactly those conditions.

No tow truck required.


How Does HIL Testing Work?

A basic HIL system contains three major pieces:

1. The real controller

This is the actual hardware engineers want to test.

It might be:

  • An automotive ECU
  • An aircraft controller
  • A battery-management system
  • An industrial controller
  • A motor controller

The production or prototype software runs on that hardware.

2. A real-time simulator

The simulator runs mathematical models representing the physical system.

That may include:

  • Vehicle dynamics
  • Motors
  • Batteries
  • Sensors
  • Actuators
  • Aerodynamics
  • Hydraulics
  • Mechanical loads
  • Electrical systems

3. Real input/output connections

The controller and simulator communicate using the same types of signals the real machine would use.

These can include:

  • Analog signals
  • Digital signals
  • CAN
  • LIN
  • Ethernet
  • FlexRay
  • Other communication buses

MathWorks emphasizes this distinction: in HIL, the actual controller is connected through real I/O to a simulated plant operating in real time. Those physical interfaces and their timing distinguish HIL from earlier purely virtual approaches such as MIL and SIL.


The Controller Thinks the Simulation Is Real

This is the clever part.

The ECU does not need to know that there isn’t actually a vehicle attached.

Suppose the controller sends:

Apply braking force.

The simulator calculates what should happen.

Vehicle slows.

Wheel speeds decrease.

The simulated wheel-speed sensors send new signals to the real controller.

The controller responds.

The simulator responds again.

And the loop continues.

That is why it is called:

Hardware-in-the-loop.

The physical controller is literally placed inside the simulation loop.


HIL Requires Real-Time Simulation

Ordinary simulation does not necessarily need to keep pace with reality.

A complicated CFD simulation might take six hours to calculate ten seconds of physical behavior.

That is fine.

HIL cannot do that.

If the ECU expects new sensor information every millisecond, the simulator has to provide it every millisecond.

Not eventually.

Not when the calculation finishes.

On time.

HIL therefore requires deterministic real-time execution.

If the real physical system would respond in one millisecond, the simulated version needs to behave appropriately within that same timing environment.

That is one reason HIL requires specialized real-time hardware and software.


The Aquarium Analogy

NI uses a surprisingly good analogy for HIL:

A fish in an aquarium.

The fish is real.

The ocean isn’t.

But if the aquarium provides the correct:

  • Water
  • Temperature
  • Salinity
  • Oxygen
  • Environment

the fish behaves as though it is living inside its natural world.

A HIL simulator does something similar for an embedded controller.

The controller is the fish.

The simulated vehicle or machine is the aquarium.

Except engineering gets much more entertaining because we can deliberately make the aquarium misbehave.


Why Engineers Use HIL Testing

HIL exists largely because modern products contain enormous amounts of embedded software.

Software now controls:

  • Braking
  • Steering
  • Engines
  • Electric motors
  • Batteries
  • Flight controls
  • Industrial equipment
  • Energy systems
  • Autonomous functions

Waiting until the completed product exists to test all of that software would create a very expensive development process.

NI identifies several central advantages of HIL, including earlier testing, repeatable scenarios, lower dependence on full prototypes and the ability to investigate dangerous conditions safely.


HIL Lets Engineers Test Before the Whole Product Exists

This can be enormously important to a development schedule.

Imagine an automotive program.

The brake ECU may be ready.

The complete prototype vehicle may not exist for another six months.

Without HIL:

Wait six months.

With HIL:

Connect the controller to a simulated vehicle and start testing now.

By the time the first complete prototype arrives, engineers may already have executed thousands of controller tests.

That is a classic example of shift-left testing:

Find defects earlier, when fixing them is cheaper.


HIL Lets Engineers Test Dangerous Situations Safely

This may be HIL’s most obvious advantage.

Consider testing an aircraft controller.

Would you prefer to discover an unusual control-logic defect:

A. In a laboratory

or

B. At 20,000 feet?

HIL lets engineers deliberately create abnormal conditions without exposing the complete physical system to the same risk.

Tests can include:

  • Sensor failures
  • Power failures
  • Communication loss
  • Actuator failures
  • Extreme operating conditions
  • Conflicting signals
  • Invalid inputs
  • Timing problems

You can make the system fail repeatedly.

Safely.


Failure Injection: Let’s Break Things on Purpose

Normal-operation testing asks:

Does the system work when everything works?

HIL lets engineers ask the much more interesting question:

What does the system do when something stops working?

A HIL system may simulate failures such as:

  • Open circuits
  • Short circuits
  • Stuck sensors
  • Missing messages
  • Implausible values
  • Low voltage
  • Excessive voltage
  • Communication delays
  • Broken actuators

NI’s current HIL architecture explicitly includes fault insertion capabilities along with signal conditioning, loads, communication networks and real-time simulation.

This is particularly important in safety-critical systems.

The controller should not merely work correctly when the world behaves.

It should also fail correctly when the world does not.


An Automotive HIL Example

Suppose engineers are testing an anti-lock braking controller.

The HIL simulator represents:

  • Four wheels
  • Tires
  • Road friction
  • Vehicle speed
  • Brake pressure
  • Wheel-speed sensors

The real ABS controller receives simulated wheel-speed signals.

Engineers can then create:

Normal braking

All four wheels behave normally.

Wet pavement

Reduce simulated tire-road friction.

Ice

Reduce it dramatically.

One wheel locks

Make one simulated wheel rapidly lose speed.

Sensor failure

Remove the signal from one wheel-speed sensor.

Implausible sensor

Make one wheel report 200 mph while the others report 45 mph.

Then observe what the actual controller does.

No actual icy parking lot required.


You Can Repeat the Exact Same Failure

This is another major advantage.

Real-world conditions are difficult to reproduce precisely.

Two road tests rarely have:

  • Exactly the same speed
  • Exactly the same friction
  • Exactly the same temperature
  • Exactly the same driver input
  • Exactly the same timing

HIL can produce the same simulated condition repeatedly.

That makes debugging much easier.

Engineer finds a failure.

Fixes the software.

Runs the exact same scenario again.

That repeatability is one of the reasons HIL is so valuable for regression testing.


HIL Is Particularly Good for Regression Testing

A software update fixes one problem.

Unfortunately, software updates occasionally create another.

Regression testing asks:

Did the change break something that used to work?

An automated HIL system can execute hundreds or thousands of previously established scenarios after every important software change.

Instead of asking an engineer to manually reproduce them, test automation can:

Load software โ†’ initialize system โ†’ execute scenario โ†’ compare results โ†’ record outcome โ†’ reset โ†’ repeat

That can turn a HIL system into something resembling a continuous verification environment for embedded software.


MIL vs. SIL vs. PIL vs. HIL

HIL usually appears as part of a progression.

The terminology is intimidating until you see what changes at each stage.

MethodControllerPhysical System
MILSimulated modelSimulated
SILCompiled softwareSimulated
PILSoftware running on target/similar processorSimulated
HILReal controller hardwareSimulated in real time
Physical testReal controllerReal system

MathWorks describes essentially this same progression, with each stage increasing the amount of actual implementation involved in the test.


What Is Model-in-the-Loop Testing?

Model-in-the-loop, or MIL, occurs very early.

Both the controller logic and physical system are represented by models.

Suppose engineers are developing cruise control.

A control-algorithm model represents the controller.

Another model represents:

  • Vehicle mass
  • Engine or motor
  • Road grade
  • Aerodynamic drag

Engineers can test the basic control strategy before production software or hardware exists.

MIL asks:

Does our control concept work?


What Is Software-in-the-Loop Testing?

Software-in-the-loop, or SIL, introduces the actual compiled control software while keeping the surrounding environment simulated.

Instead of testing only the abstract control model, engineers test executable software generated from or written to implement that model.

SIL helps answer:

Did the software implementation preserve the intended behavior?

MathWorks describes SIL as testing compiled control code within a simulated environment, providing a bridge between early model simulation and later hardware integration.


What Is Processor-in-the-Loop Testing?

Processor-in-the-loop, or PIL, puts the software onto the actual target processorโ€”or a representative processorโ€”while the physical environment remains simulated.

This can reveal problems involving:

  • Processor behavior
  • Execution timing
  • Compiler behavior
  • Numeric differences
  • Memory constraints

PIL moves another step toward reality.


Then Comes HIL

With HIL, the actual controller hardware enters.

Now engineers are testing:

  • Real processor
  • Real memory
  • Real firmware
  • Real I/O
  • Real communication interfaces
  • Real timing behavior

while the larger physical machine remains simulated.

So the progression can be remembered as:

MIL: Is the idea right?

SIL: Is the code right?

PIL: Does it behave properly on the processor?

HIL: Does the real controller behave properly when interacting with a realistic world?


Why Not Skip Straight to HIL?

Because HIL is more expensive and complicated.

MIL and SIL can often run on ordinary computing infrastructure and execute faster than real time.

That makes them excellent for exploring enormous numbers of early test cases.

You don’t want to use an expensive HIL rack to discover that someone wrote:

+

when they meant:

โˆ’

Catch easy problems earlier.

Save HIL for the problems that require real hardware interaction.


HIL Doesn’t Replace Software Testing

This is important.

HIL is not intended to replace:

  • Unit testing
  • Static analysis
  • Code review
  • SIL
  • Formal verification
  • Integration testing

It adds another layer.

A strong verification process catches different defect classes at different stages.

The earlier and cheaper the method that can reliably find a defect, the better.


HIL Doesn’t Replace Physical Product Testing Either

At the other end of development, HIL also does not replace the final physical product.

A simulated vehicle cannot perfectly reproduce:

  • Mechanical wear
  • Real vibration
  • Connector problems
  • Corrosion
  • Manufacturing variation
  • Tire variation
  • Road contamination
  • Human behavior
  • Weather

The controller may pass thousands of HIL tests.

Eventually somebody still needs to drive the car.

HIL reduces the number of unpleasant surprises that happen when they do.


The Model Matters

A HIL system is only as useful as the simulated environment surrounding the controller.

If the simulated vehicle behaves incorrectly, engineers may draw incorrect conclusions about the ECU.

That creates a second verification problem:

How do we know the plant model is accurate enough?

HIL development therefore requires credible models.

Those models may be created with software such as:

  • MATLAB/Simulink
  • Simcenter
  • Modelica-based tools
  • Specialized vehicle simulation software
  • Custom modeling environments

NI VeriStand, for example, can integrate simulation models into real-time test systems and connect the model’s inputs and outputs with physical I/O.


HIL Timing Matters Just as Much as Values

Suppose a brake controller is supposed to receive a sensor message every 10 milliseconds.

The HIL simulator sends the correct value.

But it sends it 50 milliseconds late.

That is not an accurate representation of the real system.

Timing behavior can itself be part of the thing being tested.

Engineers therefore need to consider:

  • Model execution time
  • I/O latency
  • Bus timing
  • Jitter
  • Synchronization
  • Real-time deadlines

This is why a HIL system is more than simply running a simulation on a laptop.


Communication Networks Become Part of the Test

Modern embedded systems rarely operate alone.

Automotive controllers may communicate over:

  • CAN
  • CAN FD
  • LIN
  • FlexRay
  • Automotive Ethernet

Industrial equipment may use other networks.

A HIL system can reproduce those communications and manipulate them.

NI VeriStand, for example, supports vehicle-network interfaces such as CAN, LIN and FlexRay through NI-XNET hardware.

That allows engineers to investigate problems such as:

  • Missing messages
  • Delayed messages
  • Incorrect values
  • Bus overload
  • Controller communication failures

For a modern software-defined vehicle, the communication network itself is part of the system that needs verification.


HIL for Electric Vehicles

Electric vehicles are especially well suited to HIL testing because so many important functions are software-controlled.

Potential HIL targets include:

  • Battery-management systems
  • Motor controllers
  • Inverters
  • Charging controllers
  • Thermal management
  • Vehicle-control units
  • Brake controllers

Engineers can simulate batteries, motors, loads and electrical conditions while connecting the actual controller hardware.

That lets teams explore situations that would be expensive or dangerous to reproduce with a full battery pack.


HIL for ADAS and Autonomous Vehicles

ADAS presents an even larger simulation problem.

A controller may need to respond to:

  • Cameras
  • Radar
  • LiDAR
  • GPS
  • Vehicle dynamics
  • Traffic
  • Pedestrians
  • Road geometry
  • Weather

There are essentially unlimited possible combinations.

HIL lets real control hardware interact with simulated driving scenarios repeatedly.

It cannot eliminate road testing.

But it can move enormous amounts of testing into a laboratory before anyone puts a prototype into traffic.


HIL in Aerospace

Aircraft contain safety-critical embedded controllers for:

  • Flight control
  • Engines
  • Landing gear
  • Environmental systems
  • Electrical systems
  • Avionics

Testing some failure conditions in an actual aircraft would be extremely difficultโ€”or spectacularly unwise.

HIL lets engineers test the real controller while simulated aircraft systems and environments provide the inputs.

MathWorks notes that HIL is used in industries such as aerospace and automotive for hardware/software integration and requirements-based testing in safety-critical development.


HIL Is Not Just Automotive and Aerospace

The same basic approach applies to:

  • Industrial machinery
  • Agricultural equipment
  • Robotics
  • Rail systems
  • Wind turbines
  • Grid equipment
  • Power electronics
  • Appliances

NI cites industrial HIL implementations at organizations including Whirlpool, Danfoss and Caterpillar, demonstrating that the method extends well beyond vehicles.

If a physical controller interacts with a complicated physical system, HIL may be useful.


What Software Is Used for HIL Testing?

Several engineering software ecosystems support HIL.

dSPACE

dSPACE provides one of the best-known automotive HIL environments, including:

  • SCALEXIO
  • ControlDesk
  • AutomationDesk
  • VEOS

Its heritage is particularly strong in ECU development and automotive controls.

NI

NI’s HIL environment centers on:

  • VeriStand
  • PXI
  • CompactRIO
  • SLSC
  • TestStand
  • LabVIEW

NI describes VeriStand as its core application for configuring and controlling HIL systems and embedded-software tests.

MathWorks

MATLAB and Simulink support MIL, SIL, PIL and HIL workflows.

Simulink Real-Time allows engineers to deploy real-time plant models onto compatible real-time test hardware.

Other vendors and specialized HIL platforms also serve automotive, aerospace, power electronics and industrial markets.


HIL Testing and Test Automation

Manually running one HIL scenario is useful.

Running 20,000 manually is not.

That is why HIL environments are commonly paired with test automation.

Automation may:

  1. Load a controller configuration.
  2. Start the simulation.
  3. Create an operating condition.
  4. Insert a fault.
  5. Measure the controller response.
  6. Compare it with requirements.
  7. Record the result.
  8. Reset the system.
  9. Move to the next scenario.

NI VeriStand can be automated using TestStand, Python, .NET and ASAM XIL interfaces.

The result is repeatable regression testing of actual embedded hardware.


HIL and Continuous Integration

As embedded products become increasingly software-defined, HIL systems are moving closer to software-development workflows.

Imagine:

Developer commits code.

โ†“

Software builds.

โ†“

MIL/SIL tests execute automatically.

โ†“

Controller software is deployed.

โ†“

HIL regression executes overnight.

โ†“

Failures are reported the next morning.

That begins to connect traditional software CI/CD practices with physical engineering verification.

The challenge is that HIL resources are finite.

You can create unlimited virtual test runners relatively cheaply.

You probably do not own unlimited HIL racks.

That makes test scheduling and simulator utilization increasingly important.


What Makes a Good HIL Test?

A useful HIL test should have:

A clear requirement

What behavior are you verifying?

Defined initial conditions

What state is the controller and simulated system in?

Defined stimulus

What event or input occurs?

Expected behavior

What should the controller do?

Pass/fail criteria

How will the software decide whether the requirement was met?

Traceability

Which requirement does this test support?

Reproducibility

Can another engineer run the same test and obtain comparable evidence?

Otherwise you may simply be creating interesting demonstrations.


A HIL System Can Be Wrong Too

This is worth emphasizing.

The HIL system itself is an engineered product.

It contains:

  • Software
  • Models
  • Hardware
  • Wiring
  • Sensors
  • Signal conditioning
  • Communication interfaces
  • Test scripts

Any of those can contain defects.

If the HIL system says the ECU failed, engineers need to know:

Did the product failโ€”or did the test system fail?

That is why HIL platforms themselves require careful configuration, calibration, maintenance and validation.


Don’t Let HIL Become the Expensive Machine Nobody Wants to Touch

Sophisticated HIL installations can become dependent on one or two specialists.

That is dangerous.

A useful HIL environment should be:

  • Understandable
  • Maintainable
  • Documented
  • Automatable
  • Reusable

If every test requires calling the one engineer who knows how the rack works, the organization has created a bottleneck rather than a verification platform.

This should be part of every HIL software evaluation.


What Should You Evaluate in HIL Software?

If you are evaluating dSPACE, NI, MathWorks or another HIL platform, don’t begin with the vendor’s perfect demonstration.

Use one of your controllers.

Then examine:

Model integration

Can you use models you already have?

Real-time performance

Can the simulator consistently meet timing requirements?

I/O

Does it support the signals and buses your controller actually uses?

Fault insertion

Can engineers easily create the failures they need to investigate?

Automation

Can test campaigns run unattended?

Debugging

When something fails, can you determine why?

SIL-to-HIL reuse

Can earlier tests move forward into HIL?

Requirements traceability

Can test evidence be connected back to engineering requirements?

Maintainability

Can another engineer understand and modify the environment?

Scalability

What happens when one ECU becomes ten?


The Real Value of HIL Is Not the Hardware Rack

A giant HIL rack filled with electronics is certainly impressive.

But buying a rack is not the objective.

The objective is moving useful knowledge earlier.

If HIL lets engineers discover:

  • A control defect
  • A timing problem
  • A communication failure
  • A dangerous fault response
  • A software regression

six months before the complete physical product exists, that can be enormously valuable.

The earlier the defect is found, the more options engineers usually have for fixing it.


HIL Testing: The Bottom Line

Hardware-in-the-loop testing occupies a fascinating middle ground between simulation and physical testing.

The controller is real.

The world is simulated.

That combination lets engineers test actual embedded hardware against conditions that are:

  • Expensive
  • Rare
  • Difficult
  • Dangerous
  • Not yet physically available

HIL can reproduce those conditions repeatedly and automatically.

It can deliberately fail sensors.

Drop voltage.

Corrupt communications.

Change environmental conditions.

Create edge cases.

Then watch how the real controller responds.

It does not eliminate MIL.

It does not eliminate SIL.

It does not eliminate physical testing.

Instead, it provides another important step in the progression from:

Idea โ†’ model โ†’ software โ†’ controller โ†’ complete physical system

And the question HIL ultimately helps engineers answer is wonderfully practical:

Before we connect this controller to the real machine, have we given it enough opportunities to do something stupid in the laboratory?

Because when the controller eventually reaches the car, aircraft, robot or industrial machine, that is a considerably better question to have answered already.