07-16-2009 12:18 PM
I have the following task to finish:
1) Periodically every 1 second acquire one (or more) sample of data from two Ai channels
2) Write 6 consecutive periodic measurements into one row with a timestamp at the beginning. In such situation will be a total of 12 readings (two Ai channels every 1 second for 6 seconds) and the time stamp, total of 13 columns in one row.
3) Write next (following) sequence of next 6 measurements into a second row with a timestamp at the beginning (append to file), and so on.
Additionally, for very large file, a sequence of 12 or 18 measurements in one row is required.
How to modify attached file? or any other solution.
I have another version of this file with “Write to Text File” (spreadsheet format) kipping a file continuously open through entire test.
Equipment:
DAQ-6221 (37 pin)
LabView 8.6.1
Tks.
Solved! Go to Solution.
07-16-2009 12:45 PM
You are going to have to make quite a few modifications and futher define some of your requirements.
First thing to change is to place the DAQ configuration functions and stop task outside the loop. There is no need to repeat all of this with each loop iteration. Second, you say that you acquire one or more samples but want 12 columsn every 6 seconds. The VI is currently set to acquire 2048 samples per channel so you can't save all of that data into 12 columns. You could take the mean of each channel and save that. Third, you have nothing in the program to take samples every second. Use the Wait (ms) or Wait Until Next ms Multiple to control the acquisition rate. Fourth, you are going to have to monitor the iteration count to determine when to save the data. You can use the Quotient & Remainder to do the save every 6 times. Fifth, you are going to have to modify how you are creating the data array. You should use a shift register so that you append new elements to the end and at the sixth iteration and after the file write is done, clear the array in the shift register. Lastly, I think your method of saving the data is confusing. You will have one row with a single timestamp but the different columns will actually be acquired at different times. If you write an analysis program to handle that, it will be fine but anyone looking at the raw data will be totally confused.
07-16-2009 02:00 PM
Hi Dennis
This program works, tested with PCI-6221. It writes time stamp, Ai0 and Ai1 in a row.
I used “While Loop” to get readings at a time when trigger from the Co0 is fired (1 per second). Trigger is internally connected to the output of the counter (see notes on “Block Diagram”). I do not have clearer solution.
Settings have to be reentered, for some reason, the software “SAVE” function does not save new settings, I do not know why? It saves only some arbitrary settings.
I need only two analog channels, Ai0 and Ai1 with only one sample per Ai channel. If program runs with multiple samplings it writes only time stamp, Ai0 and Ai1 as single values in the same row.
The counter Co0 is responsible for taking sample every 1 second (Ai0 and Ai1), (wired internally).
Both circuits, Ai and Co are running simultaneously. Probably they should be connected somehow (error lines ?).
They are 6 sequential events (one group) which are monitored over long period of time and one timestamp is more transparent.
I do not have experience with shift registers and data arrays; can you provide more details how to do it?
Tks
07-16-2009 03:07 PM
By settings, I assume you mean the values of the front panel controls. What is saved is not at all arbitrary. The default values of the controls are saved and you must have changed the defaults at one time. To make new defaults, make the changes and then go to Edit>Make Current Values Default.
Look at the attached code. On iteration 0, the timestamp and two data points are appended to the array. Iterations 1 through 4 append just the new data. Iteration 5 appends the new data and then clears the array.
07-17-2009 10:32 PM
Hi Dennis
You are a brain.
You were right from day one. I removed the large “While Loop” and now trigger is working properly. Your code is doing exactly what I need it.
If the trigger is activated everything is working well.
Just only one observation, if the circuitry is idling for more than 10 seconds (DAQmax Read TimeOut default setting), it writes empty spaces instead of measurements, whole row every 90 seconds.
My entire project is far from finish. My next dilemma is how to create digital array with (1s) and (0s), writes it into DAQ max Write as a data and generate pulses by a digital output(s) shifted in time compare to mutual clock with fixed duty cycle, similar to pulse width modulation.
Probably, I am going to post another “Please Help”.
This task is SOLVED.
Thank you very much Dennis, you saved me a lot of time! I own you at least a bear, a good one!
Tks.
07-17-2009 10:45 PM
behappy wrote:Hi Dennis
....Thank you very much Dennis, you saved me a lot of time! I own you at least a bear, a good one!
Tks.
If it's all the same to you, I'd rather have a beer.
10-22-2009 09:41 PM
Hi,
This solution is very helpful to me. Thanks for it.
However, I encountered difficulty when I tried to output multiple samples. Is there any solution if I need multiple samples instead of only 1 sample?
Thank you very much 🙂
Kid
10-23-2009 11:01 AM
You can just change the Analog Read to be N Channels N Samples. Just be aware that when you use build array it'll generate a 3D array. It's simply a matter of manipulating your data appropriately to get it into 2D type before writing to Spreadsheet.
You could break up the data into separate shift registers for each channel, or do it before writing it, or whatever.
10-25-2009 09:53 PM
Hi Jeff,
Thanks for your reply. Do you have any examples or reference on how to achieve this?
I am totally new to LabVIEW and I really appreciate that if there are some examples on this.
Kind Regards,
kid
10-26-2009 02:34 PM
Hi,
Something like this is I think what you're looking for.