From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I acquire multiple counter inputs without timeout error

I am using two counters to read an encoder and a flow meter.  At the same time other I/O is going on.  At times the encoder and flow meter are generating pulses.  Other times the flow meter is not.  The problem I have is that when I am receiving no signal from the flow meter the entire process gets hung up while waiting for a timeout.  I need to continue to collect data from all I/O at a specified frequency while one counter is waiting for a signal.  

I have tried to use multithreading for the counters only but this still holds up the acquisition of the second counter.  

 

One way I have thought about is to buffer both of the counters and check if there is any available data on either.  If there is data then read just the last/current data point?

 

Any one have any suggestions on how to handle this or good examples?

 

 

Windows 7

CVI 2012

PCI-6036E

0 Kudos
Message 1 of 5
(3,744 Views)

Anyone have a good example using DAQmxGetReadAvailSampPerChan or DAQmxGetReadTotalSampPerChanAcquired for counter channels?  These sound like they would work but there is very little documentation on these.

0 Kudos
Message 2 of 5
(3,728 Views)

Hi Mike,

 

I think a good starting point would be to take a look at the LabVIEW example here for buffered counter encoder input: https://decibel.ni.com/content/docs/DOC-11642.

 

So the way this should be possible in CVI would be to use sample clock timing for your encoder counter task, but use an external clock source for the timing configuration (the LabVIEW example uses another counter's frequency output).

 

But ideally, if you have the counters set to a different timing source and on a different task than your other I/O, then they should be able to run independently.  I haven't seen any examples of this with multiple counters but I think you could run them both on the same timing source.  If you could clarify more what you mean by 'holding up' the other task that would help as well.

0 Kudos
Message 3 of 5
(3,711 Views)

The hold up is due to the read function timeout.  The amount of time that I see the counter read function run is between 0.015 - 0.025 with the timeout set to 0.  I am trying to sample my data at 0.01.  This inconsistent time that the counter read function runs is longer than my timer tick.  You can view this behavior with any of the examples measuring period or frequency in CVI.  Load the example and run with no counter input.

 

 I could use multithreading for ever counter that I have but, that could get messy.  

 

0 Kudos
Message 4 of 5
(3,703 Views)

Hi Mike,

 

It is also that sometimes that you were running out of samples. If it is a continous acquision that was internally clocked. The primary idea to keep in mind is that the the DAQ card and the code running in Windows are sychronously disjoint and it would be very possible, depending on the rate that you are sampling, and the rate that your softwaer loop iterates that there are actually no samples available on some iterations, for instance if there is no delay in your loop, its very possible that there will be no samples available by the time the next iteration comes around. So maybe slowing down in between calls to query the available samples can solve the issue.

National Instruments
Applications Engineer
0 Kudos
Message 5 of 5
(3,674 Views)