LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use two counters simultaneously for pulse width measurment

Solved!
Go to solution

Hello, everyone!

I am new to Labview. I currently do some pulse width measurment with 9401 and cDAQ9171. My understanding is the 9401 has 4 counters, that means I can use these counter separately. However I meet following problem. 

 

1. I use the ctr 0 and ctr 1 (PFI 1 and PFI5) to measure two different pulse width. However, it seems there is an interference between two counters. How can I make the two counters working simultaneously and separately?

2. I first try one counter for pulse width measurment in Labview signalExpress. My pulse width is around 0.4ms. However, I cannot get the right result if I choose the starting edge is rising (the results always around 20ns. Only if I revise my pulse and choose the starting edge is falling, I can get a reliable results.

 

I am confused about those question for about 3 weeks....Is there anyone can help what can I do with that?

I have attached a simple vi....

 

Thank you very much!

 

0 Kudos
Message 1 of 38
(9,417 Views)

Hi daisy610539,

 

Thank you for your post to the forums!

 

I understand you have a 9171 1 slot cDAQ chassis with a 9401 DIO 8 channel bi-directional module. You wish to make use of the onboard 32-bit counters from the 9171 chassis. The counters are not on the 9401, the counters are simply accessible through the 9401. 

 

1. When you mention interference what exactly do you mean? Are you seeing values being superimposed on each other? What values are you expecting?

 

Here are some links to look at relating to mutliple counter measurement applications:

 

How do I read two counters simultaneously?

 

Synchronizing Two Counter Tasks in NI-DAQmx

 

AO+ 2 counter tasks of PCI-6110

 

Use Counter to Create a Clock for a Buffered Edge Counting Task

 

Finite Buffered Measurement of Digital Frequency Using Two Counters in DAQmx

 

Period Measurement with a Counter

 

Using an NI Digitizer for Frequency Counter Measurements

 

NI 9401 pulse width measurement

 

How Many CompactDAQ modules do I need for Counter Application?

 

The 9401 can use the 4 counters available on the 9171 chassis. You will need to make sure that you are in fact creating 2 counter tasks in order to use both counters, you cannot use 2 counters for the same task because of an interference from the line being reserved. 

 

This link provides for a great reference for knowing the necessary number of counters for each kind of counter measurement that you are looking for: 

 

How Many Counters Does Each Type of Counter Input or Output Task Take?

 

Here is an example below that shows how to synchronise and use two counters. It uses an analogue input task as a clock source for the counters but the architecture will give you a good idea as to how to synchronise the counters.

 

Synchronize Two Counters using a Dummy AI and an Arm Start Trigger

 

Here are some other links that describe how to use the cDAQs internal counters as an event counter, sample clock or trigger for other tasks:

 

Using Internal Counters on a NI cDAQ Chassis as an Event Counter, Sample Clock or Trigger for Other ...

 

If you have LabVIEW available to you (I assume so as you have created a simple vi), you can take a look at the NI Example Finder and look at the following:

 

- Hardware Input and Output>>Counter Input>>Counter - Read Pulse Width and Frequency (Continuous/Finite/On Demand); there are three examples here.

 

Here are a couple of other links:

 

Why Do I Get Error 201133 When Trying To Perform Bidirectional DI/O with My NI 9401 in DAQmx?

 

2. In regards to the unreliable results. What are you expecting? What result do you get for the starting edge as falling? What type of pulse width are you taking in?

 

If you could let me know how you get on, I would appreciate it. I will take a look at your code and let you know what I find.

 

Kind Regards,

 

 

Dom C
Message 2 of 38
(9,384 Views)

Hi Dominic

 

I so appreciate your kind and quick reply.

What I am doing is to measure the bullet velocity. To measure the velocity, I want to know the time the bullet go through two gates (one for the timer start and the other for timer stop). Actually if the device can work as a real timer and it can be either start or stop controlled by the input signal, that would be perfect. However, I don't know how to do it, so I choose to measure the pulse width which is generated from the signal from the two gates. When the bullet goes through the first gate, the input will be with high voltage, and it will become low when the bullet goes through the second gate, by which a 'up' pulse is generated. I can also change the order and makes the first is low and second is high. That is the reason why I can use either rising or falling as the start edge for the pulse width measurement.

 

Also, there are two counters/timers I need to do two separately pulse width measurements. When I test my vi, if I only generate pulse to counter0, both counter 0 and 1 can show the result and the result is not correct.  

 

As you see, I have separate the two clocks with two tasks. It seems I need to add a clock to make them work simultaneously. My thinking is how can I do with my vi to make each counter work with the relative pulse come?

 

I don't know whether I have clearly explained my problem.

 

Cheers

Daisy 

0 Kudos
Message 3 of 38
(9,366 Views)

Hi dasiy610539,

 

Thank you for clarifying your problem.

 

Measuring the pulse width sounds like a good idea, certainly.

 

I understand the principle of the high and low signals, one for the start of the measurement and one of the stop. This sounds really good. 

 

Have you taken a look at the links I posted? 

 

Yes in order to synchronise the two counter input tasks, you will need an additional analogue input task, as shown in the following example:

 

Synchronizing Two Counter Tasks in NI-DAQmx

 

I would try to work through these two options to see where you get to. 

 

It may also be worth reading through this tutorial:

 

Complete Industrial Digital I/O and Counter/Timer Tutorial

 

You mention that you get an incorrect result on both of the counters. What do you mean? Would you be able to clarify this?

 

Kind Regards,

Dom C
0 Kudos
Message 4 of 38
(9,342 Views)

Hi daisy610539,

 

I found a couple of additional links that will be useful to you:

 

measuring distance between 2 pulses (PCI-6221)

 

measure pulse width with 4 counter simultaneously

 

Measure Pulse Width with DAQmx

 

Kind Regards,

Dom C
0 Kudos
Message 5 of 38
(9,341 Views)

Really thank you for your kind help, Dominic

 

I am not really understand the way to add an analogue input task, because NI 9401 do not have any analog in/output. The message shows it cannot find the physical channel.

 

I really don't know how to create the clock for making two counter simultaneously. Could you please let me know how to do that?

 

Thank you very much

 

Daisy

0 Kudos
Message 6 of 38
(9,322 Views)

Hi daisy610539,

 

That is no problem at all.

 

If you have a look at the example again, it shows an alternative method of synchronising the two counter input tasks, using a counter output task, which should be possible with your 9401. 

 

This should provide you with a better idea of how to do this.

 

I will see what other links I can find at some point.

 

Kind Regards,

Dom C
0 Kudos
Message 7 of 38
(9,320 Views)

HI Dominic

 

Thank you for your quick reply. I tried the example 2 which use the Arm Start Trigger. Unlike other source which I can find the physical channel from the option bar, I cannot find any option if I click the arm start source. Could you please give me some advice to set the source? The error msg I've got now is 'Source terminal to be rounted could not be found on the device'.

 

Many Thanks

Cheers

Daisy

0 Kudos
Message 8 of 38
(9,313 Views)

Hi Dominic

 

I'd like to explain what is the problem I am facing to. What I use now is cDAQ 9171 and the NI 9401. Which has 4 counters and no analog input or output. I saw the NI document, it seems 9171 doesn't support arm start triggering. I think this is the reason why I cannot find any suggest physical channel for arm start source.

 

But now, the only device I got is the 9171 and 9401. Is there any alternative method for me to solve my problem?

 

Many Thanks!

 

Daisy

0 Kudos
Message 9 of 38
(9,288 Views)

Hi Daisy,

 

Can you post your current code?  The 9171 should indeed support arm start triggering.

 

If you're using a spare counter to generate the trigger signal for the other two, you should probably be referencing the counter internally

 

You can reference the counter internally when creating your channel by using "[chassis name]/_[ctr name]"  for example "cDAQ1/_ctr0".

 

You can reference the internal output of the counter for the trigger source of your other tasks by using "/[chassis name]/Ctr0InternalOutput" for example "/cDAQ1/Ctr0InternalOutput".

 

 

To get these items to show up in the drop down of the terminal control/constant, you have to right-click on the terminal and change the I/O Name Filtering (include internal channels in the first case above, include advanced terminals in the second case).

 

 

Best Regards,

John Passiak
0 Kudos
Message 10 of 38
(9,284 Views)