Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx feedback loop

Solved!
Go to solution

Hello,

I am writing a VI in which an initial Voltage output signal (e.g. 10 cycles of a sin wave) is sent into an electronic device. At the same time, another channel reads the voltage. In the next iteration of a loop, I want the voltage signal recorded from the read to be written to the output of the original channel, such that input becomes output and so on.

 

Here is my vi at present, it works only in the most generous sense of the word, but I get a couple of errors that I cannot seem to fix.

 

Initially, the first iteration is recorded without a problem, but then in the read portion i get error -200279, then error -200462 in the write portion. These are tied to overwriting data in the input buffer, and an empty output buffer, respectively.

 

Attached is my .vi. Any words of advice or encouragement?

 

Thanks so much!

0 Kudos
Message 1 of 6
(4,120 Views)

Hi gimNPC,

 

I have a couple of suggestions for your code to help eliminate those errors.  First, you do not need the shift registers on the tasks that go through the while loop, you can remove these from both task lines.  It will also be helpful to remove the DAQmx Stop and Wait before your DAQmx Write in the while loop.  The stop should be done outside of the while loop.  On the top task, your configuration should be set to continuous samples, not finite samples.  Lastly, you should remove the DAQmx Sample Clock in the second task, this will cause problems between the two tasks.  I hope this helps!!

 

Regards,

Kira T

0 Kudos
Message 2 of 6
(4,089 Views)

Hi Kira,

 

THanks very much for taking the time to help me on this.

 

I've applied the changes and attached my latest version. The VI runs with no errors (although a warning 200015); I cannot tell if it has worked because I get the cryptic "error -2525" (cannot convert specified file format or something like that) whenever I try to read or convert the tdms. Any ideas on what causes this?

 

I also have another important question: what is the reasoning behind all your changes? Through a process of trial and error I made version 1_0, and found that every part was necessary to get it to work. For example, I tried it without the daq wait/stop vis, but the initial output sign became badly truncated, possibly because the next loop iteration started before all the samples were read. The only problem seemed to be that a rather small portion of the initial output was truncated, so the result was a sort of sin wave with a chunk cut out. I'm just trying to get a better feel for labview, for when the documentation doesn't satisfy me!

 

Thank you,

gim 

0 Kudos
Message 3 of 6
(4,081 Views)

Hey,

 

Here is some of the reasoning behind the changes that I suggested you make:

  • You do not want the DAQmx stop inside of a loop because it is not necessary to stop and then restart a task every time the loop executes and, since there was not a start task in the loop, the analog read is try to take samples on a task that is not running.
  • The shift registers are not necessary because the task is going to be identical leaving the loop as it was entering so there is no need to rewrite this every time the loop executes. You need to configure the acquisition type as continuous because you have the read inside of a while loop and thus you want to continuously acquire data.
  • The sample clock on the second task was causing problems with the size of the buffer and the number of samples/rate you were trying to acquire.

For the TDMS error, I would suggest removing the DAQmx logging and do log your TDMS file as the program runs as part of your while loop.  I have made some other modifications to the VI that I have attached below.  Hope this helps!

Message 4 of 6
(4,058 Views)

The error code -2525 means the data type convertion failed, like when you storing the data values as string data type in the channel, but you require to read it as double values, the data type convertion would fail. 

Message 5 of 6
(4,050 Views)
Solution
Accepted by topic author gimNPC

Okay thank you both Kira T and Yongqing Ye for helping me through this, and I think I have arrived at a solution that I wanted to post in case it helps other people with their projects.

 

Kira, I took your vi and, as suggested, exchanged the data logging for a manual .tdms data logging and that solved the problem of error 2525. However, when I looked at the data (see data1.jpg), there were 2 immediate problems:

 

The beginning of the initial sin wave was being clipped off. I attributed this to the fact that the first Daq write task begins before the read one inside the loop, so the first bits of the sin wave passed through the system before the read task could begin. I fixed this by placing the start task for the write vi inside the while loop, in a case statement that would only run on the initial iteration. Now the write and read tasks were synchronized.

 

The second problem is quite strange - it seems that only a portion of the data in iteration "i" is fed back into the write task for iteration i+1, and so the signal becomes progressively slowed down or magnified with each iteration since the write task writes a progressively smaller chunck of the initial sin wave. Through trial and error I found that by re-introducing the timing vi on the read task, this problem was solved.

 

In feedback v1_3. The desired effect is achieved: as the signal is fed back on itself the noise level increases steadily with each iteration,and there does not appear to be clipping or truncation of the sin wave.

 

Thank you both once again for your help!

-gim

 

Download All
0 Kudos
Message 6 of 6
(4,039 Views)