From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

USING TWO COUNTERS TO COUNT INDEPENDAN EVENTS

Hi Group,

Been searching an trying many things to find a solution.  I know there is one but just can't seem to get it right.

 

I have two devices which supply TTL pulses which I need to count.  Ctr 1 will be used as a master clock, Ctr 2 will be used to count pulses from the other device based upon a finite number of ticks from counter 1.

Both pulses are asynchronus, and run continuously.  For instance I want Ctr 1 to read 500 pulses from device 1, and concurrently read pulses from device 2.  Both signals are relatively low freq (<10kHz).  I would like to start and stop both counters with the same clock, but realize this might be an issue with my X Series USB MIO

 

At the conclusion of counting the 500 pulses from device 1, I want end the while loop and read the accrued pulses from both devices.

A little error is tolerable on the second counter, as to it generally being a higher freq than counter 1 source.

 

I'm thinking that the two-edge seperation technique is what's needed, but just can't seem to get there.

 

Help would be greatly appreciated.

Chris B.

 

0 Kudos
Message 1 of 8
(5,403 Views)

Hi Chris,

 

Could you be a little more specific about your setup? What NI device(s) are you using to count the pulses? Are your two devices that are supplying the TTL pulses external or are they in the chassis with the modules that are going to be counting the pulses? You want to stop counting on ctr 2 when ctr 1 gets to a 500 pulses? If that is the case you can just have Boolean logic (count > 500) to stop the while loop.

 

Here are a couple of links that I think might help.

 

How do I read two counters simultaneously?

Synchronizing Two Counter Tasks in NI-DAQmx

How can I use two counters simultaneously for pulse width measurement?

 

If these don’t help please post more information about your setup and I will be happy to continue to help.

Scott B.
AE NI
0 Kudos
Message 2 of 8
(5,377 Views)

Thanks Scott,

Now I should say 3-counters.

Attached is my latest attempt but a timeout occurs on the tw-edge sampling task.

 

Device is a USB-6343.

The devices which supply the pulses from (2) separate charge countes which out put TTL, slower one at ~500 Hz, faster one (ctr 2) at max 10kHz.

Ctr 1 input and cter 2 are used for the 500 Hz device, input of ctr 3.  Unsure of where to input the device output for ctr 3?

I was hoping to start-stop the two-edge task from the start-stop events on counter 1 and 2.

Appreciate your help.

 

Chris

0 Kudos
Message 3 of 8
(5,373 Views)

Chris,

 

Looking at your block diagram it appears that you are trying to use two different counters (ctr0 and crt1) to count the same pulse; the only difference is what they are triggered off. The third counter (ctr3) appears to be counting the ticks between the two PFI lines. Is this correct? I am confused about what you mean by "unsure of where to input the device output for ctr 3?" Could you please clarify what you are trying to do with the third counter? Also to prevent a timeout just attach a -1 constant to timeout input of the function that is giving you the timeout error. 

Scott B.
AE NI
0 Kudos
Message 4 of 8
(5,360 Views)

Scott:

 

Yes, that is correct.  I would like to use the slower event to generate a start and stop trigger on a PFI to another counter which will be assigned to the higher frequency instrument. 

I know that using a 500 Hz clock to measure a 10 kHz event is strange and will have errors, but that is what the experiment calls for.

I assume that timing of starting which counter 1st, 2nd and 3 must be important, as the vi will successfully stop sometime, but times out mostly.

 

Does this approch seem feasible?  If so, some guidance on timing would be helpful if that is the issue.

 

Attached is another snippet whch hopefully is clearer to follow.

 

Thanks,

Chris B.

0 Kudos
Message 5 of 8
(5,340 Views)

Chris,

 

In your screenshot I am guessing that you have removed the While Loop? Currently it appears that your ctr2 starts immediately and your other two counters start when they are triggered. Your current issue with getting the timeout before the VI successfully stops sounds like a race condition. A race condition is when you do not have any clear way of controlling what of multiple functions happens first. I would recommend putting a long timeout of a couple of seconds on your read VIs and run your program in highlight execution before you try to stop. You will then be able to see the data flow that is happening and can figure out what needs to be stopped first.

Scott B.
AE NI
0 Kudos
Message 6 of 8
(5,309 Views)

Scott,

Sorry for the protracted reply.

Got the 3-counter scheme to work with some minor changes to the code.

However, after discussion with the users and looking at the semi-periodic and stochastic nature of the counts, found out that the attached 2-counter solution falls well within the expected limits of error. Simpler is better.

 

Thanks for your help.

Regards,

Chris B.

0 Kudos
Message 7 of 8
(5,263 Views)

Chris,

 

I'm glad that you have gotten everything working correctly! Good luck with the rest of your application!

Scott B.
AE NI
0 Kudos
Message 8 of 8
(5,247 Views)