LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I hold a reading in a point in time and then process it after a duration?

Help me translate this into LabVIEW.

 

I can describe it this way, and all happening within a fast while loop (no delays in the while loop)

 

at t0: read and hold on to "Reading" (temporal var1

(1 second later)

at t1: read and hold on to "Reading" (temporal var2)

 

additionally: Then Subtract Var2 and Var1 e.g. (Var2-Var1)

 

The Reading can be a random generated number for instance.

0 Kudos
Message 1 of 6
(1,270 Views)

Hi kulani,

 

use shift registers to hold your values!

Keep in mind: LabVIEW stores values in wires and shift registers (or feedback nodes)...

Best regards,
GerdW


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

If the example you gave was significantly simplified, and you're also concerned about the processing time of the "subtract" operation (i.e., if it is not subtract but instead some much more complicated function of larger data sets than two doubles) you could also look at the Producer/Consumer pattern/design.

 

That would allow you to make your measurements in one loop (Producer) and then calculations in a separate loop (Consumer). This is particularly useful if your results are written to file or similar (potentially slow) and your measurements are much faster than the 1Hz you gave in your post.

 

If you are measuring one double per second, I don't think this will be necessary (even for file I/O, probably, just don't open and close the file inside the loop).

 


GCentral
Message 3 of 6
(1,195 Views)

@Kulani93 wrote:

I can describe it this way, and all happening within a fast while loop (no delays in the while loop)


Fast can mean many things to many people (a tricycle going "fast" probably has a different speed than a fighter jet going "fast" 🙂 ). If you don't have a wait, the loop rate is determined whatever the processing time of the code is and thus unpredictable and different every time you change the hardware. Unpredictable code is not future-proof and not professional!!

 

OTOH, if you can guarantee a defined loop rate, the "1 second later" can be calculated from a defined increment of [i] and you don't even need to bother with timing functions. 😉

 

So if you have a free-running loop with undefined loop time (hopefully below 1 seconds, but who knows! 😉 ), easiest would be to calculate the elapsed time from differencing either "tick count(ms)" or "high resolution relative seconds" then reset after each second. Keep var(n-1) in a shift register. Whenever the time has elapsed, subtract var(n) and var(n-1) and place the new one in the shift register to be used as var(n-1) at the next time point.

 

General advice: Instead of telling us how you want to do something, tell us what you want to do in general terms. What is the purpose of this exercise? Maybe there is a much better solution to get whatever you need.

 

Message 4 of 6
(1,180 Views)

@altenbach wrote:

@Kulani93 wrote:

I can describe it this way, and all happening within a fast while loop (no delays in the while loop)


General advice: Instead of telling us how you want to do something, tell us what you want to do in general terms. What is the purpose of this exercise? Maybe there is a much better solution to get whatever you need.


This is good advice, I will stick to it.

0 Kudos
Message 5 of 6
(1,168 Views)

@GerdW wrote:

Hi kulani,

 

use shift registers to hold your values!

Keep in mind: LabVIEW stores values in wires and shift registers (or feedback nodes)...


Thanks, I actually made use of them.

0 Kudos
Message 6 of 6
(1,160 Views)