LabVIEW Control Design and Simulation Module

Tutorial: Configuring Simulation Functions and Accessing Signals in a Simulation Hierarchy (Control Design and Simulation Module)

  • Updated2023-03-14
  • 5 minute(s) read

This tutorial guides you through configuring parameters of Simulation functions elsewhere in a hierarchy of Simulation functions and subsystems. In these exercises, you configure the Access Model Hierarchy function to initialize parameters of a Simulation function in a VI before the simulation runs.

Exercise 1: Preparing the Block Diagram

Complete the following steps to create a VI with simulation functions and a VI that edits model parameters in the simulation VI:

  1. Open the SimEx Sine VI in the labview\examples\Control and Simulation\Simulation\Signal Generation directory. This example VI contains a simulation diagram with a function you can configure.

    Open example 
  2. Save a copy of this VI in a convenient directory that is readable and writable. Name the file SimEx Sine Test.vi.
  3. Open the block diagram. In the Control & Simulation Loop, delete the frequency control and the wire that connects it to the Sine Signal function. Instead of setting the frequency of the signal through a wired terminal, you will configure the value from another VI.
  4. Select File»New VI to create a blank VI. This VI will set the frequency parameter in SimEx Sine Test.vi.
  5. Save the blank VI in the same directory as SimEx Sine Test.vi.
  6. Add the Access Model Hierarchy function to the block diagram of the blank VI.

    Add 

Exercise 2: Identifying Which Model Parameters to Update

Complete the following steps to configure the Access Model Hierarchy function to access a particular model parameter in the simulation VI:

  1. Double-click the Access Model Hierarchy function to open its configuration dialog box.
  2. In the VI with Simulation text box, enter the location on disk of SimEx Sine Test.vi.
    Tip  If the VI is still open, click the Select VI in memory button to select that VI as the VI with Simulation.
  3. In the Accessors list, click accessor 1 to make its name editable and enter the name freq_accessor. This list corresponds to terminals on the Access Model Hierarchy function.
  4. In the bottom half of the dialog box, select Sine Signal in the Select a function or subsystem list.
  5. In the Select a parameter or signal list, select the frequency item. The Source column for this item reads Unwired Terminal to indicate the frequency parameter does not have another source. The Access Model Hierarchy function can write only to parameters that are unwired or configured.
  6. Note that the path to the frequency parameter you selected automatically appears in the Path to model parameter or signal text box. Also, note that the Get/Set option is configured to set the value of the frequency parameter rather than to read its value.
  7. (Optional) In the Parameter Value section, change the value of the frequency control. You also can set the value of model parameters from a block diagram terminal.

The following dialog box for the Access Model Hierarchy function shows the configuration from this exercise.

Exercise 3: Identifying Which Signals to Collect

Complete the following steps to configure the Access Model Hierarchy function to return signal values from the simulation VI:

  1. Beside the Accessors list, click the add button to create a new accessor through which the Access Model Hierarchy function will return the signal value.
  2. Click the new accessor to make its name editable and enter the name sine_sig_accessor.
  3. In the bottom half of the dialog box, select Sine Signal in the Select a function or subsystem list.
  4. In the Select a parameter or signal list, select the output item. The Source column for this item reads Signal to indicate the item corresponds to a wire in the simulation diagram in which it resides. The Access Model Hierarchy function can return only signals on wires.
  5. Note that the path to the output parameter you selected automatically appears in the Path to model parameter or signal text box.
  6. Click OK, which displays a popup dialog about configuring a collection period. You will complete this task in Exercise 4 so LabVIEW can collect signal values.

On the block diagram, the Access Model Hierarchy function, shown as follows, is configured to perform the following tasks:

  • Write to the frequency model parameter of the Sine Signal function in SimEx Sine Test.vi.
  • Read and return signal values from the output terminal of the same function.

Exercise 4: Updating the Model Parameter and Collecting Signal Values at Run Time

Complete the following steps to set the frequency parameter of the Sine Signal function and collect the signal it generates as the simulation runs:

  1. On the block diagram that contains the Access Model Hierarchy function, right-click the value input for the Sine Signal.frequency accessor and select Create»Control from the shortcut menu.
  2. Enter a value of 3 in the Sine Signal.frequency control from step 1.

    This concludes the preparation for setting the frequency parameter.
  3. Right-click the value output for the Sine Signal.output accessor and select Create»Indicator.
  4. Return to the block diagram of SimEx Sine Test.vi. Though you identified signal to collect with the Sine Signal.output accessor, you still must specify how often to collect signal values.
  5. Double-click the Input Node of the Control & Simulation Loop to display the Configure Simulation Parameters dialog box.
  6. In the Signal Collection section, set the Decimation control to 1, which means LabVIEW collects a value at every time step. By default, the decimation period is 0, which means LabVIEW does not collect any values.
  7. Click OK to return to the block diagram.

    This concludes the preparation for collecting signal values.
  8. Run SimEx Sine Test.vi and observe the simulated signal in the waveform chart.
  9. Run the VI that contains the Access Model Hierarchy function and observe the change to the signal frequency in the waveform chart of SimEx Sine Test.vi. Note the signal value collected and displayed in the Sine Signal.output indicator.

You can use this function in other types of applications, such as to access parameters and signals in the same VI as the Access Model Hierarchy function and to access these items in a simulation that runs on an RT target.

Log in to get a better experience