Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Change Counter sample to read dynamically and sample the card every 200 millisecond.

Hi,

I am using a PCI-6602 card and I need to sample the card every 200 millisecond.

According to the "MeasDigFrequency_LowFreq1Ctr" example, I have implemented a code that samples the frequency continuously.

My problem is that if I set the variable SamplesPerChannel to be 1, when my frequency is 1 KHz, I receive many callbacks which is too much and affects the performance. If I set SamplesPerChannel to 20, and the actual frequency is 2Hz, I receive callbacks every 10 second which is not enough.

I try to use another method, according to the "CountDigEvents" example, I have implemented a code that read every 200 millisecond the numbers of event that occur in that period of time (which is supposed to be equal to the frequency). However, I cannot calculate exactly the frequency due to windows clock accuracy.

  1. Is there a way to set the SamplesPerChannel dynamically? (when the task is already running)
  2. Could I read every 200 millisecond all the samples (frequency) that are arrived from the last point of my last reading?

Thanks,

Simon.

 

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

Hello Simon,

 

To answer your first question, whether or not you can set the SamplesPerChannel dynamically is determined by the card you're using. I looked it up and the PCI-6602 card does not have this functionality enabled. 

 

As far as your second question goes, I would institute a 200 millisecond wait in the while loop that is reading the data. Then, if you set number of samples per channel to -1, it will empty the buffer entirely every 200 milliseconds. I made some sample code in LabVIEW that you can see below.

 

Hope this helps answer your questions. 

 

Zoe B.

Account Manager - Pacific Northwest
0 Kudos
Message 2 of 4
(3,292 Views)

Hello Zoe,


I don't know LabVIEW. I work in C#.
Could you please write the example in C#?


Thanks,
Simon.

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

Hi Simon,

 

I am not a fluent coder in C#, but the LabVIEW code I sent is actually just a shipping example that I modified slightly. As such, there's a corresponding C# shipping example you could use as a reference called Measure Digital Frequency - Low Frequency - 1 Counter. 

 

A list of all the shipping examples and how to access them are found here.

 

Since the inputs/outputs of the functions are the same in LabVIEW as C#, you would change the corresponding number of samples per channel value to -1 and institute a wait within the while loop. 

 

Zoe B.

Account Manager - Pacific Northwest
Message 4 of 4
(3,268 Views)