LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx: write a finite number of samples in a loop but timing is not respected

Solved!
Go to solution

Dear Community,

 

I'm trying to write a huge waveform (tens of minutes to hours).

In practice, I creat a small waveform representing a minimal pattern that I repeat N times to correspond to the huge waveform.

Here are the different steps:

1- create the small waveform

2- write the waveform

3- within a for loop:

     - Start task

     - Wait unitl the task is finished

     - Stop the task

     - repeat n times

 

 

The problem is that the sequence Start/Wait/Stop seems within a loop seems to slow down the process and the timing is not as expected:

 

Finite.PNG

 

Could you help me please?

Best regards.

Sébastien

0 Kudos
Message 1 of 13
(3,869 Views)

Here is a simple example of what I did:

 

Front Panel.PNGDiagram.PNG

0 Kudos
Message 2 of 13
(3,853 Views)

You do not want to stop/start the task inside the loop.  A DAQmx Write Task (if configured correctly) is designed to be "self-clocking".  Here's the basic idea (a few details might be wrong in practice/implementation, but this is how it works in principle):

  1. You specify the DAQmx Write Task, including the Clock Rate, Number of Samples, and set it for continuous sampling (because you do not want to "pause" even for a nanosecond between the first "buffer-full of samples" and the second, until you've output all gazillion samples).
  2. You generate (in a sub-VI) the first aliquot (say, 1000 or 10,000 samples) of your Waveform.  The assumption here is it takes much less time to compute the values for the next aliquot than it does to send them out through the DAQ device.
  3. In a While Loop, you do the following:
    1. Output the Aliquot, brought into the While on a Shift Register (from the Initialization in Step 2), using a DAQmx Write, N Channels, N Samples (you must use N samples, and be sure to wire N into the DAQ Write)(if you are only outputting 1 Channel, of course, you'd use 1 Channel, N Samples).
    2. On the Error Line just after the DAQmx Write, use your sub-VI to generate the next Aliquot, and put it on the Shift Register for the next time though the loop.
  4. The first time through the Loop, the DAQmx Write will immediately start outputting Samples.  Once it gets going, it will "finish" (even though most of the points have not been output) and allow the Aliquot Generator to run, generating the next sample.  This first loop will take very little time.
  5. But the second time through the loop, the DAQmx Write will block, waiting until it finishes outputting the first Aliquot.  Once it has, it will accept the second and continue outputting, without missing any time, and start generating the third Aliquot.  The DAQmx Write acts like the "clock" for the While loop, a clock that is independent of the PC's clock.

Give it a try.

 

Bob Schor

Message 3 of 13
(3,844 Views)

Dear Bob,

 

Thank you for your answer.

It seems that I have something to learn!

As all of my aliqua=ots of samples are identical, I just generate them once.

Then I write a first set of samples then start my task and then, in a loop, I write the N-1 aliquots of samples.

But, this is not the solution, so I missed Something in your exmplanation, sorry.

 

 

Front Panel.PNGDiagram.PNG

Sébastien

 

 

0 Kudos
Message 4 of 13
(3,830 Views)

I cannot examine, test, modify, probe, etc. a picture.  Attach your VI (or, if part of a LabVIEW Project, consider compressing the folder containing the Project and attaching the resulting .zip file).  You'll help all of us to help you.  Remember this for your next post.

 

Bob Schor

0 Kudos
Message 5 of 13
(3,818 Views)

Sorry, I was too busy at work... Here is the testing code, for Labview 2016

 

0 Kudos
Message 6 of 13
(3,781 Views)

Dear all,

any answer?

Séb

0 Kudos
Message 7 of 13
(3,720 Views)

I tried with a while loop  but once again, the time spent is not the expected time.

Thank you.

Séb

0 Kudos
Message 8 of 13
(3,713 Views)

Hello, Séb.

 

     I've not done much digital signal generation in LabVIEW with DAQmx, so don't have code of my own to share.  Have you looked at the Examples that ship with LabVIEW?  There's one called "Digital - Continuous Output" that has a lot of "bells and whistles" (meaning "other code that shows off all of the possible modes"), but which looks pretty simple to try out.  

 

     I don't know if you are familiar with the Examples.  Here is what I suggest:

 

  1. Open LabVIEW.  Go to Help, Find Examples.
  2. Go to Hardware Input and Output, DAQmx, Digital Output, Digital - Continuous Output.vi
  3. Double-click to open the Example.  Immediately go to File, Save As, Substitute copy for original.  In the File Explorer window that appears, navigate out of the NI examples folders and into your Documents folder, where you can save a copy that you can freely edit/change/etc. without losing the original copy that NI provided to you.
  4. Now you have your copy of this code available to you.  Run it.  See if it seems to work.  Note how simple the code seems to be (it even surprised me!).  Once you think you "get it", try removing the bits and pieces that don't apply to you, bringing the code down to something that you can incorporate into your own VI.

     Sometimes NI doesn't provide as much explanation as we might want for all the little details for all of LabVIEW's functionality.  However, having a series of Examples that we can study and incorporate into our code partly makes up for this!

 

Bob Schor

0 Kudos
Message 9 of 13
(3,699 Views)
Dear Bob,
 
yes, I already tried and tested this example and other.
It is quite different from what I need to do, unfortunately.
Here, the N samples are not sent a certain number of time.
My need is to send n samples M times.
 
In the "finite" example that I send today, I need to send 20 times 15000 samples at a sample rate of 10000 samples/s, which represents 30s. Unfortunately, the real duration between the beginnning and theend of the loop is less that 30s. Where is the problem?
Best regards.
Sébastien
0 Kudos
Message 10 of 13
(3,648 Views)