LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Low Frequency Signal at a Higher Rate Using DAQmx

Solved!
Go to solution

Hello,

 

I trying to make a program to read the frequency of a signal every 250ms. My problem is that sometimes the frequency can drop below 4Hz, causing a timing issue. So, I tried to solve this by acquiring continuously and reading just the most recent sample to avoid timeout issues. In doing so, I ran into some quirks that I was hoping someone could explain to understand what is really happening in my VI.

 

I've attached my program and a picture of the block diagram. To test it, I'm simulating my signal using a 0-4V square wave function generator and varying the frequency. Also, I'm using an NI-9402 module in a cDAQ-9174. I'm running LabVIEW 2015 Service Pack 1.

 

So, my specific questions are:

(1) From other posts, I've found I need to set the "Offset" in the DAQmx read property to 0 and read a sample before changing the "Offset" to -1 to read the last sample acquired. If I don't do this (set "Initial Read?" bool to false in my VI), I get Error -200277 (Invalid combination of position and offset). Can anyone explain why this is necessary for the program to function?

 

2. If I change the "Read Property?" bool to false, my read will no longer update with the correct frequency. As soon as I change it to true, the program works as expected. I've tried other property node reads besides "AvailSampPerChan", but this seems to be the only one that allows the program to function. Can anyone explain why this is required and if their is another method?

 

Lastly, is this the best methodology to solving my issue or am I going about this all wrong? I'd appreciate any other solutions.

 

Thanks!

Patrick

Download All
0 Kudos
Message 1 of 3
(161 Views)
Solution
Accepted by topic author Tenneco-Instrumentation

1. Yes.  When Offset = -1, it means to start reading from a point in the buffer where the most recent sample was placed.  That puts it at an offset of -1 from where the next sample will go.   But when you first start the task, there is not yet a "most recent sample".  The next sample is the first sample and it's going to go into buffer position 0.  Offsetting that by -1 is illegal because there is no sample prior to the one that will be next.

    The single read with Offset = 0 will wait until 1 sample is acquired before the code continues to where you attempt to do your looped reads with Offset = -1.  But because there is sure to be at least 1 sample in the buffer, it becomes ok to have Offset = -1.

    (The method you're using is more certain and robust than a method I've seen that just adds a "Stall Data Flow" between starting the task and doing the first read with Offset = -1.  Such a timing method might work ok with a fixed-rate sample clock task, but not so well with an intermittent or unknown frequency pulse train.)

 

2.  I'm mystified by this one.  Reading that property or not shouldn't have any effect on the data returned by the DAQmx Read function.

 

Are you going about this all wrong?   No, I wouldn't say so.  Your approach is pretty reasonable.  There's a couple things you might consider though:

A. Use the "msec multiple" delay and add data dependency so that the Read occurs *after* the delay elapses.

B. Query the "Total Samples Acquired" property so you can be aware of the case where the pulses stop and you keep reading the same "most recent sample" over and over.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 2 of 3
(95 Views)

@Tenneco-Instrumentation wrote:

Hello,

 

I trying to make a program to read the frequency of a signal every 250ms. My problem is that sometimes the frequency can drop below 4Hz, causing a timing issue. So, I tried to solve this by acquiring continuously and reading just the most recent sample to avoid timeout issues. In doing so, I ran into some quirks that I was hoping someone could explain to understand what is really happening in my VI.


Keep some older samples so you have e.g. 2s worth of data to analyze. If the signal changes fast and often you can try to analyze your 250ms sample first and if that fails (because the signal is currently slow), use a bigger sample.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 3
(53 Views)