LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting Daqmx digital input

Hi, I am pretty new to Labview trying to figure out how to count the number of times a digital input changes within a second. My test setup includes a cDAQ with NI 9403 and a waveform generator outputting square wave to line0. Expected frequency for digital input would befrom 1kHz to 45kHz. I have set the sample rate to 90000, however, the code appears to be working only for higher frequencies of square wave, i.e for 45kHz and as the frequency from waveform generator is reduced the counter does not provide any accurate data. For lower frequency, the code will work if I lower the sample rate by stopping the vi and running it again. But this is not practical as once deployed I will not be knowing the input frequency anyway.

 

What am I doing wrong here? Any helps would be much appreciated, including any literature on DAQmx functions. I wrote this code after referring to example codes and online.  

0 Kudos
Message 1 of 3
(978 Views)

Hi Dante,

 


@Dante616 wrote:

What am I doing wrong here? Any helps would be much appreciated, including any literature on DAQmx functions. I wrote this code after referring to example codes and online.  


Reading "1 sample" at a samplerate of 90kS/s is wrong. Read chunks of 9000 samples instead!

 

Can't you define the digital input as counter? Then you can just read the counter values instead of counting edges on your own!

 

LabVIEW comes with a huge example library, including a lot of example VIs for DAQmx…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 3
(943 Views)

The most important thing to do is to change from a Digital Input task to a Counter task.  Counting edges is exactly what counters *do*.  See the shipping examples for a counter task that counts edges.

 

If you need to know the timing of the edges, you can look to the example for continuous freq & duty cycle which can actually be configured for a wide variety of measurements.  Frequency or Period measurement can give you the timing for a full digital cycle (either rising to rising or falling to falling).  Semiperiod gives you the durations of each "half" of the digital cycle, alternating between the high and low times.

 

Depending on which cDAQ chassis you have, its counters *might* support a newer "pulse measurement" mode, which can accomplish the same kind of semi-period measurement but will present the data in a friendlier form.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 3 of 3
(940 Views)