It's "time" for another digression. Timing functions are very important in LabVIEW and help you measure time, synchronize tasks, and allow enough idle processor time so that loops in your VI don't race too fast and hog the CPU. You can find LabVIEW's timing functions on the Programming>>Timing palette, as shown in Figure 6.51. Figure 6.51. Timing palette
The basic timing functions in LabVIEW are Wait (ms), Tick Count (ms), and Wait Until Next ms Multiple, located in the Programming>>Timing subpalette of the Functions palette. Wait (ms) causes your VI to wait a specified number of milliseconds before it continues execution (see Figure 6.52). Figure 6.52. Wait (ms)
Wait Until Next ms Multiple causes LabVIEW to wait until the internal clock equals or has passed a multiple of the millisecond multiple input number before continuing VI execution; it is useful for causing loops to execute at specified intervals and synchronizing activities (see Figure 6.53). These two functions are similar, but not identical. For example, Wait Until Next ms Multiple will probably wait less than the specified number of milliseconds in the first loop iteration, depending on the value of the clock when it starts (that is, how long it takes until the clock is at the next multiple and the VI proceeds). Figure 6.53. Wait Until Next ms Multiple
Wait Until Next ms Multiple is commonly used for synchronizing one or more loops because its timing is periodicit waits until a specific time occurs. Wait (ms) is commonly used to create a pause between eventsit waits for a specified period of time to elapse. Tick Count (ms) returns the value of your operating system's internal clock in milliseconds; it is commonly used to calculate elapsed time, as in the next activity (see Figure 6.54). Figure 6.54. Tick Count (ms)
Activity 6-4: Matching NumbersNow you'll have the opportunity to work with the Sequence Structure and one of the timing functions. You will build a VI that computes the time it takes to match an input number with a randomly generated number. Remember this algorithm if you ever need to time a LabVIEW operation. Many experienced LabVIEW developers believe that this is the only reason ever to use a multiframe Sequence Structurefor enforcing and measuring execution timing.
Tick Count Function Tick Count (ms) function (Programming>>Timing palette). Returns the value of the internal clock. Random Number Function Random Number (0-1) function (Programming>>Numeric palette). Returns a random number between 0 and 1. Multiply Function Multiply function (Programming>>Numeric palette). Multiplies the random number by 100 so that the function returns a random number between 0.0 and 100.0. Round to Nearest Function Round to Nearest function (Programming>>Comparison palette). Rounds the random number between 0 and 100 to the nearest whole number. Not Equal? Function Not Equal? function (Programming>>Comparison palette). Compares the random number to the number specified in the front panel and returns a TRUE if the numbers are not equal; otherwise, this function returns a FALSE. Increment Function Increment function (Programming>>Numeric palette). Adds one to the loop count to produce the Number of Iterations value (to compensate for zero-based indexing).
Express Timing FunctionsIn addition to the basic timing functions, LabVIEW also provides you with two Express Timing functions: Time Delay and Elapsed Time. Time Delay works just like Wait (ms) except that you specify the time delay in seconds (see Figure 6.57). Figure 6.57. Time Delay Express VI and its configuration dialog
Elapsed Time lets you check whether a specified amount of time has passed. When you configure this timing function, you set how many seconds of elapsed time you want it to check for. When you call the VI, the Boolean output "Time has Elapsed" will return a TRUE if the specified amount of time has elapsed; otherwise, it returns a FALSE (see Figure 6.58). Figure 6.58. Elapsed Time Express VI and its configuration dialog
|