LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx: read value(s) with delay

Hello,

 

Here is a part of my initial setup:

  • analog output generates a value at each loop iteration
  • analog input must wait for some time (50ms in this case)
  • then AI reads a number of samples
  • then it calculates average, that is used for further processing (in this simplified version connected to 2nd output to be controlled at oscilloscope).

This setup doesn't work, generate error 200284 (some or all samples requested have not been required).

 

Similar example I've found here:

http://www.ni.com/example/25905/en/ 

 

Thanks in adavnce.

 

Read_value_with_delay (0).png

 

0 Kudos
Message 1 of 28
(5,470 Views)

A couple of questions.

  • The example does a single sample.  Your AI task is also set up as a single sample, as you start and stop the task within the loop.
  • Look at how the example starts the tasks.  Which does it start first?  Can you understand why that is important?  Think about it, then fix your code.

Bob Schor

Message 2 of 28
(5,458 Views)

Indeed, "read" starts first.

So, the solution would be put start/stop staff for generation branch also inside loop ?

0 Kudos
Message 3 of 28
(5,445 Views)

No, to start both outside the loop.  Think about the sequence you want to have happen.  Both the AI and AO systems are running, waiting for something to do.  The AO gets a trigger, does its thing, generates (after a delay) the AI trigger, the AI is Ready to Roll so it also does its thing, the loop "loops", and you Do It Again.  The point being, everybody is running and waiting for their signal.

 

Bob Schor

0 Kudos
Message 4 of 28
(5,438 Views)

Here is what I tried.

Once running it generates the following error:

 

Error -200557 occurred at Property Node DAQmx Trigger (arg 1) in read_input_with_delay (1).vi

Possible reason(s):

Specified property cannot be set while the task is running.

Set the property prior to starting the task, or stop the task prior to setting the property.

Property: Start.Delay

Task Name: _unnamedTask<36>

 

It seems that "Start" block should be used after "Start Trigger". Isn't it ?

 

 

 

Read_value_with_delay (1).png

0 Kudos
Message 5 of 28
(5,426 Views)

@Pavel_47 wrote:

It seems that "Start" block should be used after "Start Trigger". Isn't it ?


No. You have the trigger being set up after you call the DAQmx Start Task.  All of your trigger setup should be done before that and before the loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 28
(5,414 Views)

Thank you for suggestion.

Here is what I've tried (snippet below).

The same error: some of all samples requested have not been acquired.

I've looked through a number of examples concerning synhronization.

None corresponds to my setup.

All of them uses waveform defined outside loop, whereas in my case the output is generated inside loop.

For example this one:

https://forums.ni.com/t5/NI-DAQmx-Examples/Multi-function-Synchronization-for-AI-and-AO/td-p/3490608

 

 

Read_value_with_delay (2).png

0 Kudos
Message 7 of 28
(5,382 Views)

The issue seems to be enchanted.

Having no solution with HW triggering, I've tried to create something similar using only LabVIEW programming features.

And even this doesn't work.

Here is the gernerated error (apparently it's impossible to copy error message as text !)

 

aaa.png

 

 

Read_value_with_delay (3).png 

0 Kudos
Message 8 of 28
(5,372 Views)

Wow.  I got it to work, and in the process, learned something I didn't know about Finite Sampling.

 

So I have a USB-6009 that has 2 D/A output channels and A/D input channels, so I thought "Why not run this program on my own DAQ device?".  Of course, it didn't work, but for different reasons, such as my not having set the Max/Min properties of the Channels (your device probably allows D/A ranges of ±10V, but the USB-6009 is 0 to +5.  Not only do you need to set the Output Scales (easy to do with MAX Tasks), but you need to be sure that when you send the Averaged A/D Voltage out, you don't send a negative value (since I had no signal, I just send "Average + 1").

 

I simplified my DAQmx coding by using MAX Tasks (see "Learn 10 Functions in NI-DAQmx ..." -- a Web Search will surely find this very nice NI White Paper).  But it still didn't work -- it failed on the second loop.  Now, I've never done Finite A/D sampling under program control before (I usually use Continuous Samples), so I wondered "Maybe I need the Start and Stop Task function inside the loop".  And then it worked.

 

Here's my slightly-revised code (I did some wiring cleanup).  Note that V_Output, V_Control, and V_Sample are the names of the DAQmx Tasks I created (where the "DAQmx Details" are hidden).  I did my best to get rid of frames, keeping only the one needed to "separate" the AO from the AI.

 

Revised AO-AI Routine.png

Bob Schor

Message 9 of 28
(5,361 Views)

Bob_Schor a écrit :

Wow.  I got it to work, and in the process, learned something I didn't know about Finite Sampling.

 

So I have a USB-6009 that has 2 D/A output channels and A/D input channels, so I thought "Why not run this program on my own DAQ device?".  Of course, it didn't work, but for different reasons, such as my not having set the Max/Min properties of the Channels (your device probably allows D/A ranges of ±10V, but the USB-6009 is 0 to +5.  Not only do you need to set the Output Scales (easy to do with MAX Tasks), but you need to be sure that when you send the Averaged A/D Voltage out, you don't send a negative value (since I had no signal, I just send "Average + 1").

 

I simplified my DAQmx coding by using MAX Tasks (see "Learn 10 Functions in NI-DAQmx ..." -- a Web Search will surely find this very nice NI White Paper).  But it still didn't work -- it failed on the second loop.  Now, I've never done Finite A/D sampling under program control before (I usually use Continuous Samples), so I wondered "Maybe I need the Start and Stop Task function inside the loop".  And then it worked.

 

Here's my slightly-revised code (I did some wiring cleanup).  Note that V_Output, V_Control, and V_Sample are the names of the DAQmx Tasks I created (where the "DAQmx Details" are hidden).  I did my best to get rid of frames, keeping only the one needed to "separate" the AO from the AI.

 

Revised AO-AI Routine.png

Bob Schor


Bob, thanks a lot.

 

I've tried your example and it works.

Unfortunately the accuracy with SW timing is quite mediocre ... instead of specified 50ms the delay is about 75ms (please the snapshot from oscilloscope).

For our actual testbend is sufficient, but with some advanced features (that we planify to integrate in the future) such accuracy will be probably insufficient.

 

It's 2nd day I'm searching for a solution with HW timing (i.e. using "Start Trigger" and "Start.Delay" property node), but without success: all the examples that I've found until now uses perdefined waveform (i.e. defined before loop), whereas in my setup output value is generated inside loop. Have you any experience with "Start Trigger" ?

 

Thanks in advance.

 

Pavel.

 

 

F0000TEK.BMP

 

0 Kudos
Message 10 of 28
(5,346 Views)