Inferensys

Glossary

Simulink Real-Time

Simulink Real-Time (formerly xPC Target) is a MathWorks product that compiles Simulink models into real-time C code for execution on dedicated target computers, enabling Hardware-in-the-Loop (HIL) testing and rapid control prototyping.
ML engineer managing model versions on laptop, version history visible, technical Git-like workflow.
HARDWARE-IN-THE-LOOP TESTING

What is Simulink Real-Time?

A technical definition of the MathWorks product for deterministic real-time execution of Simulink models.

Simulink Real-Time (formerly xPC Target) is a MathWorks product that compiles Simulink and Stateflow models into real-time C code and executes them on a dedicated target computer, enabling Hardware-in-the-Loop (HIL) testing and rapid control prototyping. It provides a deterministic execution environment with a real-time kernel, ensuring model computations complete within precisely bounded time steps for synchronized interaction with physical hardware like sensors and actuators.

The system operates by deploying the compiled application from a host PC to a target machine, which interfaces with the device under test (DUT) via specialized I/O boards for analog, digital, and communication protocols. This creates a closed-loop validation environment where the physical controller interacts with a simulated plant model in real time, allowing engineers to test embedded software against a digital twin before physical deployment.

SIMULINK REAL-TIME

Key Features and Capabilities

Simulink Real-Time is a MathWorks product that compiles Simulink and Stateflow models into real-time C code and executes them on a dedicated target computer for Hardware-in-the-Loop (HIL) testing and rapid prototyping.

01

Real-Time Code Generation

The core function is the automatic translation of Simulink block diagrams and Stateflow charts into optimized, standalone C code. This code is compiled with a real-time kernel for execution on a dedicated target machine. The process ensures deterministic execution, where the model's step time is guaranteed to be met on every cycle, which is critical for closed-loop control validation.

  • Rapid Prototyping: Enables quick iteration by deploying controller designs directly to hardware.
  • Production Code Foundation: The generated code often serves as a reference for final embedded software.
02

Target Computer Execution

The generated real-time application runs on a dedicated target computer, physically separate from the host PC used for development. This target is typically a real-time operating system (RTOS) like the MathWorks real-time kernel or a commercial RTOS (e.g., VxWorks).

  • Deterministic Scheduling: The RTOS guarantees task timing, isolating the real-time model from non-deterministic processes on a general-purpose OS.
  • Hardware-in-the-Loop Core: The target computer hosts the plant model and interfaces with physical I/O, forming the heart of the HIL test system.
03

I/O Hardware Integration

Provides extensive support for interfacing with physical hardware through I/O boards installed in the target computer. These boards handle the critical signal conversion between the digital simulation and the analog/digital world of the Device Under Test (DUT).

  • Analog & Digital I/O: For reading sensor voltages and driving actuator commands.
  • Communication Protocols: Direct support for CAN, EtherCAT, ARINC 429, and serial interfaces.
  • Signal Conditioning: Built-in scaling and calibration for matching sensor/actuator ranges.
04

Interactive Real-Time Interface

Engineers can interact with and monitor the running real-time application from the host Simulink environment without stopping execution. This enables dynamic parameter tuning, signal monitoring, and data logging.

  • Tunable Parameters: Adjust gains, setpoints, or model coefficients on-the-fly.
  • Real-Time Data Visualization: Plot signals as they are generated by the target.
  • Triggered Data Capture: Log high-speed data based on specific events or conditions.
05

Deterministic Execution & Timing Analysis

Ensures the model executes within a hard real-time deadline on every time step. The system provides tools for timing analysis to verify that the worst-case execution time (WCET) is less than the sample period.

  • Sample Time Enforcement: Guarantees model tasks complete before the next sample period begins.
  • Overrun Detection: Flags and logs any instance where the real-time deadline is missed, a critical failure in HIL testing.
  • Multirate Execution: Supports models with multiple, synchronized sample rates.
06

Integration with HIL Test Automation

