Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read multiple channels based on exteral clock

Solved!
Go to solution

Hi,

 

I am using 6254 multifunction DAQ for reading voltage with VC++ 6 as the development tool.

 

Based on NI documentations I created tasks like this.

 

DAQmxCreateTask(_T("Voltagetask"),&taskHandle);

DAQmxCreateAIVoltageChan(taskHandle,sChannels,NULL,DAQmx_Val_NRSE,0,10,DAQmx_Val_Volts,NULL);

DAQmxCfgDigEdgeStartTrig(taskHandle,"PFI2",DAQmx_Val_Rising ); 

DAQmxCfgSampClkTiming(taskHandle,"PFI2",303000,DAQmx_Val_Falling,DAQmx_Val_FiniteSamps,nSamples);

DAQmxStartTask(taskHandle);

 

After the finite clock generation with the help DAQmxReadAnalogF64 function I tried to read samples from each channels.

 

DAQmxReadAnalogF64(taskHandle,DAQmx_Val_Auto,10, DAQmx_Val_GroupByScanNumber,read,m_nStates,&sampsPerChanRead, NULL);

 

Total samples (nSamples) available in buffer when created task with single channel and multiple channels are always coming as same. In multiple channel modes it returns total sample per channel which is equal to total samples divided by number of channel at a time.

 

I.e., If total clock count is 8000

            With single channel it read all 8000 samples      (m_nStates=8000,  sampsPerChanRead=8000)

When two channel it read 4000 samples per channel and so on.(m_nStates=8000,  sampsPerChanRead=4000)

 

If any body know, on each clock how to take samples from all configured channels.

 

Thanks in advance,

Renjith.

0 Kudos
Message 1 of 4
(3,294 Views)

Renjith,

 

the behavior you are seeing is expected. The reason is simple: The device has only a single ADC and your clock will digitize a single value using this ADC.

So if you connect an external clock to the device and the external clock source creates 10 pulses, you will acquire 10 samples. This is independent from the channel count.

So if you have only a single channel, the device will acquire 10 samples for this channel.

If you have two channels, the device will acquire 5 samples for each channel: ch0, ch1, ch0, ch1, ch0, ch1, ch0, ch1, ch0, ch1

With three channels, you will get: ch0, ch1, ch2, ch0, ch1, ch2, ch0, ch1, ch2, ch0

....

 

So the amount of clock cycles have to match your expectations of number of samples per channel (so sampling 8 channels and desiring 1000 samples per channel, the clock source has to generate 8000 pulses).

 

hope this helps,

Norbert 

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 4
(3,268 Views)
Solution
Accepted by topic author Renjith

Renjith,

 

please note that the behavior i explained aboved is only expected if you use your clock as AI Convert Clock. You can find information on the different clocking types of analog inputs in the NI-DAQmx Help; the item to search for is "clocks".

Since you do not set the AI Convert Clock (would require DAQmxSetAIConvSrc()), the fact i stated above is only informative for you, but does not apply to your question.  Sorry for answering too fast without looking into your quoted code...

 

In order to answer your question, we should take a look into the approach of DAQmx-programming:

If you configure your task to be "finite", the task will stop working if the set number of samples per channel is acquired. In the case of an external clock (not configured as AI Convert Clock), the AI will sample in Interval Sampling. The sample clock will automatically acquire one sample for all channels with a single clock pulse. From this point of view, the setup you have in your program seems correct.

 

If you don't get the number of samples you are expecting, the fault has to be somewhere in your Read function. Do you get any error messages?

 

DAQmxReadAnalogF64(taskHandle,DAQmx_Val_Auto,10, DAQmx_Val_GroupByScanNumber,read,m_nStates,&sampsPerChanRead, NULL)

If you configured m_nStates to be fixed at 8000, the reason is here. You tell the Read function to retrieve 8000 samples. No more. So if you have two channels, DAQmx acquires 2x8000 samples, but you read only 8000 samples..... Please change m_nStates to

 

m_nStates = #channels x #samples per channel

  

 

This should solve your problem.

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 4
(3,249 Views)

Hi Norbert,

 

You said it, The problem is in read function only. When I modified it like this 


DAQmxReadAnalogF64(taskHandle,-1,100, DAQmx_Val_GroupByChannel,read,m_nSamples*m_nNoofChannels,&sampsPerChanRead, NULL);

Then the function can read all the samples available in buffer.

 

Thank you Norbert,

Renjith.

0 Kudos
Message 4 of 4
(3,240 Views)