Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I configure the CTR 1 GATE to output a pulse (10us long) and then immediately take a pulse width measurement?

I'm using the BNC-2120 DAQ and LabVIEW for interfacing with an ultrasonic position sensor.  The sensor is the "PING))) ultrasonic range finder."  It measures the distance from PING))) to some object directly in front of it.  It has 3 pins (5V, ground, and a signal pin).  The 5V and ground are easily taken care of with the 5V and digital ground outputs on the DAQ.  The signal (SIG) pin works in the following way:
 
1) Send a 10us, 5V pulse to SIG.  This triggers PING))).
2) Wait 200us.  PING))) takes a distance measurement.
3) SIG outputs a square wave with a specific pulse width. 
 
The pulse width varies with the distance of the object away from PING))).  I've tried using CTR 1 OUT to generate the pulse, and then using CTR 1 GATE to measure the pulse width.  However, the measurement is stuck measuring 0V because CTR 1 OUT is on the same pin!  So PING))) tries to output a pulse, but cannot due to the fact that CTR 1 OUT forces the SIG voltage to be 0V.  So I need to use just one counter I/O line to trigger and measure.  How can I do this?
0 Kudos
Message 1 of 4
(4,191 Views)

Hi Matttastica,

 

What DAQ card are you using? The reason I ask is that the PFI lines on some cards can be used as PFI lines and digital I/O lines, while on others they can only be used as PFI lines. The pinouts and diagrams for our cards can be found at www.ni.com/manuals. You can accomplish what you are looking to do if your PFI line is a DIO lines as well.

I would suggest doing two tasks, one for counter output and one for counter input. (Note that both these are not going to be the same line). The counter output will be used to do a single pulse generation, while the counter input will be used to read back the period.

 

This will work because, at first, we are going to route the line from the counter output to the counter input line by using a ‘DAQmx connect terminals’ (basically making the input line an output line for a moment). First, setup the tasks and the DAQmx connect, start the tasks and have the counter output do a ‘wait until done’ to ensure the pulse is sent. After this is done, do a DAQmx disconnect terminals (turning the input back from an output to an input), and then do a DAQmx read for your counter input (period measurement). You may look at the shipping examples for pulse generation and period measurement in LabVIEW (Help » Find Examples... » Search tab … search for examples)

One note is that since this is software timed, it may not be fast enough to meet your 200us timing. If this ends up being the case, please look at the 6552, as it can do per clock cycle direction change very fast.

David L.
Systems Engineering
National Instruments
Message 2 of 4
(4,169 Views)
Hey David,

Thanks for your help.  I'm using NI PCI-MIO 16E-4.  I hope that's what you're asking for.  So far, I have a block diagram similar to what you're describing. 

I can't find a DAQmx disconnect terminals or the DAQmx connect terminals.  However, I do have something called "DAQmx channel property node."  In this, I can set CTR- GATE1 to be an output or input. 

I've made a program that works for a few seconds, and then aborts randomly.  I'm able to output the pulse width (in samples I think) to the front panel as a U32.  I get values from 10,000 to 200,000 depending on how far an object is away from PING))).  I think the reason for the program quitting is the fact that sometimes PING))) outputs a pulse width that is too long or doesn't output a pulse at all during some of the measurements.  Here's the "read" part of my program:

Create Virtual Channel(CI pulse width) --> Channel Property Node (wired constant PFI 4 to "CI.PulseWidth.term") --> start task --> read (counter U32 1 sample) --> clear task.  I'm looping forever, so the clear task is for memory management.  How can I avoid the program quitting randomly?
0 Kudos
Message 3 of 4
(4,162 Views)

Matttastica,

The connect and disconnect terminals are in the tools pallet of the block diagram under ‘Measurement I/O » NI-DAQmx » Advanced » Signal Routing’. If LabVIEW is aborting, can you please list the error code and description? You may try increasing the max time of your period measurement.

David L.
Systems Engineering
National Instruments
0 Kudos
Message 4 of 4
(4,139 Views)