11-26-2012 05:36 AM
Hi All
I have a USB 6211 that I am trying to use to measure a pulse width or period. The input to the timer gate is the A output of a rotary encoder and I need to know the instantaneous speed of this encoder. The minimum pulse width is 100uS - the maximum is about 10ms. I want to use the internal 20MHz or 80MHz clock to time these pulse widths. Using an example I found I have the following C code that works
DAQmxErrChk (DAQmxCreateTask("Pulse Width Measurement Task",&taskCounter));
CreateChannelName( channelName, deviceName, "ctr0" );
DAQmxErrChk (DAQmxCreateCIPulseWidthChan (taskCounter, channelName, NULL, 4000, 40000, DAQmx_Val_Ticks, DAQmx_Val_Rising, NULL));
I then read the samples with
DAQmxErrChk(DAQmxReadCounterU32 (taskCounter, 1023, 10.0, TimeSamples, 1023, &SamplesRead, NULL));
The problem is that if I put the following code into the device I can catch every sample up to 1000Hz. After that I seem to catch every other period.
I think this is because the code works in the "On Demand" mode.
DAQmxErrChk (DAQmxCfgSampClkTiming (taskCounter, deviceName, 10000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 10000));
DAQmxErrChk (DAQmxGetBufInputBufSize (taskCounter, &bufSize));
I have tried to add the above lines to put it into continuous mode but I get an error complaining that I need to select an external clock. Do I need to configure an output to act as a sample clock for the continous stream?
I am sure I am making a simple mistake here but I have not worked out what it is yet.
Any help appriciated.
Thanks
John
11-27-2012 11:30 AM
Hello John,
Would it be possible for you to upload the relevant code for me to have a further look at?
Regards,
11-28-2012 02:09 AM
Found the solution - I needed to call DAQmxCfgSampClkTiming to change from "On Demand" sampling to "Continuous" sampling. My problem was that all the documentation says that NULL is acceptable for the second parameter but it generates an error. Although the program works fine without this call it to DAQmxCfgSampClkTiming, it only works in "on Demand" mode.
DAQmxErrChk (DAQmxCreateTask("Pulse Width Measurement Task",&taskCounter));
CreateChannelName( channelName, deviceName, "ctr0" );//This just creates the correct name for the crt0 source on this device
DAQmxErrChk (DAQmxCreateCIPulseWidthChan (taskCounter, channelName, NULL, 4000, 40000, DAQmx_Val_Ticks, DAQmx_Val_Rising, NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming (taskCounter, "80MHzTimebase", 80000000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 10000));
I then read the samples with
DAQmxErrChk(DAQmxReadCounterU32 (taskCounter, 1023, 10.0, TimeSamples, 1023, &SamplesRead, NULL));
I wasted about a day chasing down this problem - the documentation was just wrong and the name of the function "DAQmxCfgSampClkTiming" does not lead to the conclusion that it changes the transport mechanism for the data - which is all this call does for me in this application,
Regards
John
11-28-2012 04:47 AM
Hello John,
I am pleased that you have rectified the issue however please accept our apologies that this was not resolved more swiftly.
I am sure that you are now aware that the 'On Demand' mode returns a sample every time the 'DAQmxRead' is called and is therefore software timed. For higher precision and more determinism than available in the windows operating system it is necessary to use hardware timing which can be accessed via the 'DAQmxCfgSampClkTiming' as per your current code.
To enable us to improve this would it be possible for you to point me to the document which was either incomplete or caused confusion?
Kind Regards,
11-28-2012 05:37 AM
Jamie
1) Have a look at the example programs for pulse width or period measurement - there is no example that creates a continuous stream. Actually I found one that uses DAQmxCfgImplicitTiming which may be a solution but I have not tried it.
2) Have a look at the DAQmxCreateCIPulseWidthChan or Period documentation. The setting of continuous or On Demand mode should be in this call but there is no mention of how to control this in the text that describes these commands. Continous or On Demand mode is not even mentioned.
3) Have a look at the DAQmxCfgSampClkTiming documentation.
a) It states that to use the onboard clock you pass NULL - this causes an error.
b) active edge re-specifies information that was configured in the PulseWidth command
c) The names of this command has not hint that it controls the mode of transfer of data
It would just need a quick overview on the On Demand and Continuous modes as applied to the counter applications to be inclued in the DAQmxCreateCIPulseWidthChan and DAQmxCreateCIPulsePeriod Chan descriptions.
Regards
John
11-29-2012 04:22 AM
Thank you for the feedback John,
May I also enquire which version of LabWindows/CVI you are using?
Also may I point you to the following DAQmx help document which describes the different timing modes as a useful reference:
http://zone.ni.com/reference/en-XX/help/370466V-01/mxcncpts/smpletimingtype/
I am slightly unsure unsure exactly what you mean by 'mode of transfer of data' in relation to the DAQmx functions. The timing configuration functions specify only how the signal is sampled and acquired into LabVIEW / LabWindows CVI. If there is any more clarification or assistance I could provide in this area please let me know.
Kind Regards,
11-30-2012 08:48 AM
Sorry to hijack the thread but this is close to what I am trying to do.
I am using LabVIEW 8.5 with a USB-6210 and I want to measure pulse widths on Ctr0. My pulses are fed to the gate of Ctr 0 (Pin 2) but there are no other connections. I ahve used Implicit timing in my VI and I am simply measuring pulse widths from a source with a 4.5MHz clock. So I should get pulse widths separated by about 18 clocks (80 MHz / 4.5 MHz) yet I get values all over the place. I would like to know more about how to wire up the 6210 for acurate pulse width measurements but have never seen any such information.
Is my setup ok or too simple. If it's too simple how can I improve it?
Thanks
Malcolm
12-03-2012 05:29 AM
From what you have described it seems like you have the module connected correctly to measure the period of a signal on the Gate of Ctr 0.
If you are using the Internal Source then you specify the expected range of the input signal when you set up the task. Based on this range, NI-DAQmx automatically picks the internal timebase that provides the highest resolution for your measurement and uses it as the counter timebase. You also can explicitly specify the source of the counter timebase by setting the Counter Timebase Source attribute/property and the rate of the timebase by setting the Counter Timebase Rate attribute/property.
Please also see the section of your Device's manual relating to Pulse Width Measurement which can be found at the following link:
http://www.ni.com/pdf/manuals/371931f.pdf
Finally please see the following VI snippet(attached) from the LabVIEW 2012 Example Finder which depicts Continuous Pulse Width Measurement using the DAQmx functions.
Regards,
12-03-2012 05:39 AM
Dear Jamie,
Thanks for the information. I had it set up mostly as you show in the PNG file, but I will add a bit of code that I didn't have. I had read the manual but they are often too generic. I much prefer simple pictures and code, they let you know what real-world examples work.
I think the problem is with my source, not my measurements, but thanks for confirming that what I am doing is correct.
Regards
Malcolm Myers