Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Delay in o/p at prompt when executing 'acquire1scan' example

Hi There,

              I've just started to use NIdaqmx base software for data acquisition using USB-6009.  I am using Linux running on a P4 machine. When  I execute 'acquire1Scan' or 'acquireNScans' example programs provided by NI ( /usr/local/natinst/nidaqmxbase/examples/ai), the output appears at the prompt after 8 or 9 seconds. I wanna know the likely cause for this and Is it possible to reduce this delay?.

 

Secondly I intend to implement circular buffer (or ping-pong style buffering) for single channel analog input from USB-6009. This means that I intend to process 1st buffer (e.g of length 20,000 bytes) while receiving the second at the same time, so that when the 2nd buffer is received I toggle my processing buffer from 1st to 2nd while receiving the 1st buffer, in a synchronised fashion. Is there any example code script that implements this fairly generic functionality using NIdaqmx base sriver software.

 

Regards,

Adeel

0 Kudos
Message 1 of 19
(4,731 Views)

Hi Adeel,

 

It makes sense that there could be an 8 to 9 second delay with the acquireNScans example depending on the number of samples and the sampling rate.  The fact that the acquire1Scan exhibits the same delay indicates that samples and sampling rate is not the issue, so the next thing to try is to acquire a scan multiple times in a row inside of the example so that you set up the task and then acquire 1 point multiple times before closing.  This will show where the overhead comes into play.  My guess is that even with 10 1 point samples in a row, the modified example will still take around 8 or 9 seconds to complete.  My guess is that on your machine the amount of time it takes to ready the DAQ device to sample and clear is on the order of seconds.  Experiment with this and see what you find.

 

This forum post talks a bit about circular buffers.  The DAQmx calls should take care of streaming the data to your computer and the buffering that is acquired for this.  If there's any reason you need the set this up, can you elaborate so that we can find some more detailed information?

-John Sullivan
Problem Solver
0 Kudos
Message 2 of 19
(4,705 Views)

Hi John,

             Thanks for your reply. Another thing i wanted to ask is that what is the min. sampling rate (or sampling rate accuracy) that could be set for the USB-6009.?. Is it possible to set 20000.1 Hz or 20.0001 kHz for USB 6009 ?. Or if we set the samp. rate to 20000 Hz, by how much proportion it could vary in real-time.

The reason I want to set the sampling rate so precise is that in my scenario I have two machines, one is the windows machine generating a test signal (let say 2500 Hz) and the other one is the linux machine sampling that signal at 20kHz via the USB-6009. Since both are transmitting and receiving the data independently, so there must be a small difference in the clocks of both machines and so over the period of time 10s to 100s of seconds, there will will either be a lag or lead on the receiver side depending whether the receiver application sampling clock is lagging or leading to the transmit application clock.

In my case the receiver application is always lagging and I have confirmed this thing by implementing a certain logic. Now I want to test is it possible to make the receiver 'lead' the transmitter side by increasing the sampling clock to let say 20.0001 KHz.

 

Regards,

Adeel

0 Kudos
Message 3 of 19
(4,629 Views)

Hey Adeel,

 

The sample clock is obtained by dividing down our master timebase.  Take a look here, here, and here for more information on how this is achieved.  Let us know if you have any more questions.

-John Sullivan
Problem Solver
0 Kudos
Message 4 of 19
(4,613 Views)

Hi John,

            Thanks for the reply. I read the datasheet and found that the timebase for USB-6009 device is 24 MHz. So assuming it to be an M series device with Analog Input sample clock divisor of 32 bits, the sampling rate resolution comes to about 24 MHz/ 2^32 or 0.00558 Hz. This means that sampling clock rate can be set in steps  of 0.00558 Hz, thus for 20kHz set value, the actual sampling rate would be about 19999.9976 (since 20 kHz is not eaxctly divisible by 0.00558 Hz).

On the contrary, in the knowedgebase "How Is the Actual Scan Rate Determined When I Specify the Scan Rate for My Data Acquisition", calculations are bit different, as shown in the following steps.

  1. 24MHz/20kHz = 1200 (no remainder). 
  2. Actual Sample Clock Rate = Board Clock / 1200 = 20000

Could you please comment which is the correct way of calculating the sample rate.

 

Regards,

Adeel

0 Kudos
Message 5 of 19
(4,602 Views)

Hey Adeel,

 

The USB-6009 is not an M series device.  The second calculation is used for DAQmx Base (which you are using).  This is the correct calculation. 

-John Sullivan
Problem Solver
0 Kudos
Message 6 of 19
(4,587 Views)

Hi John,

Thanks for pointing towards the correct calculation. I have got two more issues:

1. Apart from USB-6009, there is another card installed in my system which is PCI-6251. When i tried to run the code (that was sampling an analog signal at 20 kHz with a buffer size of 2000 samples in a continuous fashion) that was running ok on USB-6009, I got the following error message:

DAQmx Base error :42

Since the aforesaid code was implemented by extending the example program 'contacquireNchan.c' function, when i run this example function i get the error message:

RLP invoke node: DMA buffer overflowed.....

Could you point out the cause and likely solution for this problem.

2. I want to use PCI-6251 in a simultaneous analog-out and analog-in fashion. Precisely speaking, I want to generate 2500 square wave using either analog out or digital out and then looping it back to analog-in to read at fs=20 kHz (8 times the signal freq) such that both the 'write task' and 'read task' trigger at the same time. Could you suggest an example code with some explanation to achieve the afore-said functionality.

Regards,

Adeel

0 Kudos
Message 7 of 19
(4,570 Views)

There is one more issue that I forgot in my previous message. When I am running the example program for coninuous analog output generation (../examples/ao/contGeneration ) using PCI 6251 Ao0 channel, I get the following error message:

DAQmxBase Error: Attempted to write data that is too large or too small.

The datasheet indicates that FIFO size for analog out is 8191 samples for two channels. I have tried to set the buffersize to different values but to no avail.

Could you also please suggest how should I modify the example 'contGeneration.c' file for PCI-6251.

Thanks,

Adeel

0 Kudos
Message 8 of 19
(4,553 Views)

Hey Adeel,

 

In the future, please create a new forum post for new issues so that we can keep individual forum posts modular.

 

The reason your code doesn't work on your 625x is that DAQmx Base is not supported on that card.  You will need to use DAQmx for the 625x.  Your existing DAQmx Base VIs will need to be replaced with the corresponding DAQmx VIs.  This is because DAQmx and DAQmx Base are two different codebases. 

Message Edited by Knights Who Say NI on 02-04-2009 10:06 AM
-John Sullivan
Problem Solver
0 Kudos
Message 9 of 19
(4,544 Views)
 If both analog input and analog output tasks are going to be running at the same rate then you can just modify the DAQmxCfgSampClkTiming source for the analog output to be the analog input sample clock.  Then, as long as you start the analog output task first they will be synchronized because even if the analog output is started before the analog input the sample clock won't be available until the analog input is also started
-John Sullivan
Problem Solver
0 Kudos
Message 10 of 19
(4,542 Views)