Basic Architecture for Executing Models (Model Interface Toolkit)

LabVIEW 2017 Model Interface Toolkit Help

Edition Date: May 2017

Part Number: 374160C-01

»View Product Info
Download Help (Windows Only)

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:
  1. Writes a value of 0 to the only model inport.
    Note  This example applies the same inport value during every time step. This might be typical of applications in which you want to observe the model response to a particular stimulus. However, in hardware-in-the-loop applications, dynamic inport values might come from hardware I/O, such as channels on a DAQ device. In other applications, you might allow users to manipulate inport values via front-panel controls.
  2. Steps the model during each iteration of the Timed Loop. The Timed Loop iterates until an error occurs or the stop control is TRUE.
  3. Displays the value of the model outport in a waveform chart on the front panel.


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 Loop

When 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

WAS THIS ARTICLE HELPFUL?

Not Helpful