LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient waveform/dynamic data manpulation

Solved!
Go to solution

Hello all.  I am making a program to detect current fluctuations of heater plates.  The program will decide if a heater plate is cycling by detecting the current draw.  If the amps are above a certain threshold, the plate is considered heating.  I am using rising edge detection to determine heat on/heat off cycles.  The program works, although we do have to zero in on the threshold limits to make the program correctly decipher a cycle.

 

My main concern is the efficiency of my method of detecting edges.  I am doing the same decision-making for 12 plates, and as a result I have repeated the same code 12 times.  Is there a better way?  I could put all the 

 

My vis are attached.  The VI named Cycle Count is where I am doing the edge detection.  This vi is the one I wanted to see if I could optimize. 

Download All
0 Kudos
Message 1 of 10
(1,496 Views)

Please ignore the incomplete sentence, "I put all the. . ."  

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

Your subVI is reentrant, so you could use a parallel FOR loop with 12 parallel instances and autoindex.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 3 of 10
(1,478 Views)

That sounds great, but I did read that the Basic Detection VI that I am using advises against using it in a For Loop when manipulating multiple channels.

0 Kudos
Message 4 of 10
(1,374 Views)
Solution
Accepted by topic author Dhouston

I made the mistake of opening Cycle Count first, and wondering "Why didn't he use the Multi- channel version of the Basic Threshold Detection VI?".  Then I noticed that your input, which should have been an Array of Waveforms, was wrong -- it was an Array of (Cluster of Array), which made no sense.  

 

When I did finally open Main, and saw the Dreaded DAQ Assistant and its evil Twin, the Dynamic Data Wire, I understood how you had been misled.  DAQmx, when used as intended, likes to produce an Array of Waveforms, which bundles Time of acquisition "efficiently" into a Waveform Cluster along with the array of data.  Now you can present this Array of Waveforms to the (polymorphic, but that's not so obvious!) Threshold Detection VI.

 

Here's what you do to rewrite Cycle Count so it looks like this:

Cycle Count BS.png

  1. Arrange your Inputs on the left, outputs on the right.  We're going to "operate" on the functions in the middle.  Note that I added the Error In and Out (always a good practice when writing sub-VIs).
  2. Delete Array of Clusters (ignore all the broken wires -- we don't need much of the insides, anyway).  Replace it with an Array of Waveforms (you can find a Waveform Constant on the Block Diagram Waveform Palette, Analog Waveforms sub-Palette).
  3. Find your Basic Threshold Detector VI and delete all its inputs and outputs so that it is a bare VI.  Right-click it, click "Visible Items", and turn on "Polymorphic Indicator".  Change it to "Trigger Detection for N Channels".
  4. Now start wiring your Inputs.  The Level and Hysteresis need to be Arrays, so simply create them, using the size of your Signal In array to initialize an array of the appropriate size.
  5. I made "Reset" a variable, as you only want it to be True the first time you call this function.
  6. Rather than using a Selector to increment (or not) the Cycle Count, I changed the Boolean to 0/1 and simply added it to the Cycle Count.

So how to fix Main?  Here I usually say "Learn DAQmx", but here's a quicker way to "Undo the Damage" -- convert the Dynamic Data Wire to a 1D Array of Waveforms, like this:

Undo the Damage.png

Note that by default, the Convert from Dynamic Data does not use Array of Waveform (its First Choice) as the default, so you'll have to right-click it and choose Array of Waveform.  With all of the changes you made to Cycle Count, you might find that (as I did) you forgot to connect the new Inputs and Outputs to the Connector Pane, so do that, then wire your Array of Waveforms, Level, Hysteresis, and Reset, and enjoy the results.

 

Bob Schor

Message 5 of 10
(1,294 Views)

Thank you.  This is excellent, and is just the kind of code optimization/simplification I need.  Also, I really didn't want to use the DAQ Assistant, but I couldn't get the DAQ Read function to work correctly.  It kept outputting a waveform, which I couldn't get to work with Split Signal, as I kept getting 0 for the Split Signal outputs.  That's another topic for another day, so thank you both for the help here.

0 Kudos
Message 6 of 10
(1,099 Views)

I'm not using LabVIEW 2019 yet so I can't open your file, but you don't need split signal with waveforms. If you have multiple channels then you should have an array of waveforms - just index out the array to get the data from the individual channels.

Message 7 of 10
(1,056 Views)

Thank you JohnRich.  That is good information for me.  This will be very useful for future projects.

0 Kudos
Message 8 of 10
(1,051 Views)

The DAQmx Read should give you a 1D Array of Waveforms, exactly the input I used in my VI.  Each element of the Array is a different Channel, just what you want -- wire it directly into the function I rewrote for you.

 

Bob Schor

Message 9 of 10
(935 Views)

Ah yes, thank you for this.  That worked excellently.  This gives the solution to the issues we have always had with needing to use a DAQ Assistant with Split Signal.  Now we can forego the assistant and have better control of our VI.  Thank you yet again.

0 Kudos
Message 10 of 10
(927 Views)