From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MyDAQ Single Point treatment, ......, possible ?

Solved!
Go to solution

Hi,

I'm a french electronic teacher and I use Labview and MyDAQ board with my students.

 

So this is my question :

 

I know that MyDAQ does not support the Hardware-Timed Single Point Sampling Mode (HWTSP). So, if I have well understood, if I make an acquisition with continious samples, this samples are automatically stored in the buffer before they go to the vi treatment ? And the same for the Write function ?

 

The treatment sequency should be this one :

1 : reading sample

2 : storing in the reading buffer

3 : vi traitment

4 : storing in the writing buffer

5 : writing sample

 

If the sample frequency is set to 1kHz (see attached VI) : at t=0ms, the board reads only 1 sample, puts it in the reading buffer, then treats the data (this duration is approximativly few microseconds), then the sample goes to the writing buffer, and after it is written to the board analog output.

At t=1ms, we do the same, etc each ms ...

 

Conclusion : are we making single point treatment (N=1 in the For Loop) ??? The difference with the HWTSP is that we must pass through the buffer ... ?

 

Thanks for your help !

Regards,

David

0 Kudos
Message 1 of 14
(2,634 Views)

Tomorrow is a Federal Holiday, and my myDAQ (I think) is at work, so my response will be slightly delayed ...

 

Bob Schor

0 Kudos
Message 2 of 14
(2,588 Views)

Hi David,

 

If the sample frequency is set to 1kHz (see attached VI) : at t=0ms, the board reads only 1 sample, puts it in the reading buffer, then treats the data (this duration is approximativly few microseconds), then the sample goes to the writing buffer, and after it is written to the board analog output. At t=1ms, we do the same, etc each ms ...

Yes, BUT only when your loop spins faster than 1ms…

In case the loop needs more than 2ms to iterate you will also 2 samples as your DAQmxRead is set to read "as much as is available". What might happen when you try to read the next sample before it even was acquired?

 

- When you really want to handle sample-by-sample (which is not recommended) you should set the "number of samples to read" at DAQmxRead to "1". Now DAQmxRead will rule the loop iteration time!

- Why did you set the loop count to "1" for that inner FOR loop? Are you sure (really sure!) you will never read more than one sample? Why don't you rely on autoindexing? (And why do you need a loop at all here?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 14
(2,585 Views)
Hi GerdW, thanks for your answer ! I am OK with you, if i am sure that my loop spins faster than 1ms, it should work... I want to handle sample by sample because my final project is not a simple amplification with gain=2. I will make a DC motor position regulator (see attached picture). For that I need to make a smaple treatment ;). And finally I will handle 2 samples because my algorithm is a recursive one ... I don't understand when you say "Why don't you rely on autoindexing?" Do you mean thtat I don't rely the loop count ? Best Regards, David
0 Kudos
Message 4 of 14
(2,582 Views)
I have forgotten the attached file ...
0 Kudos
Message 5 of 14
(2,580 Views)

Hi Bob, 

Thanks for your answer, and don't worry  I will wait !

Regards, 

David

0 Kudos
Message 6 of 14
(2,574 Views)

A few points.

  • My myDAQ appears to support 1 Sample (On Demand).  However, for taking more-than-one sample (i.e. for looking at anything other than "What is the DC voltage now, and I only need to make one measurement ..."), I prefer to let the DAQ device determine the sampling rate, as its clock is generally pretty stable, not interruptable, and reliable.
  • I'm going to assume that you want to get samples at 1 kHz, and want to work with each sample (as though you were sampling one point at a time, but wanted to preserve accurate timing and prompt processing).  This is, in fact, quite easy to do with the myDAQ (and get some noise reduction "for free").  The basic idea is that you use continuous data acquisition and over-sample.

