LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I initialize a shift register when I run the vi for the first time?

I have a vi that zero's my voltage signal. The first time I run the vi the shift register has a zero value which is what I want. The second time I run the vi the shift register has the previous values in it, this will not let me zero correctly. How do I initialize the shift register only when I run the vi. I have tried setting the shift register to a zero constant but this returns a zero every time the value loops.

 

Thanks,

joew

0 Kudos
Message 1 of 14
(4,132 Views)

A shiftregister keeps values written to it in the previous iteration. Therefore if you have written a value other than 0, it will keep that value until you write the next value to it.

If you load a VI containing a shiftregister, LV will initialize it to its default datavalue (0 for numeric, "" for string, NULL for references and FALSE for boolean). Running the VI will pass on that value in iteration 0. If you do not write a new value to it in this iteration, the next iteration will also pass on the default value....

If you initialize the shiftregister, you will write a new value into the shiftregister just before executing the first iteration (0), and therefore will get the value you have just written in iteration 0.

 

If the VI is stopped and started again, LV will still have the memory of the shiftregister in it's dataspace and therefore read the value written in the last iteration of the previous VIs execution. Initializing the shiftregister in your VI will prevent the VI from reading out-of-date data.

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 14
(4,127 Views)

I'm not sure I understand correctly what you mean by "How do I initialize the shift register only when I run the vi".

A common way to work with such functional globals (or action engines) is to have different methods. One of the could be to init the VI, one to set a value, one to read a value, ...

Then you just call the VI with the init method when your application starts.

 

I'd recommend to read Ben's thread on Action Engines. It's an excellent resource on that topic.

 

Hope this helps,

Daniel

 

 

Message Edited by dan_u on 01-13-2009 04:52 PM
0 Kudos
Message 3 of 14
(4,117 Views)

The title of your question is quite clear however the following question is not.

How about this:

 

Ton

Message Edited by TonP on 01-13-2009 05:39 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 4 of 14
(4,104 Views)

Ton,

 

i am sorry to say that your screenshot is a kind of Goldberg 😉

This VI does the same (i just used Add instead of Increment since Increment would use double here):

 

 

So your VI makes only sense if your initvalue is != 0....

 

Norbert

Message Edited by Norbert B on 01-14-2009 02:36 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 5 of 14
(4,065 Views)

To initialize a shift register i usually connect do it from the "outside", just like you mention you do with a constant.

 

The shift registers idea is to pass the data to the next loop iteration, so unless you modify the data inside the loop it'll always stay at the previously initialized value.

(maybe i misunderstood)

 

What do you use the shift register for, maybe it's not needed at all?

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 14
(4,050 Views)

I'm sorry Norbert, but you are wrong and Ton is right.

When you execute the vi in the development environment, the shift register is not re-initialized when the execution is stopped and restarted.

So, Ton's code is necessary in order to restart with a proper null (or whatever needed) value in the sr, because the "First Call?" node issues a true every time the execution is restarted.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 7 of 14
(4,037 Views)

Paolo,

 

please review my screenshot: Do i init the shiftregister??

What does a (none initialized) shiftregister pass in the first iteration (i==0) in the first execution of the VI after loading it into memory????

So if Ton is passing a numeric 0 (boolean would be FALSE, Reference NULL, string an empty string), it does exactly the same.

If Ton passes something different, the select and "first call" would be neccessary because it would change the value of the shiftregister in the first call after the VIs loading process.....

 

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 8 of 14
(4,035 Views)

If you stop the VI I wrote and you rerun the VI the value  be resetted.

The code I have written has no meaning (as Norbert noticed), it is the technique of the 'FirstRun?' and the case selector and the default value that matter.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 9 of 14
(4,023 Views)

I’m struggling here to understand the requirements here, but as I see it, what Yamaeda has done is what is needed. Now if joew has tried this and, as he says, “but this returns a zero every time the value loops” maybe he has miss-wired the connection and wired zero inside the loop through a normal tunnel which is hidden under the shift register arrow.

0 Kudos
Message 10 of 14
(4,001 Views)