Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Repeated synched AI and AO

Solved!
Go to solution

I am new to LabVIEW so any tips are appreciated! I am using the NI USB-6343. I want to generate a sine wave of known phase and frequency and feed that output back to analog input. I want to collect 1000 samples 100 times using the same base signal but different noise. I broke the challenges down into two separate VI's. One to sync the AI and AO and one to average out all of the signals and will combine these into a final VI once I can get them both working.

 

1) How can you sync the AI and AO with a repeated finite reading? I have looked at all of the examples online but can not seem to get anything to work with my specifications.

2) How do I average out multiple readings from the DAQmx? When I average everything I get 0 which makes it seem I am averaging every point on the wave rather than each wave with each other.

 

I have attacked both VI's (flux_data = averaging, flux_data_test = attempted combination). Thank you for any help and apologize for any confusion in my explanation.

 

0 Kudos
Message 1 of 9
(2,066 Views)

Sorry if I you have done any of the below, I have not looked at your vis, your LabVIEW version and mine are too far apart. 

 

1 - Have you tried using the DAQmx read and write vis? These allow for you to set a finite number of samples to be in/output

2 - One way to accomplish this would be to export all of the signals to separate arrays, add them, and then to divide them afterwards. Or you could add your signals on top of each other for each reading if you know they should be in the same position for each loop.

Message 2 of 9
(2,031 Views)

Likewise, I can't open your LV 2019 code either.  A lot of us out here aren't "instant adopters" of the latest version as soon as it comes out.

 

For each of your vi's, go to the File menu and choose "Save for Previous Version...".  I for one need 2016 or earlier, but I'd recommend going back even farther to get the maximum possible eyes on your problem.  Maybe 2013 or 2014?

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW?

(Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).


0 Kudos
Message 3 of 9
(2,027 Views)

@TristanMayne wrote:

 

1 - Have you tried using the DAQmx read and write vis? These allow for you to set a finite number of samples to be in/output

2 - One way to accomplish this would be to export all of the signals to separate arrays, add them, and then to divide them afterwards. Or you could add your signals on top of each other for each reading if you know they should be in the same position for each loop.



Yes, this is the approach I tried! Thank you for the response, I messed around with the code a bit more and think I might have gotten it pretty close to working. I am a little confused on differential vs. RSE. It seems like I want to do differential but I'm not sure how to configure the actual physical channels (if possible).

 

I attached a screenshot of my updated VI's just in case anyone else wants to look at them.

Download All
0 Kudos
Message 4 of 9
(2,021 Views)

@Kevin_Price wrote:

I'd recommend going back even farther to get the maximum possible eyes on your problem.  Maybe 2013 or 2014?



That is good to know in the future. I just started using lab view and hadn't thought about version control. I attached images in a separate response but I tried to attach the newly combined code with an old version

 

I believe synching is working or nearly working. I think my main issue is not averaging the arrays correctly now.

0 Kudos
Message 5 of 9
(2,020 Views)

Not sure if I should start a new thread instead but I figured out my issues in more detail...

 

1) The averaging was showing as a line because the dt changed from 0.001 to 1 and I had my graph only showing from 0-1 so it only showed 1/1000 of the signal. This isn't very important but I'd like to figure out away to readjust dt to .001. Also the time seems to become absolute instead of relative. Is there a way to avoid these two adjustments?

2) The amplitude given by averaging is slightly lower than I would expect. My guess is it has to do with how I initialize the array but I'm not sure how to change that or if that even is the source of the error.

3) The synching is working however when I read in 1000 samples I get what looks like 8 partial readings stitched together.

 

Hopefully the attached VI works.

Download All
0 Kudos
Message 6 of 9
(2,012 Views)

The good news is that the DAQmx hardware sync actually looks correct.  AO is triggered by the start of AI and AI is started last.  The bad news is the rest of this post.

 

I'm among the grumpy old-schoolers who generally *hate* to see "Dynamic Data" wires (thick darkish blue) and most Express VI's that tend to be responsible for creating them.  Both tend to be opaque and ambiguous, two qualities I try to *avoid* in a visual language like LabVIEW.   I *highly* recommend you work to get rid of all instances of Dynamic Data and use only more strictly-defined types like arrays or waveforms.

 

