04-09-2016 06:22 PM
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
This is the SubVI
This the Main VI
04-09-2016 07:18 PM
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.
04-09-2016 07:30 PM
Thanks, greatly appreciated!
Bryan
04-10-2016 01:15 PM
While you're at it, do somwthing (anything) with that icon before you get into bad habits of leaving the default icon in place.
04-11-2016 08:02 AM
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.
04-11-2016 01:14 PM - edited 04-11-2016 01:16 PM
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
04-12-2016 09:21 AM
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.
04-12-2016 11:44 AM
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.
04-12-2016 12:05 PM
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.
04-12-2016 12:36 PM
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.