LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

connecting digital input as a source to counter to measure pulse width

I am trying to connect a digital input to a counter source to measure the digital signals pulse width.  I am able to do this using the Daq Assistant, but I would really like to see how it is done using the Daqmx functions as I would like to have more then one signal measured at the same time.  Does anyone have an example of how this is done?  I was also wondering if measuring 4 digital signal pulse widths using the PCI6220 Daq - which I know only has 2 internal counters - is possible with out using external counters.  Thanks in advance.
0 Kudos
Message 1 of 8
(4,025 Views)
Hello Greycat,
There are several pulse width measurement LabVIEW examples that install with NI-DAQ.  You can get to them in LabVIEW by going to Help>>Find Examples.  Then navigating to Hardware Input and Output>>DAQmx>>Counter Measurements>>Period or Pulse Width.  As far as measuring 4 signals, that will be a little difficult, but possible.  You definitely want to use counters, but you could also use either analog or digital input.  You can send your signal to an analog input, then do some post processing to determine the pulse width based on the number of samples and the sample rate.  With digital, you would have to do correlated dio, and again do some post processing.  Hope this helps.
-Alan A.
0 Kudos
Message 2 of 8
(4,000 Views)

Yes that does help a little.  Somethings I can't seem to figure out are; I understand that software counters a unreliable ... but is there any way to make them more reliable/usable?  In the documentation for my DAQ it states that you can wire any of the PFI lines to the counter but I can only seem to be able to use PFI 9 (source for counter 0) and PFI 4 (source for counter 1).  How is this done?   

You said:

*As far as measuring 4 signals, that will be a little difficult, but possible.  You definitely want to use counters, but you could also use either analog or digital input.  You can send your signal to an analog input, then do some post processing to determine the pulse width based on the number of samples and the sample rate.  With digital, you would have to do correlated dio, and again do some post processing.  Hope this helps.*

Any examples you know of that can define what you are talking about?  I'm going to look into it and see what I can find.
 
One more question ... Even using the counter I still get some variation in my pulse width measurement ( the pulse width range is about 2milliseconds to about 8 milliseconds) The variation I'm getting is not a lot but it is still affecting my number (the variation I'm getting is about 0.018 milliseconds ) I'm currently looking into using some sort of digital filter but I'm not sure that this is the answer.  Any insight into this would be greatly appreciated.  Thanks in advance for any help.  As you can probably tell, I'm very new at this and tryin very hard to make sense of it all. 
0 Kudos
Message 3 of 8
(3,996 Views)
Greycat,
All good questions.  Let me attempt to clarify further.
First, software counter.  The only way to use a 'software counter' in this case would be to continuously monitor a digital line and grab a system time when the line first goes high, and then grab a system time when the line goes low.  Then take the difference of the time stamps.  The reliability of that is completely dependent on how fast your polling loop executes which will control how accurate your time difference is.  Another thing to keep in mind is that you can't get any better than millisecond accuracy from a system time. 
PFI 9 and PFI 4 are the gate terminals for counter 0 and 1 respectively.  This is where you need to input your signals for a pulse width measurement.  You can use other PFI lines and route the signals to PFI 9 and 4 if you wanted, but I would recommend sticking with the default terminals unless it is necessary to do otherwise. 
I am not aware of any examples that use analog or digital input to find pulse width, but there is a Pulse Measurements VI in LabVIEW that you might be able to use for your post processing function.  It is on the All Functions>>Analyze>>Waveform Measurements palette.
 
As to your last question, you mentioned that you are getting some variation in your measurement.  The counter method to pulse measurement should be extremely accurate.  To make it as accurate as possible, you should set the minimum and maximum values to as close to the min and max values you expect to measure.  Also, is it possible that your signal is changing slightly???
 
Hope this helps to clarify 🙂
 
-Alan A.
0 Kudos
Message 4 of 8
(3,980 Views)

Thanks again Alan: 

 I've played with reading my digital signal on an analog line and I have had some success.  Still have noise though.  I have one other question .  Just for exploration sake ... I generated a digital wave from my Daq and fed it back to my Daq on PFI9 and measured pulse width ... The pulse widths were ROCK STEADY (not even 1/100 of a microsecond variation).  Then I generated a digital pulse with my function generater (oscilloscope) and measured the pulse width from that - again I got the variation of pulse width measurement.  So finally here is my question.  Would synchronizing the source clock (from daq) and the sensor clock (signal generation) (sending a clock signal from the Daq to my sensor so the output will be timed with the source signal goin into the counter of the Daq) rectify this problem?  This is the only explaination I can come up with given the above results of my tests.  I would have already done this but (sadly) the sensors we have are not capable of accepting a clock signal (so I will have to wait until the other ones come in).  Thanks in advance.

Greycat

0 Kudos
Message 5 of 8
(3,972 Views)

Graycat,
I not really sure if synchronizing your device with the DAQ board will help or not.  That will depend on the characteristics of your device.  I can tell you that it appears that the frequency measurement is precise and your device is producing a pulse train with a slightly varying frequency .  If you want to try to synchronize, you can always export one of the timebases of the DAQ device to a PFI line.  You can do this with the "DAQmx Export Signal.vi" or with "DAQmx Connect Terminals.vi".
-Alan A.

0 Kudos
Message 6 of 8
(3,957 Views)
Thanks again Alan:
 
That is the plan, but I must wait until our new sensors come in.  I'll post my results when I have some.  One thing that still doesn't sit right with me.  
 
You Said
**I can tell you that it appears that the frequency measurement is precise and your device is producing a pulse train with a slightly varying frequency**
 
Shouldn't the signal coming out of my function generator be rock steady.  I can't see that the function generator would be giving me variable frequency (or pulse width actually cause that is what I'm measuring).  I still got the variation of pulse width measurements from the function generator signal aswell as from my sensor ... but when measuring the signal generated from the Daq board the measurement was rock steady.  Synchronization could be the only really difference in that the signal coming from the Daq board was generated using the same oscillator that generates the 'source' signal into my counter for the pulsewidth measurment.  Where as the function generator being used (Tektronix TDS 1012) is using a different oscillator and therefore not synchronized. 
 
I understand that I am repeating myself here mostly but thought I might try to reword it so that I might better explain myself.  Wheather or not that was achieved is not for me to decide.Smiley Tongue 
 
Greycat
0 Kudos
Message 7 of 8
(3,952 Views)

Greycat wrote...
"...Shouldn't the signal coming out of my function generator be rock steady?..."
 
"...Synchronization could be the only really difference in that the signal coming from the Daq board was generated using the same oscillator that generates the 'source' signal into my counter for the pulsewidth measurment..."

Greycat,

1. It's certainly conceivable that the function generator signal may not be "rock steady."

2.  To check for the "synchronization" effect you mentioned: how many different discrete values do you seen in your pulse width measurement?  If the only issue is synchronization, you should see just 2 distinct values. 

For example, if your function generator's pulse width == 2000.41 cycles of your DAQ board's timebase (source) signal, then you'd only measure values of either 2000 (59 times out of 100) or 2001 (41 times out of 100).

If you see several distinct values over a small range, then the function generator's output must not have a rock steady pulse width.

-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.
0 Kudos
Message 8 of 8
(3,946 Views)