Section 8 Timing 定时
推荐给好友
打印
加入收藏
更新于2008-05-16 20:59:46

Timing

定时

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.

这儿的”time”是另外的含义. 定时函数在LabVIEW中是一个重要的功能并可以帮助你测量时间, 同步任务, 或者允许足够的的处理器停顿时间以使得你的VI循环运行不至于跑的太快而拱起CPU运行.

You can find LabVIEW's timing functions on the Programming>>Timing palette, as shown in Figure 6.51.

你可以从Programming>>Timing函数模板中找到定时函数, 如图6.51.

Figure 6.51. Timing palette

图6.51. 定时模板

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.

LabVIEW中基本的定时函数有Wait (ms), Tick Count (ms), 和 Wait Until Next ms Multiple, 都位于Programming>>Timing函数模板中

Wait (ms) causes your VI to wait a specified number of milliseconds before it continues execution (see Figure 6.52).

Wait (ms)-等待(毫秒)函数使得你的VI在继续运行前等待一个指定的毫秒数 (见图6.52)

Figure 6.52. Wait (ms)

图6.52. 等待(毫秒)函数

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).

Wait Until Next ms Multiple-等待下一个毫秒倍数函数使得LabVIEW在继续VI执行之前一直保持等待状态直到内部时钟等于或已经超过了millisecond multiple 输入数值的整倍数时间; 这对于致使循环以指定的间隔时间执行和同步活动是非常有用的(见图6.53). 这两个函数是相似的, 但还是不一样的. 例如, Wait Until Next ms Multiple也许在第一次循环重复时等待时间要小于指定的毫秒数值, 依赖于当它开始时候的时钟值(那就是, 它要花费多长时间直到这个时钟到达了下一个倍数并被VI收到)

Figure 6.53. Wait Until Next ms Multiple

图6.53. 等待下一个毫秒倍数函数



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.

Wait Until Next ms Multiple通常被用来同步一个或多个循环, 因为它的定时是周期性的, 它会等待直到一个指定的时间发生. Wait (ms)通常被用于在事件之间创建一个中止停顿, 它等待一个指定的时间周期直到时间流逝.

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).

Tick Count (ms)-时钟计数函数返回你的操作系统的内部时钟的值, 并且是以毫秒的形式; 它通常被用于计算总共用时, 入在接下来的练习中(见图6.54).

Figure 6.54. Tick Count (ms)

Activity 6-4: Matching Numbers

练习6-4: 匹配数值

Now 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.

现在你将有机会来使用一个顺序结构和一个定时函数来工作了. 你要构建一个VI来计算一个输入数与一个随机产生的数之间相互匹配所花费的时间. 如果你总要记录LabVIEW运行的时间就记住这个算法. 许多有经验的LabVIEW开发员认为这就是使用多框架的顺序结构强迫并测量执行计时最好的原因.

1. Open a new front panel.

1.打开一个新的面板

2. Build the front panel shown (see Figure 6.55).

2.构建前面板如图6.55所示

Figure 6.55. The front panel of the VI you will construct during this activity

图6.55. 本练习中所构建的VI前面板

3. Open the diagram window and build the block diagram shown in Figure 6.56.

3.打开框图窗口并构建程序框图如图6.56所示

Figure 6.56. The block diagram of the VI you will construct during this activity

图6.56. 本练习中所构建的VI程序框图

4. Place a Flat Sequence Structure (Programming>>Structures palette) in the diagram window. It works like the For Loop and While Loop; click with the structure cursor and drag to define the boundaries you want.

4.放置一个平铺式的顺序结构(Programming>>Structures)在框图窗口里. 它如同For Loop 和 While Loop; 点击结构的指针并拖拽来指定到你需要的边框大小.

You will have to build three separate frames of the Flat Sequence Structure. To create new frames, pop up on the frame border and choose Add Frame After or Add Frame Before from the pop-up menu.

你将不得不给这个Flat Sequence Structure构建三个分开的框架. 要创建一个新的框架, 点击边框的弹出菜单并选择Add Frame After 或者 Add Frame Before.


5. Build the rest of the diagram. Some new functions are described here. Make sure to use the Help window to display terminal inputs and outputs when you wire!

5.构建框图的其余部分. 一些新函数将被使用到. 当你连线的时候可以使用帮助窗口来显示端子的输入和输出.



