Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

how do you measure period between every edge?

Hi,

I am using a cDAQ 9174 with a NI 9401 to measure period.  I am confused though, because it appears to be measuring every other period instead of every period like this.  I am using rising edges.  I am using the example code given in LV2011, slightly modified with a WHILE loop.  The sample code measures only one period.

 

Suppose I have 4 rising edges A, B, C and D.

 

What I am observing (I think) is that the period is being measured between A and B, and then from C to D, but, not between B and C.  I want to know the period between every rising edge, not just consecutive pairs.  Is there a way to do this?

 

I expect my periods to be relatively long, e.g. 10s to 100s of milliseconds.  Also, how do I stop this crazy thing...I have to ABORT to stop it!!!

 

Thanks,

Dave

0 Kudos
Message 1 of 5
(3,036 Views)

use a counter with a fast clock

use your signal as a trigger to store the counter value in a buffer and continiously read the buffer

You could also reset the counter on each edge, but that might depending on your measuring task

I don't know the capabilities of your device , NI (John P) please jump in 😉

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 2 of 5
(3,030 Views)

Dave,

 

We will need to make a few adjustments to your VI before we take full advantage of your hardware.  First, we need to make sure you start the counter input task outside the while, rather than automatically everytime the DAQmx Read VI executes.  Second, we will want to buffer your acquisition using the DAQmx Implicit Timing VI.  Take a look at the attached VI.  Make sure to set all parameters before running.  Also, if the input signal to the counter is disconnected, the DAQmx Read VIs will generally hang since there are no counts in the buffer to read.

 

Regards,

 

Alexander M

Application Engineer

National Instruments

Message 3 of 5
(3,007 Views)

Hi Alexander,

 

Thanks for your suggestion, but, the vi you sent does not work, apparently.  I am using another vi that I found in the examples, attached here without any modification from the LV2011 example finder.  I can see little difference from the one you sent me, and the LV2011 example, but, I can't get yours to display the data.  This example works fine, but, yours does not display anything in the box labelled period.  In fact, the box is greyed out, and remains grey while the vi is running?  Also, one question for you is about the data.  In your vi, the data appears to be produced in an array.  Suppose I just want a SINGLE value for each period (time between two consecutive rising edges) on which to do my calculations after each iteration?  Do I need a 1-D array, and if I use an array, is some of the data being lost between iterations of the program?  I want to use EVERY period that results from consecutive rising edges, single values.

 

Thanks for the help.

 

Dave

0 Kudos
Message 4 of 5
(2,999 Views)

Hi Dave,

 

The VI you posted most recently is slightly modified from the one in the example finder (the unmodified example by that name is set to "High Frequency 2 Counter" mode--yours uses "Low Frequency 1 Counter", which is in fact the mode you want to be using).

 

Anyway, you are very close.  Configuring the timing to "Implicit" means a sample is taken on every rising (or falling) edge of your signal.  Note that the first sample is actually thrown away by the hardware on the 9174 (since it does not actually represent a complete "period" of the signal, but rather the time between the arming of the counter and the first edge of your signal--if you do want this first sample let me know, because there is a workaround).

 

The key is that DAQmx Read can read back a user-defined number of samples.  For example, with higher frequency signals, you might not be able to keep up in software if you only read back a single sample per loop iteration so in this case it would be required to read back an array of samples on every loop.

 

Your periods are on the order of 10-100 ms, so you can probably keep up by reading one sample per loop:

 

 

 

CI Period.png

 

 

A couple possibilities of why your code might have worked and not Alexanders:

 

1)  If you are trying to read a large number of samples, perhaps the Read call was blocking longer than you might have expected and was not returning data before you hit the abort button.  Reading 100 samples at 100 ms intervals is 10 seconds of data which is right at the default timeout value for DAQmx Read.

 

2)  I noticed you started with the High Frequency 2 Counter Example but have modified it to use Low Frequency 1 Counter (which is correct for this application).  However, the High Frequency 2 Counter method uses a different default terminal for your external signal than the Low Frequency 1 Counter Method (source vs. gate respectively).  Perhaps you are connecting your external signal to the default source terminal and therefore you would only get data if using the high frequency 2 counter method.  I actually usually just specify which terminal I want to use rather than use the defaults to avoid any potential confusion.

 

 

Best Regards,

John Passiak
0 Kudos
Message 5 of 5
(2,980 Views)