Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

compare two pulse counts

Hello,
 
I'm trying to compare two simultaneous pulse counts using a cDAQ-9172 chassis, a 9401 card, and LabVIEW 8.2. What I want to do is set up a single output pulse that lasts for, say, 1000 incoming pulses on ctr0, and then use that single output pulse as a gate on ctr1 to count the input pulses that it sees during those 1000 pulses on ctr0. In other words, I want to synchronize the two counters, and as soon as ctr0 reaches 1000 pulses, they should both stop so I can compare the two counts. The issue is slightly complicated by the fact that both counter inputs are very noisy and require a pulse width filter in order to be read properly.
 
I more or less understand what needs to happen conceptually, but I'm at a loss for how to make it happen. A simple walkthrough would help enormously. Alternatively, if there's a better way to accomplish this, that would be helpful as well.
 
Thanks.
0 Kudos
Message 1 of 8
(4,927 Views)

Hello,

The following steps should accomplish this:

  1. Connect the 1000 pulse signal to one of the PFI lines.
  2. Set up a Counter Output -- Pulse Generation -- Ticks task on ctr0. On the "source of ticks" input, use the PFI line that has the 1000 pulse signal connected to it.  Wire a constant of 1000 to the "high ticks" input.
  3. Route the output of ctr1 to the gate of ctr0 using the DAQmx Export Signal VI.
  4. Set up a Counter Input -- Count Edges task on ctr1 to do buffered edge counting. 
  5. Use the PFI line that corresponds to ctr1 out for the Sample Clock Source for the buffered counter input task.  This will allow you to read from the count register as soon as the 1000 pulses are counted.

The only problem with this is that it will not stop after the first 1000 pulses; instead it will start the whole process over again.  You would need another counter in order to force the tasks to stop after 1000 pulses.  Or, you will need a software timed stop, but software timing is slower and non-deterministic so it's not recommended.

Let me know if you need more details about this.

0 Kudos
Message 2 of 8
(4,871 Views)
Thanks for the advice. I set up a program (attached) that tries to implement basically what you suggest, but there are still problems. The main issue is that it gives me an error -200141 message telling me to change the data transfer mechanism to DMA. When I set up a channel property node to do this, it tells me that DMA is not available.
 
The other concern I have involves the pulse width filter on the counter output task. The 1000 pulse signal is extremely noisy, and without any filtering, the noise will increase the frequency by a significant amount. I've set up the filters as you can see in the program, but I have no idea whether I've done this properly.
 
Any further help you could offer would be greatly appreciated.
0 Kudos
Message 3 of 8
(4,863 Views)

Hello,

This error message is confusing, since, as you correctly noted, DMA is not supported in this use case.  You will want to use the USB Bulk data transfer mechanism instead.  Do you still see that error when you use USB Bulk?  If you do, it's possible that USB may not be fast enough for your application.  What is the approximate frequency of the 1000 pulse signal?

You have set up the digital filters correctly.  More information can be found about DAQmx and digital filters in KnowledgeBase 3VDG0388: Enabling the Digital Filters for Counter/Timer Devices in NI-DAQmx.

Please let me know if there's anything else I can help with.

0 Kudos
Message 4 of 8
(4,817 Views)
Using USB bulk gives me the same error message. The frequencies I'm working with are in the range of several kilohertz. Is it likely that this is too fast for USB?
0 Kudos
Message 5 of 8
(4,815 Views)

Hello,

I doubt that a few kHz would be too fast, but it is possible.  There are two potential problems here:

  • Either your signal is not being filtered correctly and is clocking the buffered counter input task at a higher rate than you think because of noise, or
  • You are indeed going faster than you can go with compact DAQ (although I would say this is the less likely of the two possibilities)

To find out whether or not the problem is noise on your buffered counter input clock source, try running a buffered counter input task that uses a pulse generated by the other counter of the same frequency that you believe your signal to be (several kHz).  If this works fine then you will know that you can handle that speed and we can find out what is going wrong with the digital filtering.

Hope this helps!

0 Kudos
Message 6 of 8
(4,782 Views)
I know that the filtering method I used works for a simple edge counting task, so I tried to set up a buffered edge counting task based on one of the examples in the LabVIEW help. I've attached this vi. Sometimes I get the same error message, and other times it doesn't seem to count anything at all. It seems like I should be able to do a buffered edge count no matter what, but I can't get it to work. Any suggestions?
0 Kudos
Message 7 of 8
(4,755 Views)

Update: I think I figured it out. I'll keep you posted if it turns out I was wrong.

Thanks for all your help.

0 Kudos
Message 8 of 8
(4,735 Views)