Skip to content Skip to navigation

Connexions

You are here: Home » Content » Auto Match VI

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • National Instruments display tagshide tags

    This module is included in aLens by: National InstrumentsAs a part of collection:"LabVIEW Graphical Programming Course"

    Comments:

    "A full introductory course on programming with LabVIEW."

    Click the "National Instruments" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

Auto Match VI

Module by: National Instruments. E-mail the author

User rating (How does the rating system work?)
Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

:
(0 ratings)

Summary: To pass data out of a While Loop through a tunnel.

Note: Your browser may not currently support MathML. See our browser support page for additional details. You can always view the correct math in the PDF version.

Exercise 1

Complete the following steps to build a VI that generates random numbers until the number generated matches a number you specify. The iteration terminal records the number of random numbers generated until a match occurs.

1.a) Front Panel

  1. Open a blank VI and build the front panel shown in Figure 1. Modify the controls and indicators as shown in the front panel and as described in the following steps.
    Figure 1
    Figure 1 (automatch.png)
    1. Place a numeric control, located on the Controls>>Numeric Controls palette, on the front panel. Label the control Number to Match. This control specifies the number to match.
    2. Place a numeric indicator, located on the Controls>>Numeric Indicators palette, on the front panel. Label the indicator Current Number. This indicator displays the current random number.
    3. Place another numeric indicator on the front panel. Label the indicator Number of iterations. This indicator displays the number of iterations before a match.

1.b) Setting the Data Range

Set a data range for a control to prevent the user from selecting a value that is not compatible with a range or increment. You can choose to ignore a value that is out of range or coerce it to within the range. Complete the following steps to set the range between 0 and 10000 with an increment of 1 and a default value of 50.

  1. Right-click the Number to Match control and select Data Range from the shortcut menu. The Data Range page of the Numeric Properties dialog box appears.
    1. Remove the checkmark from the Use Default Range checkbox.
    2. Set the Default Value to 50.
    3. Set the Minimum value to 0 and select Coerce from the Out of Range Action pull-down menu.
    4. Set the Maximum value to 10000 and select Coerce from the Out of Range Action pull-down menu.
    5. Set the Increment value to 1 and select Coerce to Nearest from the Out of Range Action pull-down menu. Do not close the dialog box.

1.c) Modifying Digits of Precision

By default, LabVIEW automatically formats numeric controls. You also can specify the precision or notation. You can display numeric values in floating-point, scientific, or SI notation. Complete the following steps to change the precision to 0.

  1. Select the Format and Precision tab. If you closed the Numeric Properties dialog box, right-click the Current Number indicator and select Format & Precision from the shortcut menu. The Format & Precision page of the Numeric Properties dialog box appears.
    1. Select Floating Point and change Significant digits to Digits of precision.
    2. Type 0 in the Digits of precision text box and click the OK button.
  2. Repeat the instructions to set the precision for Current Number and Number of iterations indicators.

1.d) Block Diagram

  1. Build the block diagram in Figure 2.
    Figure 2
    Figure 2 (automatchbd.png)
    1. randnum.png Place the Random Number (0-1) function, located on the Functions>>Arithmetic & Comparison>>Express Numeric palette, on the block diagram. This function produces a random number between 00 and 11.
    2. multiply.png Place the Multiply function, located on the Functions>>Arithmetic & Comparison>>Express Numeric palette, on the block diagram. This function multiplies the random number by 10,00010,000 to produce a random number between 00 and 10,00010,000.
    3. automatchconst.png Right-click the y terminal of the Multiply function, select Create>>Constant from the shortcut menu, type 10000, and press the <Enter> key to create a numeric constant.
    4. roundnearicon.png Place the Round To Nearest function, located on the Functions>>Arithmetic & Comparison>>Express Numeric palette, on the block diagram. This function rounds the random number to the nearest integer.
    5. noteqicon.png Place the Not Equal? function, located on the Functions>>Arithmetic & Comparison>>Express Comparison palette, on the block diagram. This function compares the random number with Number to Match and returns True if the numbers are not equal; otherwise, it returns False.
    6. while.png Place the While Loop, located on the Functions>>All Functions>>Structures palette, on the block diagram. Right-click the conditional terminal and select Continue if True from the shortcut menu.

      Note:

      Use the While Loop with Stop button, located on the Execution Control palette, when you need a stop button to stop the While Loop. In this exercise, you use the Number to Match control to stop the loop; you do not need a Stop button.
    7. iteration.png Wire the iteration terminal to the border of the While Loop. A blue tunnel appears on the While Loop border. You will wire the tunnel to the Increment function. Each time the loop executes, the iteration terminal increments by one. The iteration count passes out of the loop upon completion. Increment this value by one outside the loop because the count starts at 00.
    8. incremicon.png Place the Increment function, located on the Functions>>Arithmetic & Comparison>>Express Numeric palette, on the block diagram. This function adds 11 to the While Loop count. A coercion dot appears on the Number of iterations output to indicate that LabVIEW coerced the numeric representation of the iteration terminal to match the numeric representation of the Number of iterations output. Refer to the For Loops section for more information about numeric conversion.
  2. Save the VI as Auto Match.vi.

1.e) Run the VI

  1. Display the front panel and change the number in Number to Match.
  2. Run the VI. Change Number to Match and run the VI again. Current Number updates at every iteration of the loop because it is inside the loop. Number of iterations updates upon completion because it is outside the loop.
  3. exehilit.png To see how the VI updates the indicators, enable execution highlighting. On the block diagram toolbar, click the Highlight Execution button, shown at left, to enable execution highlighting. Execution highlighting shows the movement of data on the block diagram from one node to another so you can see each number as the VI generates it.
  4. Change Number to Match to a number that is out of the data range, which is 00 to 1000010000 with an increment of 11.
  5. Run the VI. LabVIEW coerces the out-of-range value to the nearest value in the specified data range.
  6. Close the VI.

Solution

Content actions

Give Feedback:

E-mail the module author | Rate module ( How does the rating system work?)

Rating system

Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

(0 ratings)

Download:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.

| A lens (?)

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks