LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to count pulse with digital input on 6351

Solved!
Go to solution

Hi all Labview experts,

 

I just got my usb x series 6351 and it works great, but I am certainly lacking in labview skills to use it to its full potential. 

 

I would like to read digital pulses with multiple digital inputs, and count the number of pulses every T interval in time. All the pulses that I am inputting are not synced at any clock edge, and can occur at random times during the testing. I basically have a square wave oscillator that I can modulate the frequency. I do not want to use the counter as inputs as I am then limited to only 2 inputs (if I use the 2 input counter option to get the pulse count or frequency). The input frequency can go from 0-1kHz, and goes from 0-3V. So not too fast, and I shouldn't get too much error in trying to get the pulse count and then backing out the frequency as per ni.com article on counters.


I would like to read out 8 digital input channels and get the pulse count for each channel. I searched high and low for help online but couldn't find any examples that were helpful. Anyone has ideas on how to go or direct me to a useful resource? Thanks very much in advance!  

 

0 Kudos
Message 1 of 5
(5,690 Views)
Solution
Accepted by greylocks

Are you worried about getting the count as a hardware timed operation?  Would it be okay to acquire a digital waveform, and then postprocess on it to detect how many events occured?  I've attached an example that shows how you might accomplish this. It reads in a digital waveform, and then uses a peak detection VI to determine how many pulses occured. It would take some tweaking for your particular signal.  The VI i'm using seems to count twice as many events (likely counting each edge), so the count it gives needs to be halved in order to work.

Applications Engineer
National Instruments
Message 2 of 5
(5,667 Views)

Hi Jonathan, 

Thanks for the quick response! Your solution works well. I am not too worried about using a hardware timed operation. What kind of benefit does that give me?


When you say tweaking, what do you mean? I tried playing around with the sample rate and number of samples, and it seems I have to set the number of samples less than the sample rate in the sampling subvi. Right now, I set it to 1000 samples and 10000 rate. I also changed the sampling to continuous sampling. In my digital waveform chart, I see the values from 0 to 0.1s. So is the count for 0.1s such the actual frequency is 10x of the counts?

 

I guess the only issue with this method is I cannot easily get a low frequency count. I tried setting both number of samples and sample rate to 10000, but it doesn't seem to register a count even though I am pretty sure the signal is oscillating. However, the graph shows from 0 to 1s instead.

 

If I want to continously sample, where is best to wrap the loop? Right now I just use the run continuous button to

keep running the vi.  


Thanks again!!

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

I am not too worried about using a hardware timed operation. What kind of benefit does that give me?

 

Using hardware timing allows you to count a rising edge as it occurs in hardware.  You are basically reading out the count from the physical counter on your device.  Doing it in software requires processing time and an accurate algorithm.

 

When you say tweaking, what do you mean? I tried playing around with the sample rate and number of samples, and it seems I have to set the number of samples less than the sample rate in the sampling subvi. Right now, I set it to 1000 samples and 10000 rate. I also changed the sampling to continuous sampling. In my digital waveform chart, I see the values from 0 to 0.1s. So is the count for 0.1s such the actual frequency is 10x of the counts?

 

To do continuous sampling, you will need to place your DAQmx read in a while loop.  You can then add the counts together each time the loop iterates to get your total count.  I'm a little worried about doing a continuous acquisition this way, because I'm worried that pulses that occure at the edge of an acquisition will not be counted. A way to get around this is to analyze all of the data after the acquistion.  If you must do it at the same time you are acquiring, the best way to do this will be to append each acqusition to the previous so you have one big array that represents all of the data.  This way, edges won't get ignored.  I've attached an example that shows this.  It might be a little intimidating because it uses queues.  Queues are used to pass data between loops.  I did this because I was worried about the processing time involved in the edge counting acquisition once the array got too large.  I think this should also help with your low frequency counts.

 

Jon

Applications Engineer
National Instruments
Message 4 of 5
(5,648 Views)

Hi Jon,

Thanks for your reply! 

I see what you mean. I don't need for an accurate count from sample window to window. What I do hope to achieve though is the ability to read multiple digital inputs. Right now the softwareCount works quite well, except that there is only one digital input. I changed to to read multiple lines from port 0, and that works fine. But I have a problem trying to get peak counts for each line per sample window. It seems that the daqmx read task returns a digital waveform. Is there anyway to get individual line data?

 

Also, do you have recommendations for labview books on this topic of digital daq? The help files aren't exactly very useful when I am not familiar with the palettes..


Thanks so much!

0 Kudos
Message 5 of 5
(5,625 Views)