Basic Architecture for Executing Models
- Updated2025-10-15
- 5 minute(s) read
Basic Architecture for Executing Models
The Model Interface API allows you to integrate and run models in LabVIEW control systems. In many applications, timing is an important consideration in application design because you want time steps to repeat according to specific timing characteristics or to synchronize model execution with the clock of a hardware device. To ensure LabVIEW runs a model reliably, you can separate your code into at least two components:
- A high-priority control loop—Executes one time step, first writing to model inports, and then reading from outports.
- Lower priority/background code—Executes when the control loop sleeps after completing execution. This code might get and set parameter values or read values from signals in the model.
Prior to the control loop of your code, you can perform initialization-related tasks, such as loading the model and initializing parameter values. After the control loop and background code stop executing, you unload the model and close any references you opened. Example: Simple Model Control Application
The following block diagram shows a simple VI that uses the Model Interface API to load the model, execute the model indefinitely in a control loop, set a parameter value in background-priority code, and unload the model.
|
Loads the model from disk and creates a model reference you pass to
other VIs throughout the application to run and interact with the model.
Note Avoid branching the model reference wire to
ensure optimal performance. The Model Interface API is not designed
to operate on a model in parallel locations.
|
|
Reads the compiled rate of the model in seconds and sets the period of the Timed Loop. Each iteration of the Timed Loop must complete execution before the specified period. This example converts seconds to milliseconds because the Period input of the Timed Loop expects values in the same units as the 1 kHz clock timing source the loop is configured to use. |
|
Performs the following tasks during each iteration of the
high-priority control loop:
|
|
Sets the value of a parameter when the control loop sleeps. This loop is typical of background-priority code. |
|
Unloads the model and handles any errors that occurred. |
In this example, the control loop transfers data between the model and front panel controls and indicators. A real-world application might contain features such as:
- A model with multiple inports, outports, parameters, and signals
- Hardware device driver VIs that read data from or write data to hardware I/O
- Multiple models
Refer to the labview\examples\Control and Simulation\Model Interface directory for example code that demonstrates various uses of the Model Interface API.


Related Links
Selecting a Timing Source for a Timed Structure
Initializing Parameter Values
Updating Parameters While the Model Runs
Probing Signal Values
Choosing the Right Type of Control LoopWhen you design the control-loop portion of your application, choose between using a Timed Loop or a While Loop to repeatedly step the model:
- Use a Timed Loop when:
- You want your code to repeat according to specific timing characteristics, such as at a guaranteed rate. Timed Loops provide features that help you ensure that the model executes deterministically, with each time step finishing on time, every time.
- You want the model execution code to run at a higher priority than other code whose timing characteristics are less critical.
- You want to synchronize the control loop with the clock of a hardware device. For example, if you want to pass data from a DAQ device into a model, a Timed Loop can use an external signal on the DAQ device to control its timing.
- Use a While Loop when you do not need precise timing abilities or deterministic execution. While Loops might be appropriate if you want to run your application on a general-purpose operating system, such as Windows, that does not guarantee real-time performance.
Related Links
Timed Loop
While Loop