Functions as the core real-time engine within larger automated test systems. It integrates with frameworks like Simulink Test and SystemTest for creating, managing, and executing comprehensive test suites.

  • Automated Test Sequences: Run pre-defined test vectors and scenarios.
  • Requirements Tracing: Link test cases to high-level requirements (e.g., with Simulink Requirements).
  • Continuous Integration (CI): Supports integration into CI/CD pipelines for regression testing.
MECHANISM

How Simulink Real-Time Works: The HIL Pipeline

Simulink Real-Time enables Hardware-in-the-Loop (HIL) testing by providing a deterministic pipeline from model to physical hardware.

Simulink Real-Time (formerly xPC Target) is a MathWorks product that compiles Simulink and Stateflow models into real-time C code and executes them on a dedicated target computer for HIL testing and rapid prototyping. The pipeline begins with a plant model—a virtual representation of the physical system—which is compiled with a fixed-step solver. This generated code is then deployed to a real-time target machine, a separate computer running a deterministic kernel that guarantees execution within strict microsecond-level timing deadlines, forming the core of the simulation engine.

The target machine interfaces with physical hardware through specialized I/O boards that handle analog/digital signal conversion and communication protocols like CAN or EtherCAT. In the HIL loop, the model receives actual sensor signals from the Device Under Test (DUT), processes them through the simulated plant dynamics, and outputs corresponding actuator commands. This closed-loop validation allows engineers to test embedded controllers against a high-fidelity, real-time virtual environment before physical prototype availability, significantly de-risking development.

SIMULINK REAL-TIME

Primary Use Cases and Industries

Simulink Real-Time is a dedicated platform for executing Simulink and Stateflow models as compiled C code on a real-time target computer. Its primary applications span industries where validating control logic against a simulated physical environment before physical deployment is critical for safety, cost, and development speed.

VALIDATION METHODOLOGY COMPARISON

Simulink Real-Time in the V-Model: MIL, SIL, PIL, HIL

A comparison of the four primary testing methodologies within the V-model development cycle, detailing the role of Simulink Real-Time in executing these tests.

Validation PhaseDescriptionSystem Under Test (SUT)Plant Model / EnvironmentPrimary ObjectiveSimulink Real-Time Role

Model-in-the-Loop (MIL)

Algorithmic validation within the simulation environment.

Simulink/Stateflow model (floating-point).

Simulink model of the physical system (plant).

Verify control logic and system dynamics. No code generation.

Not used. Purely desktop simulation.

Software-in-the-Loop (SIL)

Validation of generated or handwritten source code on a host PC.

C/C++ code compiled for the host PC.

Simulink model of the plant, run on the host PC.

Verify functional equivalence of code to model. Processor-agnostic.

Not typically used. Executes on standard host OS.

Processor-in-the-Loop (PIL)

Validation of compiled executable on the target processor.

C/C++ code cross-compiled and running on the target embedded processor (e.g., microcontroller).

Simulink model of the plant, run on the host PC.

Verify numerical behavior and timing on the target processor.

Can provide the target execution environment and host communication link.

Hardware-in-the-Loop (HIL)

Validation of the embedded controller with real I/O in a closed loop.

Physical Electronic Control Unit (ECU) with production software.

High-fidelity, real-time Simulink model of the plant, executed deterministically.

Test integrated hardware/software system with simulated sensors/actuators under realistic & edge-case conditions.

Core platform. Executes the real-time plant model and manages physical I/O interfacing with the ECU.

SIMULINK REAL-TIME

Frequently Asked Questions

Common questions about Simulink Real-Time, a MathWorks product for executing Simulink and Stateflow models on dedicated hardware for real-time testing and rapid prototyping.

Simulink Real-Time (formerly xPC Target) is a MathWorks product that compiles Simulink and Stateflow models into optimized, real-time C code and executes them with deterministic timing on a dedicated target computer. It works by taking a control algorithm or system model designed in the Simulink graphical environment, automatically generating code, and deploying it to a real-time operating system (RTOS) running on separate target hardware. This target machine, connected to physical sensors and actuators via I/O boards, runs the model in a hard real-time loop, ensuring computational deadlines are met for Hardware-in-the-Loop (HIL) testing and rapid control prototyping.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.