Ok, rant over.  As to your problem with "dt", I promise the "dt" value in the waveform you read with DAQmx Read will be correct.  But from there you:

inside the outer For Loop

- convert to Dynamic Data in an Express VI that implements a filter

- convert to 2D array for cumulative summation (P.S. have you verified the correct #'s of rows and columns here?)

 

outside the For Loop

- convert to Dynamic Data

- immediately convert back to 2D array (?!?)

- immediately convert back to Dynamic Data (?!?!?)

- feed into a measurement function that wants a waveform input

 

That's a *lot* of opportunity for things to go wrong.

 

Not sure what you expect for an average -- you seem to be generating the sum of 3 uniform noise distributions with 0 amplitude.  What do you expect to measure when you generate 0?

 

Can't comment on "8 partial readings stitched together" - no graph or data to illustrate.

 

 

-Kevin P

 

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW?

(Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).


0 Kudos
Message 7 of 9
(2,008 Views)
Both tend to be opaque and ambiguous

This is maybe the first question I should have asked. As a newbie the dynamic data has been very confusing but I wasn't sure how to deal with data types so I just tried to deal with as it was. Any specific advice on how to adjust would be helpful. Despite lots of googling I am still confused on how to interact with the data and what data type is best.

 

Not sure what you expect for an average -- you seem to be generating the sum of 3 uniform noise distributions with 0 amplitude.  What do you expect to measure when you generate 0?


The 0 for noise is just temporary. Once I get the data handling figured out I am planning to change that value so that there is actually noise. Sorry for the confusion.

 

Can't comment on "8 partial readings stitched together" - no graph or data to illustrate.


I have attached images that hopefully make this clear. Original is the sine wave I generate within my code. Data is the initial data using AI. Average and Filtered are irrelevant for this part as they just show the data processing.

Download All
0 Kudos
Message 8 of 9
(2,006 Views)
Solution
Accepted by curious_frog

Tip:  going forward, it's going to help if you at least add a version # to your filename to help distinguish different versions of your code.

 

1. Not all the 1000 samples of sine wave data you create and graph as 'Original' makes it all the way to DAQmx Write.  The unwired inputs of your noise functions default to 128 samples.  The special In-Place structures favor the dataspace of the 128-sample noise waveforms over the 1000-sample sine wave.  So you end up keeping only the 1st 128 samples of your sine wave.  You should wire the noise functions with the correct # of samples (1000).

 

2. Apparently you have your AO channels looped back to AI channels so you can measure your output using an AI task.

 

3. You've told AO to generate 1000 samples but only defined 128 values.  It (apparently) decides to go into regeneration mode and repeatedly regenerate those 128 values until a total of 1000 samples have been generated.

 

4. The AI measurements are telling the truth.  You keep generating and measuring the first ~1/8th of your sine wave.

 

5. There's no need for the "Wait (msec)" function in the loop.  The loop can't iterate until all the DAQ functions are done, which will take a full second for sampling plus a little overhead time.

 

6. Advice on avoiding Dynamic Data:

  • replace the Express VI for sine wave generation with the equivalent waveform-based function (in the palette under Signal Processing-->Wfm Generation)
  • replace the Express VI for filtering with the equivalent waveform-based function (in the palette under Signal Processing--> Wfm Condition-->IIR Filter Wfm)

 

7.  There's still a little work to do b/c you're presently accumulating data sums in a 2D array in preparation for averaging while I've been steering you toward waveforms for most functions.  Here's my recommendation:

- initialize to have 3 rows and 1000 columns full of 0 values (right now you're doing 1000 rows and 3 columns)

- convert your 1D array of 3 waveforms to a 3 row by 1000 column 2D array of DBLs using For Loop auto-indexing.  Like this:

autoindex wfm to 2d.png

 

8. I'd retain the "dt" information from a waveform and pass it out of the loop for use in later functions that need waveform input, such as the one you're using "Amplitude and Levels.vi"

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW?

(Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).


Message 9 of 9
(1,995 Views)