Using Formula Nodes in LabVIEW

Updated Sep 5, 2023

Environment

Software

  • LabVIEW

The Formula Node in LabVIEW software is a convenient, text-based node you can use to perform complicated mathematical operations on a block diagram using the C- syntax structure. It is most useful for equations that have many variables or are otherwise complicated.

The text-based code simplifies the block diagram and increases its readability. Furthermore, you can copy and paste existing code directly into the Formula Node rather than recreating it graphically. The Formula Node is available in all development versions of LabVIEW and does not require an additional toolkit or add-on.

This tutorial is useful for familiarizing yourself with the Formula Node. Follow the steps to create a simple structure to compute different formulas depending on input values. Then, compare the simplicity of your block diagram using a formula node to its counterpart using graphical programming. The Formula Node is a tool that allows the benefits of text-based code within the easy-to-use graphical LabVIEW architecture.

  1. Selecting File»New VI to open a blank VI.
  2. Place a Formula Node on the block diagram.
    1. Right-click on the diagram and navigate to Programming»Structures»Formula Node
    2. Left-click to select the Formula Node.
    3. Place the Formula Node on the block diagram by left-clicking, dragging, and releasing the mouse. 
  3. Right-click the border of the Formula Node and select Add Input from the shortcut menu.
  4. Label the input variable x.
  5. Repeat steps 3 and 4 to add another input and label it y.
 
  1. Right-click the border of the Formula Node and select Add Output from the shortcut menu.
  1. Label the output z1.
  2. Repeat step 5 to create another output, and label this output z2.

Note: It is considered good programming practice to keep the inputs on the left border and the outputs on the right border of the Formula Node. This helps you follow the data flow in your VI and keep your code organized.

    1. Enter the expressions below in the Formula Node.
      • Make sure that you complete each command with a semicolon. Notice, however, that the if-statement does not require a semicolon on the first line.

    if (x*y>0)
    z1 = 3*x**2 - 2*y**3;
    else z1 = 0;
    z2 = sinh(z1);

    1. Create controls and indicators for the inputs and outputs.
      1. Right-click on each input and select Create»Control from the shortcut menu.
      2. Right-click on each output and select Create»Indicator from the shortcut menu.
    Note that you can change the control and indicator names to their respective variable by editing their labels.
    1. Place a While Loop around the Formula Node and the controls.
      1. Right-click on the diagram and navigate to Programming»Structures»While Loop
      2. Left-click to select the While Loop.
      3. Place the While Loop on the block diagram by left-clicking, dragging, and releasing the mouse.
      4. Right-click the Stop icon and Create Control. Label it as Stop.
    2. Add a Wait (ms) function inside of the While Loop to conserve memory usage, and wire in 100 milliseconds as a wait time. Your block diagram should appear as follows:
    1. Click the Run button to run the VI. Change the values of the input controls to see how the outputs change.

    In this case, the Formula Node helps minimize the space required on the block diagram. Accomplishing the same task without the use of a Formula Node requires the following code: