LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why are separate subvi shift registers exchanging previous data between themselves

What I have is a NI USB-6001 to acquire data with. I set up a single task in NiMax to acquire two analog channels Ch0 and Ch1. Both are single ended with a range of 0-5 vdc. The main VI acquires the data from both channels and sends it off to individual subvi's. This subvi compares previous data to current data from a shift  register. It determines if the previous and current data exceed a specified percentage of difference. If it does it latches on an Led indicator. This works fine if I do this for only one channel (only one subvi). I duplicate this for 2 channels one subvi for each channel now and it is acting strange. My "previous ch0" indicator is receiving  "previous ch1" data and vice versa as seen in my image of the front panel. I have included the images here. If the VI code is needed I will attach it. 

 

This is the Front Panel

 

testvi.png

 

 

This is the SubVI

subvi.png

 

This the Main VI

mainvi.png

0 Kudos
Message 1 of 14
(3,902 Views)

In the subVI, go to VI Properties (Ctrl+I will open it up).  Then go to the Execution section via the dropdown.  Choose "Preallocated Clone Reentrant Execution".  Save the VI.

 

The default setting for a VI is to have non-reentrant execution.  What this does is make it so that there is only 1 copy of the VI in memory at all times.  This means that each call will share the memory/state.  By making it peaalocted clone reentrant, each call has itsmown memory and state.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 14
(3,886 Views)

Thanks, greatly appreciated!

 

Bryan

0 Kudos
Message 3 of 14
(3,871 Views)

While you're at it, do somwthing (anything) with that icon before you get into bad habits of leaving the default icon in place.

Message 4 of 14
(3,819 Views)

It would also be a good idea to move the DAQmx Start Task and DAQmx Stop Task outside the while loop.  Always open and close references outside the loop, then read/write inside the loop.

Cody A.
Message 5 of 14
(3,760 Views)

This works good now but seeing I have to compare approximately 7 channels channels of analog data for % of difference I'm thinking it would be better try and do that using an array of channels instead of each channel seperately going into my subvi. I'm not sure how to setup mathscript to work with an array. I looked through the forum but the concept is still pretty vague to me considering my formula is different then the others I've seen. I am noticing that my main  loop time is taking a hit from trying to acquire and compare 7 channels of data. I'm sampling at 300ks/s right now but everything else in the main loop is eating up time.  My analog tasks are now configured in max and not in code now. I have attached my subvi if anyone can help me out converting it to work with an array rather then a channel of data at a time. It would be appreciated.

Thanks,

Bryan

0 Kudos
Message 6 of 14
(3,730 Views)

Hi,

 

Currently, your subVI calculates the % difference between the current value and the previous value from the same channel. I'm not sure how you plan on using an array for this calculation. Are you trying to get the % difference across 2 different channels? It may be best if you can attempt to create what you had in mind and I can try to steer you in the right direction from there.

James F.
Applications Engineer
National Instruments
0 Kudos
Message 7 of 14
(3,685 Views)

James,

I acquire 7 analog channels. So my array of 7 elements hold one sample of data from each channel.  I acquire 100 samples for each channel then average them and then store to an array. The code I posted previously was only for testing purposes not my actual application I'm working on.

Anyways to reduce code I wanted to compare newly acquired data into an array with previously acquired data using a shift register. Also determine if any of the elements being compared exceed a % of change. I was not sure how to work with arrays in a formula node. My first time actually doing this. Anyways I have figured out how to do it and it appears to be working fine now. Appreciate your interest in helping me out. I've attached a image of the subvi I used to do the job. If you see anything I didn't do correctly , please feel free to offer other advice. Thank you.

 

CompareArrays.png

0 Kudos
Message 8 of 14
(3,665 Views)

Your biggest problem is that you have "An infinite loop"  While "FALSE" exists you cannot process the code past the While Loop.  And, please trust me, FALSE exists!

 

Stop using the "Abort" button to stop your code!  Your code aborts when you press that button!  It does not "Complete" execution. it STOPS! Done! Over, no more calculations nor logic!  STOPS! DING just over-n-done.  

 

On the other side, (Big mistake Number Two) Shift Registers keep data between loop iterations while the vi is in memory.  At times this is a useful side-effect.  Your use case could use an initialization on that Shift Register.


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 14
(3,659 Views)

Jeff,

 

He has it set up as an action engine with the False wired to a Continue? terminal.

 

Brian,

 

Is there a reason you want to use a formula node?  That formula is very simple and can easily work on arrays with regular LabVIEW primitives.

Message 10 of 14
(3,649 Views)