Shift Register and Function Global

Publisher:感恩的7号Latest update time:2015-08-24 Source: eefocusKeywords:Shift  Register  Function  Global Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Let's first look at a piece of C code. The purpose of this function is to record the number of times it has been called. The best way is of course to record it inside the function, which requires keeping the last record between two calls. It is most reasonable to use a static variable. First, the variable's scope of action is only within the function and cannot be directly modified from the outside. Second, the variable can be automatically initialized when it is called for the first time.

int Record(void)

{

static int counter=0; //initialization for the first call

counter++;

return(counter);

}

How is a similar function implemented in LabVIEW? Of course, we can use a global variable and perform a +1 operation on the global variable in SUBVI, but the side effects of doing so are very obvious.

First, because there is no encapsulated data, the global variable can be modified at any location in the program. Second, when several places operate on the global variable at the same time, the current result is unpredictable because there is no protection mechanism.

The best way is to use Function Global, also known as LV2 type global variables. It may be that there were no built-in global variables before LABVIEW2, so this is the only way.


The core of Function Global is Shift Register (uninitialized). Most books emphasize the importance of Shift Register initialization. In fact, uninitialized Shift Register is more important.

I won't explain the general usage of Shift Register, such as the problem of finding the average value in a FOR loop. What we need to consider is what exactly is Shift Register? In fact, it should be a shared memory space that is readable and writable. In this case, it is essentially no different from a global variable. A basic Function Global is shown in the figure below:


Correction: The Boolean constant controlling the loop in the above figure should be TRUE, in order to make the loop run only once, in order to use SHIFT REGISTER

Here's how to use it:


This realizes the data exchange function of global variables. Component programming is an important programming method of LABVIEW, and Function Global is its core part.


 There is a problem with this program. When the program starts and no write operation is performed, what is the value of Shift Register? As a component programming, it should implement self-initialization inside it. Here we introduce an important VI, FIRST CALL, to solve this problem.


Keywords:Shift  Register  Function  Global Reference address:Shift Register and Function Global

Previous article:Function Global and Action Engine
Next article:Labview software counter and FIFO BUFFER

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号