Quantcast
Channel: Counter/Timer topics
Viewing all articles
Browse latest Browse all 1271

Reading a counter is really slow

$
0
0

I have some pretty simple code that tries to read out a counter at <8 Hz for display on an X series.  On each read 1024 samples are requested and then displayed.  I've noticed that reading out the counter is remarkably slow given how few samples are requested (~90-100 ms) such that doing this without an asynchronous read is almost impossible (nearly 100% of thread time is spent in the counter read call).  Is there a reason for this?  The counter is buffered and the data being requested is negligable (few KB).  Am I missing something?

 

Rough code:

 

int numberOfSamples = 1024;

myXCounterTask->CIChannels->CreateLinearEncoderChannel("Dev1/Ctr3", "X Counter", CIEncoderDecodingType::X1, false, 0, CIEncoderZIndexPhase::AHighBHigh, 200E-9*1000, 0, CILinearEncoderUnits::Meters); 

 

...some ommitted code to configure PFI lines for reading

 

myXCounterTask->Timing->ConfigureSampleClock("/Dev1/PFI0", 8000, SampleClockActiveEdge::Rising, SampleQuantityMode::ContinuousSamples, numberOfSamples*10);

 

myXCounterTask->Triggers->ArmStartTrigger->Type = ArmStartTriggerType:Smiley Very HappyigitalEdge;
myXCounterTask->Triggers->ArmStartTrigger->DigitalEdge->Source = "/Dev1/PFI4"; 
myXCounterTask->Triggers->ArmStartTrigger->DigitalEdge->Edge = DigitalEdgeArmStartTriggerEdge::Rising;

 

//buffer a lot of samples to be sure we don't lose any
myXCounterTask->Stream->Buffer->InputBufferSize = numberOfSamples * 4 * 20;

 

counterXInReader = gcnew CounterReader(myXCounterTask->Stream);

 

Then my read out function just calls:

 

counterXInReader->ReadMultiSampleDouble(numberOfSamples);

 

I time almost 100 ms per call!   My read doesn't happen until after the counter samples have already been recorded, so I don't think its waiting for samples to arrive.  I also don't see any dropped or missing samples.  I can of course refactor this to use async callbacks, but its surprising to me that the daqmx function call is so incredibly slow, which makes me wonder if I'm doing something wrong.


Viewing all articles
Browse latest Browse all 1271

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>