10-05-2010 01:10 PM
I am trying to setup a 6602 counter for a single (non-buffered) pulse width measurement with an external clock. Under normal testing, the unit under test will provide the pulses, I need to measure the number of pulses during different time periods (1, 60, and 300 seconds). I want to do a pulse width measurement and I'll supply the gate signal pulse to the counter for the specific time needed.
Under normal operation, the unit under test is wired into the counter's source and the pulse is wired into the gate. For testing purposes I am using a BNC-2121. I have the counter's source wired to the Adjustable Square Wave Output and the gate wired to the Trigger output.
Here is my C++ code. I am getting a timeout error on the read and I don't know why. Any help would be appreciated.
//Create Task
DAQmxCreateTask( "task1", taskHandle );
//Create Pulse Width Channel
DAQmxCreateCIPulseWidthChan( taskHandle, // TaskHandle
szCtrName.c_str(), // Counter Name
"", // Channel Name
dMin, // Min Value
dMax, // Max Value
DAQmx_Val_Ticks, // Units
DAQmx_Val_Rising, // Gate Edge
"" ); // Scale Name
//Set the Pulse Width Terminal to the gate signal
DAQmxSetCIPulseWidthTerm( taskHandle, // TaskHandle
"", // Channel
"/CTR2/PFI38" ); // Terminal
//Set the Timebase Src to the counter's source
DAQmxSetCICtrTimebaseSrc( taskHandle, // TaskHandle
"", // Channel
"/CTR2/PFI39" ); // Terminal
//Start Task
DAQmxStartTask( taskHandle );
//***Send pulse to gate counter***
//Read Counter
DAQmxReadCounterU32( taskHandle, // Task Handle
DAQmx_Val_Auto, // Num Samps to Read
10, // Timeout
ulBuffer, // Read Buffer
1000, // Buffer Size
&lSampsRead, // Num Samps Read
NULL ); // Reserved
10-06-2010 06:05 PM
Hello,
Your code looks similar to the Pulse Width example that we provide in Start » All Programs » National Instruments » NI-DAQ » Text-Based Code Support » ANSI C Examples » Counters » Measure Period or Pulse Width » Pulse Width. Can you try running this with the onboard clock to see if you can get results from the card?
From what I understand, you are trying to count the number of pulses at a certain time based on an external signal being high on the gate for your selected amount of time. How long does your pulse last in your testing? If it is 60 or 300 seconds, you will need to change the timeout on the Read function. The timeout typically occurs when the measurement does not complete in the time the property has specified. The function is either not seeing the pulse to be measured or it is taking longer than 10 seconds in my opinion. Also, you reference PFI38/39 as CTR2, while it shows as CTR0 on the 2121, are these the right terminals for you? Can you instead reference PFI30/31? Let me know what you find out.
10-07-2010 08:26 AM
I've setup a pulse width task in NI-MAX using the onboard clock and everything worked fine, so I know the hardware is working.
My unit under test is providing the pulses (from gyros) I need to measure. The pulses indicate the position of the unit so there are X, Y and Z axis gyros. I need to measure these pulses for specific periods of time (1, 60, and 300 seconds). For example during the 1 second measurement, the X and Y gyros should measure zero pulses and the Z axis should measure 515 gyros. During a 300 second measurement the X and Y gyros should measure < 60 and the Z axis should measure 30800.
So the gyro pulses are wired to the counter input and I am using a DIO channel from NI-6508 to provide the gate pulse. The gate signal will be high for either 1, 60, or 300 seconds depending on the test. The gyro pulses are essentially the external clock to the counter. I want to count the gyro pulses during the pulse of the gate (DIO).
To simplify the setup, I connected to BNC-2121 directly to the card. I have the adjustable clock output going to the counter input of ctr0 and the trigger signal going to the gate of ctr0. Once the task has been started and before the read ( I had a breakpoint set in the code), I would press the trigger button on the BNC-2121 and hold for approx. 1 second. I then execute the Read statement, and I always get a timeout. From my experience working with NI, I'm guessing I don't have a channel property set correctly, but its not obvious to me and I can't find an example to do exactly what I'm trying to do.
The CTR2 designation in the code was the object name of the card. I have two 6602 cards in my chassis. I was using ctr0 of the second counter card, so PFI38/39 was correct.
Again, any help would be appreciated.
10-07-2010 03:49 PM
Additionally, I tried to run the NI sample code (PulseWidth.c) and I still received a timeout on the Read function. Again I'm using the BNC-2121 trigger to supply the gate signal.
I was able to get the pulse width measurements to work correctly (no read timeout) if I setup the DAQmxCfgImplicitTiming. But this is a buffered pulse width measurement and I only want a single pulse width measurement. Basically with everything working as a buffered measurement, I removed the DAQmxCfgImplicitTiming line and the read function times out.
10-08-2010 05:14 PM
Hello,
Are you producing the pulse, and at the end of the pulse executing the read? You need to be inside of the read function so that it can wait for the rising edge to trigger the pulse width measurement, and on the falling edge the read should return the pulses counted in ticks for the length of the pulse. Can you try toggling the 2121 trigger several times within the 10 second timeout period to see if it ever registers?
10-11-2010 08:10 AM
No, I was starting the task, applying the pulse, then performing the read. I'll try applying the pulse while perfroming the read.
11-11-2010 05:52 AM
I have some similar problems.In single pulse-width measurement with PCI-6602,i use the GATE of counter1 to measure the number of events that occur on PFI35 while the GATE signal remains in an active state in a particular time interval.But the counter counts the 20MHz timebase all the time,what should i do to select PFI35 as the SOURCE of counter1,and which function can be used as SOURCE selector.Additionly,the events are wired to BNC-2121 ctrsource1.Any help is appreciated.
11-12-2010 11:28 AM
Hello,
Use the channel property node to specify the Counter Input Timebase Source and use your external signal as the timebase to count how long the signal is high. You could probably also do a count edges task where you set your gate signal to count or not count how many events happen at a time. The channel property you are looking for is below:
12-13-2010 04:55 AM
Thanks
This property node led an error when the external signals was connected,so i choose a count edges task instead.