03-14-2011 12:07 PM
Hello people,
I've been given at the last minute a project at school where I need to do some data acquisitions (tensions) with a DAQ NI USB-6218 and it has
been miserable ever since, I first tried the "easy" way with DAQ assistant to save a given number of samples per channel to a text file
in order to use it in matlab, well...it isn't working : every time in my text file I have a different number of samples, I used the "Write to spreadsheet" function within a while loop where I wired the path outputs to a shift register in order not to have it asking me the path all the time,
but I'm still not getting the X number of samples per channel as specified at the beginning.
So I've been using another method with the DAQmx where I get each individual waveform into a vector of samples, when I look for the size
of the vector it looks Ok, 100 in my case but the problems start when I try to have a text file where each column will represent a channel for
subsequent matlab treatment, what I'm doing doesn't seem to be working, it's really unbearable, please help me sort this mess out.
I'll add both VIs as attachment so it can help you help me, thank you.
Basically what I need is to acquire 15 tensions with a given number of samples per channel (the same for each channel) and then plot it in matlab.
Note the first VI has switches to "unblock" each channel but it doesn't seem to be working, please look at both VIs.
It's very urgent, I could fail my school year if I fail this project.
Thank you very much for your help.
03-14-2011 03:58 PM
Please I need your help,...It cost me a lot, I really need your support.
Thank You.
03-14-2011 04:31 PM
Voevoda,
I will comment on 'Project EM acquisition - Copie.vi' as the other had a missing subVI so I could not tell how you had configured your DAQmx task.
In this VI, you have the DAQmx Assistant configured to read 60 kSamples on 15 channels. You then take this data, and Convert From Dynamic Data. However, you are converting this into a 1D array of scalars. This doesn't make sense. You should have 60 kSamples from each of your channels. My guess is that you need to convert this data into a 1D array of Waveforms (in this case each element of the waveform array would contain the 60 kSamples for each channel), or a 2D array of scalars (where the data from each channel would be stored in either one row or column of the 2D array).
If you can post the missing subVI from your other attachment, I can take a look at that as well.
Dan
03-14-2011 04:42 PM
Voevada,
One other issue I see with your VI. You are requesting 60 kSamples at a rate of 1 kHz. I would expect you'll see a timeout error if you don't use something other than the default value of the 'timeout (s)' input to the DAQmx Assistant. This will need to be >= 60 s.
Dan
03-14-2011 05:35 PM
Hi Thank you very much for your help, in the meantime, I've changed the project to (see attachment), now
it is at least writing the waveforms to the txt file, but again there is an another problem, it seems to be ignoring the
number of samples I specified per channel, it seems to be writing into the txt file for as long as I keep the VI running.
What is missing ? Also I'd like to have a clock for my samples, that is when I plot in matlab I do not just plot random numbers, but the
physical analogical inputs as a function of time, that is for instance the first line corresponds to time 0, line 2 to time 0,001
ect...How could I do that ? For the meantime I got only 5 channels, when I know what my mistake is, I'll expand it to 15 channels.
Please help me.
03-14-2011 05:58 PM
It is not ignoring the number of samples. You requested 5000 samples and each time the Write to Spreadsheet is called, it writes 5000 rows with 5 columns. I don't think you understand at all what number of samples really means. Explain what you really want to sample and what you really need to write.
It writes to the file each time because that is what you have programmed. You have the Write to Spreadsheet in the same loop so of course it will keep writing.
It's also expected that there is no time information. You removed all of it by the conversion to the 2D array. You could have kept everything simpler and just wired the data from the DAQ to a Write to Measurement File. You could also have done what was suggested earlier and converted to waveform data type and used the Export Waveforms to Spreadsheet File.
03-14-2011 07:02 PM
Hi,
Thank You, "Write to measurement file" seems to be working; indeed I got the data and the time information and it's actionnable in matlab,
unfortunately when I increase the sampling frequency it seems that the indicators on the screen do not show the tension variation in real-time
as well as before, well I can do without real-time on screen data output, but do you know if there is a way to have BOTH, that is a high number of samples per channel (e.g. 10000) and a fluid real time showing of the data on the front pannel indicators ?
Here's my corrected VI, I removed "Write to spreadsheet file" in the while loop and made it simpler by using the built-in VI : "Write to a Measurement file".
03-15-2011 09:22 AM
Voevada,
Have you taken a look to see what the waveform data type is? It is a type made up of several components... you are ignoring these and wiring them to indicators of single floating point numbers, when instead the waveform data type contains an array of doubles. If you read 1000 samples, then this array will have 1000 elements. However, when you display this as a single floating point number, LabVIEW appears to simply pick the first element of this array to display. This means that you are only displaying 1/number of samples of your data. To make this display more meaningful, you could place a waveform graph on your front panel. This indicator is designed to correctly handle an array of data types, and will display all the data read in a reasonable manner. I don't know of a better way to visualize 1000 samples at a time.
Additionally, your VI does not appear to do any error handling. You might want to pay attention to the error output of the DAQ Assistant VI. As configured by default, I was getting timeout errors when DAQmx was trying to read data. It is best not to ignore these.
Dan
03-15-2011 09:54 AM
And now you are recording only the very last acquisition. I also don't see the point of acquiring so many samples and then displaying the data as a scalar (your numerical indicators). Why aren't you displaying the acquisition in a graph. Or, if you want scalars, why take so many samples? It's also much smarter, in my opinion, to request fewer samples at a time. As I said earlier, I don't think you have a basic understanding of number of samples and the relationship to sample rate. Why would you want to wait 20 seconds for each acquisition? You could easily change the number of samples to 500, get a reading every second, and run the loop for 20 seconds. Much more responsive and the same amount of data.
03-15-2011 11:28 AM
Ok, I'll try to understand what's wrong, even though I'm surprised, I mean it seems I get a text file at the end with the number of samples
I wanted per channel, it's true my understanding of labview programming is poor in some aspects, I really got this assignment very recently, here I add a vi for a previous version of labview that does for another DAQ type (PCI 6133) what I'd like to do for my NI USB-6218, could anyone send me a VI that does what this one does for NI USB-6218 ? except that it has 15 channels ?...or better it might be that someone has already had the same task as me, that is record 15 tensions with a given number of samples that the user sets, I know my
problem seems weird but it has been really unexpected for me this task to make a labview project at this moment.
Please I need your help, time is running out for me.
Thank you,