Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

AI task slows down counter task?

Hi,
 
I am using PCI6251 to sampling 6 AI channels, and at the same time monitor the frequency of the counter0 input with DAQmx ANSI C in VC++. I created one AI task for finite sampling and one counter task.
 
I set up a timer to sample the AI channels every 200ms and the analog data is about 100ms in length, and the AI task is repeatedly started and stopped. To monitor the conter0 frequency measurement, I created a second thread in which the frequency is measured similar to the example "Dig Freq-Buff-Cont-Large Range 2 Ctr" with the number of samples changed to 50 instead of 1000 in the sample.
 
Now the problem is that when the AI task is disabled, the conter0 could update very fast, but when the AI task is enabled, the counter0 updates very slow. Then I removed the timer, and started the AI task in the same thread as counter0, the problem remained.
 
So what did I do wrong? If I have to realize such a task combination, would anyone suggest a suitable way to do it without slowing down either of them?
 
Thanks a lot!
David
0 Kudos
Message 1 of 7
(3,118 Views)

Hi David,

If you are constantly restaring the tasks or even just the AI task, it would be better to change to continious acquisition since the stop/start task takes lots of overhead.  I do not think 100ms is enough time to stop task and restart task.  Use the read property node to monitor available samples, my guess is that the buffer is increasing and is lagging the UI.  If you log data with a time stamp does the lag show up in the file? I'll bet it does not.  If you are persistent on finite acquisition, change the read relative to last sample property.

I had more channels also with encoder doing same thing you are and max rate i could acheive for a sustained amount of time was 1000Hz.  By changing to continuous i can acheive 30,000Hz.  Huge difference!

Chris

0 Kudos
Message 2 of 7
(3,104 Views)

Hi, Chris,

I considered continuous sampling before, but my concern was the buffer overwritten error that bothered me in another project. If I don't care about the data overritten, is there any way to disable the overwritten error? I tried a function before that was supposed to do this job but without success.

Thank you very much.

David

0 Kudos
Message 3 of 7
(3,100 Views)
Hi David,
I have just noticed you are not using LabVIEW! Sorry about that!  However there should be some way to monitor the available number of samples in the buffer.  What is your acquisition rate and number of samples for each task?  When you mentioned you changed the number of samples from 1000 to 50 you are actually making the computer work harder to keep up which stacks up the buffer.  For instance, if you want to acquire 1000 samples per second, a "good" number of samples to read maybe 100 (depending on your computer and # of DMA channels.  The program loop speed would be need to acheive 10Hz.  If I post my code in LabVIEW, are you able to use it?
 
Chris
0 Kudos
Message 4 of 7
(3,091 Views)
Hi, Chris,
 
I can't use Labview code. Actually, I tried to use DAQmxSetReadOverWrite func to allow the data overwritten, but it seemed not successful and the overwritten error kept popping up. Someone replied in this thread http://forums.ni.com/ni/board/message?board.id=250&message.id=24413#M24413. I tried as them told me but still got no luck. Would you help me out?
 
Best regards,
David
0 Kudos
Message 5 of 7
(3,060 Views)

Hi David,

I never had any luck with the overwrite function either-maybe its broken!! I do know that the relative function works like a charm though.  Some data may be missing (small amounts).  DAQmxSetReadRelativeTo(10428) or DAQmxSetReadRelativeTo(MostRecentSample).  As i really do not know VB language I'm problaby not much help.  Try the DAQmxSetReadRelativeTo(10426) or DAQmxSetReadRelativeTo(ReferenceTrigger) and clock the analog in task on the counter.

How are you setting up the counter clock.  I usually use the analog in sample clock to clock the counter.  You will have to specify a channel, at least in labview you do.

I wish I could be more help. 

Chris

0 Kudos
Message 6 of 7
(3,055 Views)

Hi, Chris,

I just figured out how to realize a continous sampling in DAQmx ANSI C and successfully avoided the overwritten error with DAQmxSetReadRelativeTo. Thanks a lot.

I used the counter to measure the freq of the input signal connected to the counter gate. I set the counter source to be the 20MTimeBase. Since the input signal freq is no higher than 5K, one counter is enough.

Thanks again.

David

0 Kudos
Message 7 of 7
(3,050 Views)