Here's what I tried:

  1. Open MAX and create a Task for Channel A0 of the myDAQ (I called my Task myDAQAI0).  Set it up for Continuous Samples, 10 Samples to read, and a rate of 10 kHz.  Save the Task.
  2. Open LabVIEW.  Open the DAQmx sub-Palette (on the Measurement I/O Palette) and put down the following functions:  DAQmx Start Task, a DAQmx Timing Property Node, a DAQmx Read, a DAQmx Stop Task, and a DAQmx Stop Task.
  3. Wire the Error Line through these functions (in the order listed above) and keep the Error Line straight and un-kinked.  Also wire the I/O line (you have to "bend" it to connect to the Property Node) through all the functions.
  4. Draw a Loop around the DAQmx Read function.  I used a For Loop with a count of 1000 (to get 1000 Reads), but you could also use a While with a Stop control.  Make the loop big enough to include possible other processing.
  5. Right-click the upper-left node of the Start Task function, and "Create Constant".  You should get an empty I/O Constant.  See the little down-triangle?  Click it, and you should see the available Tasks.  Choose the Task you saved in Step 1.
  6. Look at the Property Node.  Click the Property "list" at the bottom of the Function and use Select Property to choose Sample Quantity, Samples Per Channel.  Although you "know" it is 10, this saves you when/if you alter the Task.  For some reason, this Property is a Dbl, so I add a "To I32" function to change it to an I32 (you can find this on the Numeric Palette under Conversions).
  7. Now look at the DAQmx Read.  We're going to read 10 samples at 10 kHz, so we'll get an array of 10 Dbls which we can pass through the Mean function to get a single (averaged!) point at an effective rate of 1 kHz.  Make sure the Read is set to Analog, Single Channel, Multiple Samples, 1D Dbl.
  8. What I did was (inside the For Loop) pass the Array through the Mean function so that my output from the Loop was an Array of 1000 Dbls.  I also timed the loop using LabVIEW's High Resolution Timer, which reported a time of 0.999885 seconds.

I'm choosing to not attach my VI -- the exercise of laying out the 5 DAQmx functions, defining the Task in MAX, adding your own "data processing" to the loop, and "playing around" with the code will be more beneficial to you.  Feel free to experiment and make changes.

 

Bob Schor   

0 Kudos
Message 7 of 14
(2,541 Views)

Hi Bob,

Thanks for this very specific answer !

 

However I have a few questions :

 

- as I am on holidays, and I don't have the MyDAQ device with me, I could'nt create the task with MAX. So I put on the DaqMX Timing function with the same values (1Khz, 10 samples and continuous samples). Is it equivalent ?

 

- I have put the Daqmx Write, with a rate of 1kHz, since we have used the mean function. Am I OK ?

 

See my VI on the attached file...

Thanks Bob,

Regards,

David

- on step 6 I can't see Sample Quantity, Samples Per Channel. When I click on the Property list I can see "Sampling clock/write a waveform/use". Is it because I don't have the device with me ?

 

 

0 Kudos
Message 8 of 14
(2,533 Views)

You can manually create the Task (using a few more DAQmx functions -- DAQmx Create Task, DAQmx Create Channel, and DAQmx Timing.  The "tricky" one is Create Channel, as you specify the Channel to use by naming it, e.g. "myDAQ1/AI0".  Here you need to use the name that LabVIEW "sees" at Run-Time, that is, the name MAX assigns to it!  You can, of course "guess" (and if you only ever plug in one myDAQ, the name will probably be OK).  What I've done is to write a little VI that does a "lookup" -- it queries LabVIEW for all the connected Devices, lets you parse them looking for, say, "myDAQ" and "do something sensible" (for example, flag an Error if none are found, use the unique one if one is found, or say "There are two myDAQs here, which did you want to use?").  Create Channel is also where you specify the voltage range and input terminal configuration (e.g. "Differential").

 

You have a Create Channel function to which you've wired a blank Task Constant.  You can replace this with writing nothing to Task In, and giving it a (unique) Task Name (a String), and wiring this to the Task In terminal of Create Channel.  See above for naming the Channel.

 

If you use the Timing Function, it has Number of Samples as a required I32 input, so you might as well use it instead of the Property Node.  [Incidentally, the property you were looking for is right "beside" the Sample Quantity.Sampling Mode property you used in your code -- click the Property and follow the Triangle Pointer to the right edge where it will expand and show you the two sub-properties.]  You don't need the Sampling Mode Property as you already set it with the Timing function.

 

I'm sure it isn't lost on you that there is a necessary 1 ms delay between Analog In and Analog Out -- you have to collect the Input Point before you can "play" it through Analog Out.  I understand that NI Engineers are working on eliminating this delay, but their Time Machine Module is still in development ...  

 

Bob Schor

0 Kudos
Message 9 of 14
(2,525 Views)

Hi Bob,

 

I understand that if I use the timing function, I won't have to use the property node.

 

However I need to understand all the things you explained to me, and when I follow the triangle pointer I don't see the 2 sub properties ... !

See the attached file.

 

After that I think that all will be good !

Regards,

David

 

 

0 Kudos
Message 10 of 14
(2,511 Views)