LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sample and hold from spreadsheet data

Dear LabVIEW Forum members,

 

I am seeking some assistance with regard to obtaining the best way to sample and hold a data value from a spreadsheet file whilst a Control & Simulation Loop is in operation.  Please refer to my attached LabVIEW vi.

I need to integrate this Control & Simulation Loop with a spreadsheet file of data (data values are in 1 second intervals) and then at a specific trigger point capture (sample & hold) the data value 'W' for use in the Control & Simulation loop.

I want to know the best way that spreadsheet data can be read into a Control & Simulation Loop so that this data can be used at specific times during the run-time of the simulation.

 

Best Regards,

0 Kudos
Message 1 of 6
(2,802 Views)

 Hello Bunnykins,

 

From the sound of it, you are attempting to replace the "W" constant in your simulation loop with a control that is updated from a 1-D array that is stored in a text file - is that correct?

 

If this is the case, you should be able to use the standard file I/O VIs (such as Read From Spreadsheet File.vi) to read from the spreadsheet in question (unless it is in some exotic format that requires a data plugin or similar.)

 

I would recommend importing the file before entering the simulation loop and then handling the resulting array of values within the loop. There are probably dozens of ways to do this- if you could provide a flowchart describing the "hold" mechanism you need, I may be able to offer some advice, but at this time I'm a bit fuzzy on what your requirements actually are- for instance, when we "hold" a value, does this overwrite the next imported values or push them back?

 

Regards,

Tom L.
0 Kudos
Message 2 of 6
(2,751 Views)

Hi Outlaw (Tom),

 

Yes, you have pretty much described exactly what I want to do.  The data is stored in an Excel spreadsheet and I've saved this as a .csv file that can be read into LabVIEW via the Read from Spreadsheet function.  Since posting my original query I have established this function (although I didn't do the reading from spreadsheet outside the simulation loop - how can this be done?).

 

The sample & hold that I mentioned is as you have said, its simply triggered at a particular point (which I can get from the Simulation Time function) and the new value simply over writes the previous value.  'W' being the value held at the trigger point.

 

What I want to do is use the data from spreadsheet plus the controller output (from the Control & Simulation Frame previously posted) to show the expected material hold-up in a hopper.  The data from spreadsheet represents a theoretical dynamic model set data of the hopper material during batch discharge operations whilst the controller output represents the hopper input flowrate.  My end result is the show the hopper mass balance (Hopper contents = Input - Output) over time.

 

Hopefully this explains the application a little better.  Where I need help is in the setting up of the spreadsheet data.  What is the best way to do this? Build an array outside the Simulation Frame?  This is where I'm struggling.

 

Regards,

 

 

0 Kudos
Message 3 of 6
(2,731 Views)

Hello Bunnykins,

 

This KnowledgeBase describing how the function works might get you started:

 

KnowledgeBase 4UAB2OLF: How Can I Import Spreadsheet Files Into LabVIEW Using The .csv Format?

http://digital.ni.com/public.nsf/allkb/C944B961B59516208625755A005955F2

 

The read from spreadsheet file.vi will return a 2D array of the data contained in the .csv file- at that point you can do whatever data manipulation is required for your application.   To read the file outside of the primary simulation loop, you'll just need to move the function outside of the loop. To simplify things a bit, I would recommend using a non-subsystem functional global variable (FGV) to keep track of the array as well as the currently "held" value.  This Community example is a fairly good reference:

 

Community: Communicating between multiple VIs using a functional global variable 

https://decibel.ni.com/content/docs/DOC-20897

 

If you're not familiar with creating FGVs, there is plenty of additional information available via an internet search.

 

Short of that, you should also be able to achieve a similar result using feedback nodes and some selector logic (using the the select function.)  If you're using this scheme it would likely be easier to keep track of the array index of interest than the value itself.

 

I would also strongly recommend posting the code you've already created and pointing out specifically where you are having issues- this will allow people to see what you're trying to achieve and offer advice.

 

Regards,

Tom L.
0 Kudos
Message 4 of 6
(2,718 Views)

Many thanks for the advice Outlaw (Tom),

 

Referring to the attachment - I have now established the 'Read from Spreadsheet' (outside the Simulation frame) and connected this to the Simulation frame and the data can be read & displayed correctly.  I then created some blocks to get a trigger at simulation time = 8 seconds to pick off the data point required for 'W' however I need to convert this from an array to an interger for the simulation part.  This is where the program is faulty.  I don't know if my sample & hold blocks are the best way to pick off the data (from Spreadsheet file) however when tried in isolation it appeared to work.  When I attempted to convert to integer and then connect up to the 'Discrete adaptive control algorithm' (blue line) I've got mismatches in the signals and hence it doesn't work.

 

Any suggestions ?

 

Regards,

0 Kudos
Message 5 of 6
(2,708 Views)

Hi Bunnykins,

 

It appears that you're importing a two-dimensional array, reducing it to a one-dimensional array/vector, and then attempting to connect it to a scalar input.  Note that the "9th row value" indicator is a 1D array.  It appears that you should probably be specifying both a row and column index when pulling data out of your spreadsheet array- I don't know what your spreadsheet looks like or what values you're attempting to pull from it, but it looks like you'll need to reduce the order of the held value to get it to work with your algorithm. 

 

Remember to check the error list by clicking on the broken run arrow!  This will give you more information on why the VI/wire is broken.

 

Regards, 

 

 

Tom L.
0 Kudos
Message 6 of 6
(2,695 Views)