LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

count pulses with digital inputs on USB-6008

Hi.

What is the easiest method of counting pulses on the digital inputs?

My application requires me to count the number of pulses in 1 second on 6 digital input channels. The maximum pulse frequency will be about 40Hz.

Thanks

Mike

UniSA, Mawson Lakes, South Australia - LV 8.6.1
0 Kudos
Message 1 of 12
(9,622 Views)

Hi Mike,

 

The best method to count digital pulses is to use a counter.  The USB-6008 has one counter that is accessible from PFI0.  Check out page 15 of the USB-6009 specifications manual for a complete description of PFI0.  As shown below, PFI0 is on pin 29:

 

screenshot.jpg

You can wire your digital pulse train to PFI0 (pin 29) and run the example called Count Digital Events.vi.  This example can be found in the NI Example Finder (Help»Find Examples) and going through the following path of folders:  Hardware Input and Output»DAQmx»Counter Measurements»Count Digital Events.

 

Post back if you have any more questions related to this issue.

Regards,

Sara Lewandroski
Applications Engineer | National Instruments
Message 2 of 12
(9,595 Views)

I'm aware of the single counter input, but I need to count pulses on 6 digital inputs.

Attached is my solution so far. I'm hopeful it will work.

UniSA, Mawson Lakes, South Australia - LV 8.6.1
0 Kudos
Message 3 of 12
(9,579 Views)

Have you tried running that?  If so, what happened?  Add indicators to your error lines and check for errors.

 

I do not think you can run separate tasks on the same device.  Read the entire port and then separate the data into separate channels if needed.

 

The biggest problem with this approach is the software timed acquisition (which is the only mode for the USB-6008).  If you cannot acquire fast enough to ensure that every transition on all the lines is captured, you will get erroneous data.  Your technique of comparing current value to previous value via the shift register will count both rising and falling edges, or two counts per pulse.

 

Lynn

0 Kudos
Message 4 of 12
(9,563 Views)

Hey Mike,

 

You could use that program to count digital pulses.  You should be cautious of a few things:

  • In quickly glancing at your program, I saw that you were counting every change on your digital line (both low to high transitions and high to low transitions), which effectively means you're counting each pulse twice.
  • If the maximum frequency of your pulse train is only 40 Hz, you want to make certain that you're sampling at least twice that (80 Samples/s), in order to capture all of your signals.
  • As mentioned this is a software-timed application, so the maximum sampling rate that you will be able to achieve will be affected by your CPU and other applications running on your system.  Since you only need to sample 80 Hz, you should be fine.  It's when your signal has a frequency greater than 500 Hz (1kHz samplling rate) that you may be missing samples.

Also, you can run separate digital tasks on the same device.  An issue occurs when you decide to add timing configurations to both tasks.  Most of our devices use only one digital timing engine; therefore, if you were creating separate digital tasks that called the same digital timing engine, you would get an error.  In your case, you shouldn't see this behavior, since your only option is static, software-timed DIO.

Regards,

Sara Lewandroski
Applications Engineer | National Instruments
Message 5 of 12
(9,554 Views)

It seems to run fine, and the 'max pulse freq' indicator flickers between 333 and 500 samples per second (meaning I could be reading up to 166 pulses per second).

I'm aware that I'm reading both the rising and falling edge of the pulses, but that will give me a better average for my data I think.

 

For interest sake I tried reading 8 analog samples at 10Hz in parallel with the inner loop and that only slowed processing down to 250 samples per second!

So I'm quite impressed with the baby 6008 🙂

 

Mike

UniSA, Mawson Lakes, South Australia - LV 8.6.1
0 Kudos
Message 6 of 12
(9,531 Views)

Hello,

I am coming back to Labview after a few years out (refreshing things and meeting a new "friend" the ni6008). I found this topic because I want to do something similar with this hardware in labview.

-The idea is to read 8 channels of a digital signal, so it is like the solution posted above, but here my problem, the input could be of 5KHz! Is there a way to do it? What I understand is maximum 500Hz, but the hardware I have to use is ni6008. Could be that possible?

0 Kudos
Message 7 of 12
(5,401 Views)

Hi sarcanji,

 

Could be that possible?

No, that's not possible with your cheap hardware!

 

What I understand is maximum 500Hz, but the hardware I have to use is ni6008.

The NI6008 can handle ~100Hz samplerate when reading the DIO pins from my experience. Additionally you are limited to "software timing" as you can only read 1 sample per request…

 

The idea is to read 8 channels of a digital signal, so it is like the solution posted above, but here my problem, the input could be of 5KHz! Is there a way to do it?

A possible workaround would be to read those 8 signals using the analog inputs as you can use "hardware timing" with them. But then you are limited to 10kS/s aggregate sample rate or 1.25kS/s per channel…

 

but the hardware I have to use is ni6008

General advice: buy hardware based on your requirements. Don't try to fit your requirements on available hardware…

(The also cheap USB6002 allows 50kS/s aggregate on their AI pins.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 12
(5,398 Views)

Ok, thanks for your fast answer.

 

So, there is no way to follow to read the 8 digital inputs with the available hardware at the possible frequency...

 

So, you are saying processing the input as analogue input and counting the time until goes under a desired value, right? But all the channels shall be working at the same time, right? I am not sure if I understand your solution... But still will not enough for our frequency, right?

 

Yes, I know, buying the equipment according the specs, but let´s say that I am trying to run something already done

 

0 Kudos
Message 9 of 12
(5,391 Views)

Hi sarcanji,

 

no, I don't see a way to read 8 signals at 5kS/s with your USB6008.

 

I am not sure if I understand your solution...

Examine the example VIs coming with LabVIEW and DAQmx. There are examples explaining how to read multiple (analog) inputs!

To convert those analog readings to "digital" values you only need to compare them to a threshold voltage…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 12
(5,388 Views)