LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQ SampleRate vi vs loop iteration time?

What happens when you set the sample timer vi to execute faster than the time it takes for the loop to execute?  If you use the iteration count of the loop to record with the data (build array) will the loop time dominate or the DAQmx?

0 Kudos
Message 1 of 15
(277 Views)

Remember (or Learn for the First Time) the Principle of Data Flow.  When you have a Loop, every function inside the loop needs to run before the Loop can "loop".  I don't know what you mean by "the sample timer", but suppose you have a Wait function with some time T (seconds) wired to it, and you also have a DAQmx Read Function that reads N samples at a rate of S Samples/sec.  The two run independently.  The Wait takes T seconds, the DAQmx Read Function requires N/S sec.  Which determines the loop speed?  It takes at least T and N/S sec, so it will be dominated by the slower of the two.  For this reason, you should (almost never) have a Wait statement inside a DAQ loop (it just "wastes time" and potentially cause you to miss samples).

 

Bob Schor

0 Kudos
Message 2 of 15
(258 Views)

Usually you grab a bunch of samples at once, e.g. 100, that way it can loop 100 times slower than the sample rate. You should as mentioned not try to match this speed with a Wait, but simple wire '100' to the number of samples to grab.

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 15
(233 Views)
Highlighted

I'd like to run in continuous mode and collect samples at a user defined rate.  Although i define the sample rate using the SampleClock.vi the loop is not controlled by this function.

 

How i thought this would work is that i'd set the sample rate with SampleClock.vi and that would control the capture rate of the DAQmx Read.vi.  The overall loop time would be controlled based on the READ vi finishing it's action.  I'm running these functions in a state machine, where the data is a 1D array, i use the BUILD array function to create a "time" column, where it is the value of the summed loop times from a shift register.

 

It all works except it doesn't seem to matter what i put in for the sample rate, it all runs at the same time.

0 Kudos
Message 4 of 15
(208 Views)

Can you post your code, preferably saved back to an older version so more people can open it?  (Offhand, I'd recommend 2014 or so).

 

Note: you should definitely *NOT* generate your time array by measuring loop iteration times in software!  Take advantage of your super-regular hardware acquisition clock.  Either use the waveform out version of DAQmx Read and extract the "dt" field or query the "sample rate" property using a DAQmx Timing property node.  These are a much better measure of the actual time between samples.

 

 

-Kevin P

0 Kudos
Message 5 of 15
(200 Views)

Ok, i found and am using the 'Get Waveform Components' function to see the t0 timestamp, the dt sampling rate and the Y data.  This is great however...I cant get the timestamp (t0) data converted to a DBL to save it to a spreadsheet.  The thought being i can just format the column for MM/DD/YYYY hh:mm:ss.00

 

I have searched this all over the net, there is a ton of information however none that explains this, or at least i couldn't find it.  Can any of you point me to an example that will convert the (t0) timestamp to a usable format for excel?

 

I have done this with TDMS before, that will require significant re-coding...hopefully there is a better way out there.

0 Kudos
Message 6 of 15
(172 Views)

Hi coolhand,

 

simple as this:

check.png

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 7 of 15
(167 Views)

@coolhandLV7 wrote:

I'd like to run in continuous mode and collect samples at a user defined rate. 

 

 


Go to Find Examples, open the Voltage (with Events) - Continuous Input example. Look at the code.

 

The event structure runs at the Sample per Loop Interval exactly, no polling, not timers, etc. Easy to implement into an event based state machine, like the JKI.

 

mcduff

0 Kudos
Message 8 of 15
(164 Views)

converting to a string is ok but i would then like to build it into the 2D data array to write to spreadsheet.  Converting to a DBL doesn't seem to work, is there a better way? 

0 Kudos
Message 9 of 15
(154 Views)

Hi coolhand,

 

you can convert the LabVIEW timestamp to an Excel timestamp entity and append that to your 2D array. Then you just need to format the corresponding column in Excel to display timestamps…

 

There are several threads on this topic, like this. (Keep in mind possible problems due to timezones, DST, …)

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 10 of 15
(152 Views)