Tick Count Function

时钟计数函数

Tick Count (ms) function (Programming>>Timing palette). Returns the value of the internal clock.

Tick Count (ms)-时钟计数函数(Programming>>Timing). 返回内部时钟的数值



Random Number Function

随机数函数

Random Number (0-1) function (Programming>>Numeric palette). Returns a random number between 0 and 1.

Random Number (0-1)-随机数函数(0-1)函数(Programming>>Numeric). 返回一个在0到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.

Multiply-乘法函数(Programming>>Numeric). 以100乘随机数, 将使函数返回一个在0到100之间的随机数.



Round to Nearest Function

舍入函数

Round to Nearest function (Programming>>Comparison palette). Rounds the random number between 0 and 100 to the nearest whole number.

Round to Nearest -舍入函数(Programming>>Comparison). 四舍五入在0到100之间的随机数而成为最接近的整数.



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.

Not Equal? -不等于函数(Programming>>Comparison). 比较这个随机数与前面板上的指定的数并返回TRUE如果两数相等; 否则返回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).

Increment -增量函数(Programming>>Numeric). 给循环计数加上数1以产生Number of Iterations的值(用来补偿以0为基本位的索引)

In the first frame (on the left), the Tick Count (ms) function returns the value of the internal clock in milliseconds This value is wired through to the last frame. In the second frame (in the middle), the VI executes the While Loop as long as the number specified does not match the number returned by the Random Number (0-1) function. In the final frame (on the right), the Tick Count (ms) function returns a new time in milliseconds. The VI subtracts the old time from the new time to compute the time elapsed, and then divides by 1000 to convert from milliseconds to seconds.

在第一个框架中(在左边的), Tick Count (ms)函数以毫秒形式返回内部时钟的数值. 这个数值被连接到了最后一个框架上. 在第二个框架中(在中间的), 该VI将当指定的数值不匹配于Random Number (0-1)返回的数值时一直执行While Loop. 在最后一个框架中(在右边的), Tick Count (ms)函数返回一个新的毫秒时间数值. VI将从这个新的时间计数值减去旧的时间计数值来计算时间的流逝, 然后再除以1000使得毫秒转换成秒单位.

6. Turn on execution highlighting, which slows the VI enough to see the current generated number on the front panel.

6.打开高亮显示运行, 这个设置将充分地放慢VI的运行速度使得可以看到在前面板上当前产生的数值.

7. Enter a number inside the Number to Match control and run the VI. When you want to speed things up, turn off execution highlighting.

7.在控件Number to Match里输入一个数值然后运行该VI. 当你想加快运行的速度, 关闭加亮显示运行.

8. Use the Save command to save the VI in your MYWORK directory as Time to Match.vi, and then close it. Good job!

8.使用保存命令保存该VI到MYWORK目录并命名为Time to Match.vi, 然后关闭该VI. 做的好!

Express Timing Functions

快捷定时函数



In addition to the basic timing functions, LabVIEW also provides you with two Express Timing functions: Time Delay and Elapsed Time.

除了基本的定时函数之外, LabVIEW也提供给你两种快捷定时函数: Time Delay和Elapsed Time.

Time Delay works just like Wait (ms) except that you specify the time delay in seconds (see Figure 6.57).

Time Delay工作相似于Wait (ms)除了你指定的时间延迟是以秒的形式(见图6.57)

Figure 6.57. Time Delay Express VI and its configuration dialog

图6.57. 时间延迟快捷VI和它的配置对话框

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).

Elapsed Time让你检查指定的时间量是否已经流逝. 当你配置这个定时函数, 你设置有多少秒的流逝时间你想让它检查. 当你调用该VI, 如果指定的时间量已经流逝, 布尔量输出” Time has Elapsed”将返回一个真值(TRUE); 否则它将返回一个FALSE(见图6.58).

Figure 6.58. Elapsed Time Express VI and its configuration dialog

图6.58. Elapsed Time快捷VI和它的配置对话框

 

<<PREV    NEXT>>




 
关于我们 | 诚邀加盟 | 客户服务 | 相关法律 | 网站地图 | 友情链接 | 服务信箱:service@eefocus.com
© 2006 与非门科技信息咨询(北京)有限公司 All Rights Reserved.