LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Synchronous Reading and Writing

I am trying to make a Lock-in Amplifier using a USB DAQ device (forgot the product Id). I am facing a problem when I am trying to send the reference signal out and read the voltage drop. The problem is that both are not synchronous. The reading of the voltage is taking place everytime at different time intervals and hence I am getting a varying phase angles between the reference and the voltage signal. I tried connecting the error out of the DAQmx write to the DAQmx Read VI. And another point is that I used the example option to generate the code for the DAQmx Task. My signal out is at 1kHz, 1V and the update rate is 50kHz and 1000 samples. My analog input is done at 50kHz sampling rate and no of samples to read is 1000 (both configured in Measurement & Automation Explorer). I also read somewhere that the reading must be continuous to avoid errors. So I gave the continous reading option '-1'. Is there any way out for this problem?
 
Secondly, when I get those 1000 samples, I multiply them with the reference signal (from sine wave generation VI). And then I pass them through a LowPass Inv Chebyshev Filter with a cutoff freq of 40 and Sampling freq as 50khz. The mean of the filtered output gives mean absurd values. But if I use the default values, Fs=1Hz and cutoff as 0.49 I am getting some proper values. Why is this happening?
 
Thanking You.
Gokul.
0 Kudos
Message 1 of 15
(6,016 Views)

You might want to consider posting in the multifunction daq thread since this seems to pertain to that.

Also, if you post your code or a screen shot it will be easier to understand what you're doing (or not doing).

 

regards,

Drew

0 Kudos
Message 2 of 15
(5,984 Views)

Please check the attachment.

I have included the VI that I am working on wid tis post.

The DAQ card that I am using is USB 6251.

Please help..

THnx.

Gokul.

0 Kudos
Message 3 of 15
(5,944 Views)

Hi Gokul,

The reason why you are getting the phase error is because your AO and AI are not synced in anyway.  Passing an error cluster from one task to the other won't synchronize the actual hardware, it will just force the order of operation, and in your code, the error cluster is being split so its really not even doing that.

Now for the good news.  There are a couple shipping examples that will do exactly what you want.  Under the Hardware Input and Output/DAQmx/Synchronization/Multi-Function folder when you search the examples, there are 2 codes Multi-Function-Synch AI-AO.vi and Multi-Function-Synch AI-AO-Ext Digital Trigger.vi.  These codes are the same except one uses an external start trigger and the other doesn't.  These show the proper way to sync the two tasks.  The synchronization is done by configuring a start trigger for the AO and setting the source of this trigger to be the AI start trigger internal signal.  That is, when the AI starts, an internal pulse will be generated to start the AO.  To make this all work in the proper sequence, the AO task is started before the AI task so that it is ready and waiting for the start trigger pulse.

As for the digital filtering, the code you posted is using the default fs and fL (1 and 0.49) so I don't what values you were wiring to get the error.  One thing about these inputs, if you put 1000 and 490 for fs and fL you will get the same filter response as using 1 and 0.49.  So its the ratio of fs and fl that matters.  In order for the filter to work, the ratio of fL/fs must be less than 0.5 to ensure Nyquist is met.  If you're intended inputs are valid (meet the less than 0.5 ratio requirement) and it still doesn't work, you might want to try lowering the order.

Regards,

Drew

Message 4 of 15
(5,929 Views)
Hi Drew.
Thnx a lot for ur post.
It was really helpful. I was able to sunchronize the ouput and input. I get a constant phase lag of -7 degrees. I guess thats due to the delay in computation that I do inside the loops. And i guess it wil depend on the processor that I am using. So when I am using the VI for the actual data acquisition, I can just add 7 degrees to the phase shift rite? ...
Out of curiosity, is there a way to make it independent of the system used?
Thnx.
Gokul.
0 Kudos
Message 5 of 15
(5,884 Views)

Glad to hear your code is working.

For more info about DAQmx and synchronizing check this link http://zone.ni.com/devzone/cda/tut/p/id/4322#toc4  In your application you might want to also make sure to share the same clock for both AI and AO and there is an example of that.

