Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter Pulse width measurement

I'm having trouble getting accurate measurments using my counterboard, and I was wondering if it is just because I am running it wrong. Here is my program:
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateCISemiPeriodChan(taskHandle,"Dev1/ctr1","",10,83.0000000,DAQmx_Val_Seconds/*,DAQmx_Val_Rising*/,""));
DAQmxErrChk (DAQmxStartTask(taskHandle));
DAQmxErrChk (DAQmxReadCounterScalarF64(taskHandle,10.0,&data[0],0));
DAQmxErrChk (DAQmxClearTask(taskHandle));
printf("Measured Pulse Width: %.9f sec\n",data[0]);
(this is the code from the code PulseWidth.c)
I manually trigger the switch, and I continue to get very low values, around 0.000011. I even put it into a for-loop to see if it was just a debouncing problem, but I'll get a string of small values. Now I changed my MinVal and MaxVal to larger values, but I continue to get the small numbers. Can anyone help me with this? I'm trying to read pulse width values between 0.0005 seconds to 3 seconds. Thanks
Craig
0 Kudos
Message 1 of 4
(4,122 Views)
Hi Craig,

I don't see anything wrong with the code on first glance, although your min and max values are set incredibly high given the semiperiod values you are expecting to measure.  However, the only thing that this will change from an execution perspective is that the driver will select the 100kHz timebase to be used for the measurement versus the 20MHz timebase.

You mentioned that you pulled this code from the shipping example PulseWidth.c (with obvious modifcations for getting the semiperiod measurement).  Does the PulseWidth.c example with no modifications return pulse width measurements that are in the range you would expect for an input pulse?  In addition, there is a buffered semiperiod example that is included with the DAQmx driver called BuffSemi-Period-Finite.c - what results do you get when running this example with no modifications?  Also, which counter/timer board and version of NI-DAQmx are you using?

Regards,
Andrew W
National Instruments
0 Kudos
Message 2 of 4
(4,108 Views)
Andrew
First off, I am using a 6601 counterboard with the latest driver for it. I forgot to add that last time. I'm very new to using these counterboards. When I run the plain PulseWidth program,
I get this error: BSCMAKE: error BK1506 : cannot open file '.\Debug\PulseWidth.sbr': No such file or directory
However, I've gotten around this by pasting the contents of the cpp file into another file. (though if you can tell me how to fix this I'd be greatful")
Anyways, I get the very low numbers using this function as well as the buff-semi period finite. Is there some multiplier that I'm am missing, or do I need to put it into some equation? Here is my problem, I need to measure the time period that an input is low and high. I was planning on using two different counters for this purpose. Am I using the correct commands? Any help would be appreciated, and please feel free to simplify the problem as much as possible. I will not be offended. I am very new at this. Thanks again.
Craig
0 Kudos
Message 3 of 4
(4,089 Views)
Hi Craig,

As far as the error that you get when running the PulseWidth shipping example, that appears to be something related to the Visual C++ environment.  A Google search turns up quite a few articles and forums related to this particular error (I would start here).

With regards to the results you are seeing, I would be interested to see the behavior of the gate signal that you are providing to the counter.  Do you have the ability to scope the signal and provide a screenshot?  I think looking at this signal could point us in the direction we need to go for troubleshooting.

Regards,
Andrew
0 Kudos
Message 4 of 4
(4,081 Views)