Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change sampling rate in DAQmx PCI-6229 device

1) My DAQmx 6229 device has totally 32 channels. The max AI Conv rate is 71428.57 (got it by from attribute DAQmxGetTimingAttribute (...., DAQmx_AIConv_Rate, ...), SampClk_MaxRate is 250K, and SampClk_Rate is 7812.5 (so you can see 250K = 32ch * 7812.5)

2) My task has 2 channels. I configured them using
    rtn = DAQmxCfgSampClkTiming(taskHandle, NULL, sampleRate,
                                    DAQmx_Val_Rising, DAQmx_Val_ContSamps, 180);
    where sampleRate=5000.0
then I went ahead and read the signals (a 500Hz square waveform) by using
    rtn = DAQmxReadAnalogF64(taskHandle, 180, 10.0, DAQmx_Val_GroupByChannel,
                 inData, 2*180, &daqRead, NULL);
In the square waveform I read, I found there were about 80 samples per cycle. Since the waveform is 500Hz, that means my sample rate is about (80*500=)40KHz.

3) The questions is: Is there any way to change this sample rate? I tried to use
    rtn = DAQmxSetTimingAttribute (taskHandle, DAQmx_AIConv_Rate, my_sample_rate);
then use
    rtn = DAQmxGetTimingAttribute (taskHandle, DAQmx_AIConv_Rate, &my_sample_rate);
to read back. It did show I'd successfully changed it. But when I did the sampling, the DAQ card was still sampling at 40KHz per channel.

Thank you very much.
Jason

0 Kudos
Message 1 of 9
(3,971 Views)
Hello JasonJ,
I've got a few things I'd like to clarify for you.  The sample rate set with DAQmxCfgSampClkTiming is the sample rate for the acquisition.  If you set it to 100, then all channels will be sampled at 100 Samples/sec, or (in other words) each channel will be sampled once every .01 seconds (1/100).  If you want to query the sample rate of the acquisition to verify that it is what you set, you can use the DAQmxGetSampClkRate function. 
The convert clock is what controls the interchannel delay when sampling more than one channel.  So I don't think you actually want to use the convert clock.  FYI - the max convert clock rate is equal to the max sample rate of the device, and can be queried with the DAQmxGetAIConvMaxRate function.
I hope this helps.
-Alan A.
0 Kudos
Message 2 of 9
(3,957 Views)
Thanks for the reply, and sorry I haven't made it clear.

Actually, "sample rate for the acuisition" is the only thing I care. I set it with function call DAQmxCfgSampClkTiming (). But seems it's not working. No matter what value I set  (eg, 100, 5000), I got the results described in item 2) in my previous post, which is: I always got the sample rate of about 40KHz (80 samples per cycle on a 500Hz waveform).
Because of this, I thought maybe I need to play with the convert clock....

Thanks again.
Jason
0 Kudos
Message 3 of 9
(3,952 Views)
Hello JasonJ,
Unless the sample clock gets set somewhere else in your program (either with the DAQmxCfgSampClkTiming or with DAQmxSetSampClkRate property) then its rate will be set by the sample rate input to the DAQmxCfgSampClkTiming function, barring a defective device.  I would suggest taking a look at your math again, double checking the data in your array, and how it is returned (interleaved or not), etc.  Also, where is this 500Hz waveform coming from.  Could its frequency be changing??  If you wanted another way to verify the sample rate (besides the function mentioned in the previous post), you could use a DAQmxSetExportedSampClkOutputTerm function to export the sample clock.  Then you could measure its frequency either with an onboard counter of your M Series device or an external device.
-Alan A.
0 Kudos
Message 4 of 9
(3,947 Views)
Here is my code to do the sampling:

    rtn = DAQmxStartTask(taskHandle);
    rtn = DAQmxGetTimingAttribute (gDAQmxAnalogInTask, DAQmx_SampClk_Rate, (void *)data);
    rtn = DAQmxReadAnalogF64(taskHandle, numSamplePerCh, 10.0, DAQmx_Val_GroupByChannel,
                 inData, numCh*numSamplePerCh, &daqRead, NULL);

The sample clock rate DAQmxGetTimingAttribute () returned to *data is 5000.
In DAQmxReadAnalogF64(), numCh=2, numSamplePerCh=180, the samples returned in inData showed that there were 40 samples high, 40 samples low for one cycle.

I changed the sample rate to 100 and did again, and got the same samples in inData.

I used scope to check the signales I sampled. It was always a 500Hz square waveform.

Thanks.
Jason
0 Kudos
Message 5 of 9
(3,942 Views)
To simplify, could you try just one channel and let me know the results?  Also, what channel (s) are you using, how have you connected to them, and what terminal configuration are you using (diff/rse/nrse).
-Alan A.
0 Kudos
Message 6 of 9
(3,938 Views)
I found the problem. It's stupid. I was using a wrong task handle. I found this when I got problem using the other task.

All problems solved now. Very sorry for wasting your time and thanks a lot.

Jason
0 Kudos
Message 7 of 9
(3,931 Views)
No problem.  Best of luck with your project:)
-Alan A.
0 Kudos
Message 8 of 9
(3,918 Views)
Thank you very much.

I like NI.

Jason
0 Kudos
Message 9 of 9
(3,910 Views)