I am a little unclear about what 2 signals the phase lag refers to.  If you've done the synchronized start correctly, the AI should start the same time the AO does.  For instance, you should be able to read exactly what you are writing.  I don't believe the phase lag has anything to do with computation delays or processor speed since this would probably give a time varying phase lag.  Once the AI has started, it will continue to sample data.  The read function just pulls the data in LV memory to allow for the data processing.  On the next read, you don't read the AO data at that time but rather continue where the last read left off.  If your application is fast enough, then the read function might have to wait a little before reading the N requested samples since they won't be available yet.  If your application is slower, then the number of samples in the buffer will slowly build over time until you might reach the condition where the AI is overwriting old data.

Back to the phase shift.  If you are using a single phase lock-in then to maximize the output you must make sure the reference signal and the measured signal are in phase.  However, to not have to worry about the phase a dual-phase lockin can be used.  the measured signal is multiplied to a sine wave and cosine and then filtered and added in quadrature.  This eliminates the need for knowing the phase of the measured signal.  In your previous code, it looks as if this is what your kind of doing.  However, I don't have the vi you are using to create the reference signals.

You might want to post the new code so I can better understand where the phase lag is coming from.

regards

Drew

0 Kudos
Message 6 of 15
(5,869 Views)
Hi..
I have included the Code that I am using with this post (screenshot. cudnt load tht VI due to some system problems.). Trial.vi is the main VI with trialfunc.vi generates the necessary AO data.
Please tell me from where the phase lag arises. I checked for the phase lag by connecting the Analog Output 0 of the DAQ to the Analog Input 0 of the DAQ. And started the VI. I got the samples properly but I am getting a phase lag of -7 degrees. The Analog Output that I am generating is used as the reference. And how do I make sure that I am using the same clock for both of AI and AO ? And one more thing, to recover the signal at DC I have used a AC&DC estimate VI but is it necessary to use the Low pass filters? Wat are the pros and cons of both?
Thnx a lot.
Bye.
Gokul.
0 Kudos
Message 7 of 15
(5,858 Views)
You can set the clock on the DAQmx timing function.
 
What you will want to do in your case is to leave the AO clock unwired and set the AI clock to be dev1/ao/sample clock.  By doing this, the timing of your code should be this;
 
1) The AO task starts first and waits for a digital trigger
2) The AI task starts and sends a trigger but does not sample since no clock edges are available
3) The AO task receives the trigger and begins AO samples on clock edges
4) The AI task samples on the same clock edges as the AO task thus removing any chance of phase differences
 
As for the filtering for the digital lock-in.  If you're measured signal is a perfect sinusoid (1 frequency), then just the DC component is all you need.  However, a real signal will have some bandwidth around its central frequency and this bandwidth is captured by using a low pass filter with a cut-off set to half the bandwidth of your expected signal.  I would not use the AC&DC estimator.
 
Happy wire trails,
Drew
0 Kudos
Message 8 of 15
(5,822 Views)
Hi..
Thnx for the info.
I tried doing wat u said. But I am facing some problems. I connected to the Source of AI clock the /Dev1/ao0/SampleClock . But dont know how to leave the ao0 clock unwired? When I am just by passing the ao0 clock, I am getting error saying "Write cannot be performed when the auto start input to DAQmx Write is false, task is not running, and timing for the task is not configured or Timing Type is set to On Demand. Set auto start to true, start the task, or configure timing and specify Timing Type other than On Demand." I tried making the AutoStart True. But again I faced some error. How should I leave the clock ao0? I understood the flow you were talking about. But I have a doubt. In step 2 - 3, the ai clock source has been set to be the ao0 clock right? now the ao0 clock will functioning right once I press the start button? Otherwise how will ao0 start once it recieves the trigger? Does the ao0 clock itself starts when it receives the trigger? According the connections I think only the generation starts after the trigger. So I tried connecting the ao0 task to the Digital Edge trigger which I connected to the ao0 clock and then to the Generation VIs. But I am still facing the same problem of phase lags. I am attachin the jpg file with this post please have a look and tell me about wat sud I do with ao0 clock? I understood the info about the LPF and DC Estimator. Thnx a lot.
Bye.
Gokul.
0 Kudos
Message 9 of 15
(5,816 Views)

I believe that the AO task will not start the AO clock until it receives the trigger or put another way, the AO clock that the AI task uses should only be the edges that are actually used for waveform generation thus syncing your 2 tasks.  You have wired the AO task correctly by not wiring anything, it should default to the onboad clock which is what you want.  If it makes you more comfortable you could explicitly set the AO clock to be the onboard clock.

Let me think about this a little more and I will get back to you.

 

Drew 

0 Kudos
Message 10 of 15
(5,798 Views)