LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Questions on synchronization between analog input and output

Solved!
Go to solution

Hello everyone,

 

I now have a simple task that is feeding a voltage signal(from PXI ao0) to a circuit and then feedback a voltage across a component, for example say one of the resistors in the circuit, through ai0 on the PXI. So in this case, synchronization between analogue input and analog output need to be performed to avoid any phase shift error.

 

I tried to build my VI by learning this example: https://decibel.ni.com/content/docs/DOC-3882 

However I have a few questions.

 

1. I noticed that there is a merged error fed to the "start task"sub VI for analog output.  What is the point of merging error?

 

2. I have attached my VI (also as shown below) for voltage output. I put my DAQmx write subVI in the while loop so that I can change the voltage while the VI is running.

AC.png

However, in the example, the author put the read outside the loop, and even before the start task. What difference will it make?

 

3. I also attached my synchronized VI. I still put the wavegeneration and DAQmxwrite in the loop. An error keeps popping out saying about samples being unavailable and it needs a higher sampling rate or longer waiting time. What causes this?

 

I would appreciate if these problems can be sorted out. Thank you everyone.

Download All
0 Kudos
Message 1 of 11
(4,131 Views)
Solution
Accepted by topic author pokenan

1) First you need to start acquisition task, it will wait for trigger to arrive. Then you start generation task that provides this trigger. Otherwise acquisition might skip trigger and never start.

3) First you need to write something into buffer (DAQmx write), only then you can generate it (Daqmx Start). 

Check Cont Gen Voltage Wfm-Int Clk-Non Regeneration.vi in Help -> examples for example.

 

Message 2 of 11
(4,102 Views)
Solution
Accepted by topic author pokenan

pokenan a écrit :

Hello everyone,

 

2. I have attached my VI (also as shown below) for voltage output. I put my DAQmx write subVI in the while loop so that I can change the voltage while the VI is running.

AC.png

However, in the example, the author put the  read  write outside the loop, and even before the start task. What difference will it make?

 


As Alexander said, the Write.vi writes the data to the internal buffer. In countinuous output mode the output will always regenerate the buffered data. If you put the Write.vi inside the while loop you should put a write node (before the StartTask vi) and set the Regeneration Mode property to Do Not Allow Regeneration to avoid glitching. Also use a Channel node to set the Data Transfer Rate Condition (probably to Onboard Memory Empty in your case but you will have to try the different values). Have a look at this document on the subject.

 

You should also put a Write.vi before the loop to make sure data is available for the Read.vi in the first loop iteration. I would also try adding a DAQmx Is Task Done.vi after the Write.vi inside the loop.

 

Ben64

Message 3 of 11
(4,064 Views)

Hi Alexender,

 

So in the VI I built, generation actually begins in the second interation because there is nothing written into the buffer in the beginning of the first itteration and they are actually written in the end of the first iteration. Can you please tell me if my understanding is correct?

 

Many Thanks

Junjie Tu

0 Kudos
Message 4 of 11
(4,035 Views)

Hi Ben64,

 

Can you please tell me why there will still be a continuous output even the writing has been done before the loop? I checked the example that Alexender posted and its writing is put inside the loop.

 

Sorry for frequent questions. I just started learning LabVIEW a couple of days ago.Smiley Tongue

 

Many thanks

Junjie Tu
 

0 Kudos
Message 5 of 11
(4,024 Views)

pokenan a écrit :

Hi Ben64,

 

Can you please tell me why there will still be a continuous output even the writing has been done before the loop? I checked the example that Alexender posted and its writing is put inside the loop.

 

Sorry for frequent questions. I just started learning LabVIEW a couple of days ago.Smiley Tongue

 

Many thanks

Junjie Tu
 


When Sample Mode is set to Continuous and Regeneration is allowed the content that was initially written to the buffer will contuously be outputted (no need to write at every iteration). Note that you are not writing to the output, the content of the buffer is only outputted after you start the task.

 

Ben64

Message 6 of 11
(4,001 Views)

>> So in the VI I built, generation actually begins in the second interation because there is nothing written into the buffer in the beginning of the first itteration and they are actually written in the end of the first iteration. Can you please tell me if my understanding is correct?

Not really... . 

Nothing is in the buffer when task starts (before the loop), so it can not start - task is not running. It is not writing into buffer on the first iteration, because on the input there is an error.

If you clear error after Start task (or remove it as it is not functioning),  it will write into buffer on first iteration. Then you need to start task (once) - to initiate real generation. To continuously update data in the buffer (to write after start) you need regeneration mode.

 

>> I checked the example that Alexender posted and its writing is put inside the loop.

On the first iteration of the loop first it writes into the loop. Then goes case structure that checks if it is the first iteration and starts the task (initiate generation). 

Non-regeneration mode means that it will wait for new data when finished generating old ones rather than starting original data from beginning. You have to write data continuously.

Message 7 of 11
(3,966 Views)

Correcting myself

>> Non-regeneration mode means that it will wait for new data when finished generating old ones rather than starting original data from beginning.

It will not wait for new data, it requires new data and will give an error if does have them.

Late DAQmx write will report the error you have seen (task late, write faster). I can not check now, but as far as I remember, you can not ignore error: it will stop task and you will need to restart it to continue writing. 

Message 8 of 11
(3,943 Views)

Hi Alexander,

 

Thank you very much for your reply.

 

Another question, you said in the sychronization example, the point of merging errors and feeding the merged error to "start task" for generation is to let the acquisition start first. Can you please explain further? I do not really get it why connecting errors can do this. Also I noticed that there is no "task in" connected to "start task" for generation. How does it still start the task of generation?

 

Sorry for frequent questions.

 

Many thanks

Junjie Tu

0 Kudos
Message 9 of 11
(3,928 Views)

pokenan a écrit :

 

Another question, you said in the sychronization example, the point of merging errors and feeding the merged error to "start task" for generation is to let the acquisition start first. Can you please explain further?

 

I do not really get it why connecting errors can do this. Also I noticed that there is no "task in" connected to "start task" for generation. How does it still start the task of generation?

 

Sorry for frequent questions.

 

Many thanks

Junjie Tu


The Merge Error vi is used to insure dataflow. In this case it insure that the analog input task is started before the analog output task. It you don't use it between the lower write ans start task you will have a race condition, meaning there is no way to know which task will start first. You start the analog input task first to avoid missing the first data outputted by the analog output task.

 

The missing Task in connection for the analog output generation is an error, it should be connected to the output of the lower DAQmxWrite.vi.

 

Ben64

Message 10 of 11
(3,910 Views)