10-05-2015 09:37 PM
01-17-2024 04:39 AM
I see this is a very old thread, but I hope someone sees this and offers the help I desperately need. I am very new to Labview and signal processing. I am getting pressure vs time data from a pressure sensor with a 4-20 mA output. The sensor's sampling rate is 400 hz; I want a sampling rate of at least 200 hz, then apply a median filter and write the output of 1 data point every 10 seconds to manage the buffer size. I tried to replicate what has been advised in this thread, but I get an output of 100 data points every second. Kindly help me fix this. Thank you. Attached is the pressure sensor datasheet and my Labview VI.
01-17-2024 10:24 PM
You can easily accomplish what you want with a pair of simple While loops organized in Producer/Consumer fashion. You'll need to learn some step for this, but I'll try to explain the basic steps.
The Producer Loop consists of using DAQmx to acquire data from your sensor at 200 Hz. Find the NI White Paper "Learn 10 Functions in NI-DAQmx and Handle 80 Percent of your Data Acquisition Applications" (hint -- Web search). Learn how to set up your sensor (plugged into your PC, and tested with a Test Panel using MAX -- you want a Sampling Rate of 200 Hz, a buffer size of 2000 points (or one buffer every 10 seconds), Continuous Sampling (so you don't lose any points). This While Loop, once started, should produce 2000 points every 10 seconds as the output of its Analog Read function (we'll get to what you do with these data in a second). You need a Stop control to stop the Producer Loop whenever you want it to stop.
Now, suppose you could instantaneously transfer those 2000 points to another While Loop that can compute the median of those points and "do something with them". This is your Consumer Loop -- it runs every 10 seconds and plots, saves, or whatever the data you generated. You might, for example, want to do some processing of these data (in addition to taking the median of those 2000 points, which should take a few milliseconds, you might want to do Fourier Transforms, 3-D plotting, who-knows-what, and not worry about mssing some incoming data points).
OK, two independent loops, one producing 2000 data points/10 seconds, the other consuming 2000 data points/10 seconds. How to get the data from Producer to Consumer (and how to stop the Consumer when the Producer stops).
Enter the Stream "Asynchronous Channel Wire" (or the Stream Channel Wire, for short). This is a wonderful feature that made its public appearance with LabVIEW 2016. You right-click on the output of the DAQmx Read (where your 2000-point data appear) and "Create Channel Writer Endpoint", specifying a Stream Channel. 2-4 seconds later, the Channel Writer appears, with the data array going in on the left, and a "pipe" (the design for Channel Wires that can "leap over Structure Edges", such as the output edge of a While Loop to get the data out of the Consumer Loop and into the Producer Loop (which you place to the right of the Producer, so data "flows" from left to right). You now right-click on the Stream Channel inside the Producer Loop and "Create, Channel Reader", specifying a Stream Channel. 2-4 seconds later, there's your connector whose output is the same Array you put into the Producer side, transmitted "instantaneously" (or "Asynchronously") for you to process however you want, without interfering with the Producer.
But how to stop the Consumer? Look closely at the Stream Channel Reader. There is a Boolean input that says "This is the last sample I'm sending" (which is the same Boolean you wire to the Producer's Stop indicator), and a similar Boolean output on the Channel Reader that says "Last Sample" that you can wire to the Consumer's Stop indicator. The Producer (who knows about whether or not more data are coming) tells the Consumer explicitly whether or not more data are coming, and both stop together. Very clear.
Try it. You'll like it.
Bob Schor
01-18-2024 09:36 AM
I can't believe Bob-Schor responded to my message. I have been following the detailed help you provide in the NI community and was hoping you would help me. I am very very grateful for this detailed steps you have provided, you are a life saver. As I am not conversant with Labview, it may take a while to implement and get it right, but I will reply again when I get it right. Thank you so much.
01-18-2024 06:04 PM
I tried to use the producer-consumer loops and the channel wires like you adviced. I keep getting an error that says, "TDMS Close: Contains unwired or bad terminal." I have looked at the VI over and again and can see what I have done wrong. Can you kindly advise on this? Attached below is my new VI. Thank you so much.
01-20-2024 10:36 AM
Sadly, I cannot open your VI as I am using LabVIEW 2019 and LabVIEW 2021. But do not despair -- open your VI in LabVIEW 2022, then click the File menu and choose File, Save for Previous Version, and choose LabVIEW 2021. It should make you a Folder that contains your VI in a version I can open, and possibly other VIs that it calls. Right-click the Folder, choose "Send to", and select "Compressed (zipped) Folder". Attach the .zip file and I'll have a look.
Bob Schor
01-20-2024 12:04 PM - edited 01-20-2024 12:05 PM
Thank you so much Bob for your kind response and help. I did as advised and attached below is the zip folder with the Labview 2021 files. Thank you again.