LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is this snippet going to subtract the initial value from all subsequent values?

Solved!
Go to solution

I need to save the value of an input from the first time a sub-vi is called, and subtract that value from all subsequent input values. It's a "baseline" of sorts. Will this snippet do this?

0 Kudos
Message 1 of 10
(2,469 Views)

no, use FGV

0 Kudos
Message 2 of 10
(2,434 Views)
Solution
Accepted by topic author jfalesi

Hi jfalesi,

 

I need to save the value of an input from the first time a sub-vi is called

When you are uncertain about the behaviour of a VI you should create a small "testbench" for that subVI…

 

Something like this:

check.png

There's a "First Call?" function and you can use it whenever you want to do something at the first call of a VI!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 10
(2,429 Views)

@jfalesi wrote:

I need to save the value of an input from the first time a sub-vi is called, and subtract that value from all subsequent input values. It's a "baseline" of sorts. Will this snippet do this?



Almost. Show enable terminal and use a "first call?" node on that terminal. See attached VI and test VI.

Certified LabVIEW Architect
Download All
Message 4 of 10
(2,423 Views)

@thols wrote:

Almost. Show enable terminal and use a "first call?" node on that terminal. See attached VI and test VI.


throls, you've written "2012", but VIs in LV 2018.
bthw, GerdW's variant better imho, because no need extra terminals.

0 Kudos
Message 5 of 10
(2,416 Views)

Hi Artem,

 

bthw, GerdW's variant better imho, because no need extra terminals.

But I need one more LabVIEW primitive, so I see an advantage for the Enable terminal of the feedback node!

(I hope the compiler will create the same code for both variations…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(2,411 Views)


throls, you've written "2012", but VIs in LV 2018.

Thanks. Corrected. Lol, I resaved it in 2018 to relink to the renamed file for 2012. Exchanging coffee for tea was maybe not such a good idea.

 

Any flavor of the solution will do. 

Certified LabVIEW Architect
0 Kudos
Message 7 of 10
(2,406 Views)

Why would using "first call" have different behavior than wiring the desired value to the "initializer" terminal and setting it to "Initialize on first call"?

0 Kudos
Message 8 of 10
(2,375 Views)
@jfalesi wrote:

Why would using "first call" have different behavior than wiring the desired value to the "initializer" terminal and setting it to "Initialize on first call"?


Using "Initialize on first call" will still feed each iteration's value into the feedback node. Using the Enable input and setting the value only on the first call will keep the initial value for every iteration.

Certified LabVIEW Architect
0 Kudos
Message 9 of 10
(2,353 Views)

Yes, each iteration's value will be sent back into the feedback node, but iterations don't alter the value. So once it's initialized, the initialized value should be fed back into the feedback node every time the VI is called. I would use a shift register, but this VI is executed only once per call so I don't need a while loop.

0 Kudos
Message 10 of 10
(2,323 Views)