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

Thank you for your reply John!

 

I have tried the internal output of the counter you have mentioned. But I still got problem. I have attached my vi, could you please have a look?

 

Cheers

Daisy

0 Kudos
Message 11 of 38
(2,229 Views)

Ok--so from what I gather you are trying to do, please make the following changes:

 

1.  Change "/cDAQ1/80MHzTimebase" to "/cDAQ1/FrequencyOutput".

 

2.  Change "/cDAQ1/Ctr2InternalOutput" to also "/cDAQ1/FrequencyOutput" (you may use the same constant wired into both property nodes).  

 

3.  Start the freqout task after you start the other two tasks.

 

 

EDIT:  Oh I actually just noticed you're doing a pulse width measurement.  I'm not really so clear on what you're trying to do now or why the shared clock/trigger is necessary.  Sample clocked pulse width measurements are supported but you have to guarantee that you have an input signal that is faster than your sample clock or you'll get an error.

 

 

Best Regards,

John Passiak
0 Kudos
Message 12 of 38
(2,215 Views)

Ignore my last post.  I re-read this thread from the start--the example you posted doesn't really align with what you mentioned you were trying to do earlier:

 

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.  

 

 

I'm not sure I follow--if one gate toggles the line low and the other toggles it high then what is the state of the line when there is no bullet at all?  If the first gate toggles the line low but the line is low to begin with you would have no idea the bullet has passed.  If the signal is as you describe, why do you need the two counters?

 

More typically in this type of scenario, each gate will generate a pulse when the bullet passes through (each gate generates the pulse on a separate line).  In this typical case, you would use a two edge separation measurement (something as simple as this would do, but perhaps the example is too simple in that you need to run the software, then fire your bullet before the read times out).

 

 

 

Best Regards,

John Passiak
0 Kudos
Message 13 of 38
(2,203 Views)

Hi John

 

I have to explain, the line start status is depend on which starting edge we choose for the counter. If I choose the falling as the start edge, when there is no bullet, the line will be 'high', that is the starting status is 'high'. If there is a bullet going through the first gate, the line will change to 'low' until the bullet reach the second gate. Then the line will keep 'high' until the next bullet come to the first gate. By measuring 'high-low-high' pulse, I can know the time the bullet go though the two gates, and then I can calculate the average velocity according to the distance between two gates. My problem is I have two pairs of the gates. That means the bullet will go through 4 gates. I have to measure two separate pulse width from the two pairs of the gates. What I use is two counters in 9171 separately. 

 

Could you please give me some advice about my work?

 

Cheers

Daisy 

0 Kudos
Message 14 of 38
(2,195 Views)
Solution
Accepted by topic author daisy610539

Hi Daisy,

 

OK that makes sense.  It doesn't sound like the two measurements really need to be "synchroinzed" (i.e. sharing triggers and clocks) but rather they just need to be able to operate at the same time.

 

You could go with something like this:

 

Bullet Velocity2.png

 

 

The tasks are passed through as an array pretty much just for convenience.

 

Digital filtering is configured (this is almost certainly the solution to question 2 in the first post in this thread).

 

Use implicit timing rather than a simple on-demand task--this will arm both counters when the tasks are started (rather than arming the counters upon making the read call--I hate this behavior so much...).

 

Timeout errors are thrown away.  I actually consider this bad form (it would be preferable to use events or to poll available samples per channel rather than calling into the read blindly), but NI's USB DAQ devices will keep the data buffered and unavailable to software until a transfer is necessary (either the user asks for his/her data or the hardware buffer is getting close to full), so some sort of workaround is necessary--this is probably the most straightforward option.

 

"Measurements" shows the most recent acquired data from each gate (can be modified of course if you want to store past history or something like that).

 

 

*Disclaimer* I haven't tested this at all, if I left something out please let me know.

 

 

Best Regards,

John Passiak
0 Kudos
Message 15 of 38
(2,188 Views)

Hi John

 

I can not open the vi file you attached because of the different version we use. My labview version is 2010. Could you please save as a lower version?

 

Cheers

Daisy

0 Kudos
Message 16 of 38
(2,173 Views)

Here you go.

 

Best Regards,

John Passiak
0 Kudos
Message 17 of 38
(2,169 Views)

Hi John

 

I don't think I can have two channels in one task. I also got the error message that 'lines and terminals o the device are in use by anther task or route'. T_T...

 

Cheers

 

Daisy

0 Kudos
Message 18 of 38
(2,165 Views)

There are actually 2 tasks in the code I posted (they are being passed in an array).

 

The error message usually gives information as to which lines are in use--what does it say specifically?  With the way I had it configured you shouldn't be getting this error.  

 

Edit: Oh wait a minute, you're using the 9401 right?  Are you getting this error?  Try reserving the tasks before starting them using DAQmx Control Task.vi (put it in the first loop so that both tasks are reserved before either is started).

 

 

Best Regards,

John Passiak
0 Kudos
Message 19 of 38
(2,161 Views)

Hi John

 

Thank you very much for your help. It seems the system can work. However, I have another question is how can I separate the two channels' output. I need to use the measurement results from both channel separately. The system seems just show the results randomly in the 'Most Recent Measurements'.

 

Cheers

Daisy

 

 

0 Kudos
Message 20 of 38
(2,136 Views)