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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to employ multiple counters using producer consumer loop

Solved!
Go to solution

Hello,

 

I have developed a VI that computes the auto-correlation function in real time using data from one counter and employing the producer consumer loop. Now I want to use two more counters(Three in total) to compute the auto-correlation function from the data obtained from these counter simultaneously. And then display the curves in real time too. 

But since I am new to LabVIEW programming I am confused as to whether I should use multiple producer-consumer loops or I can achieve my goal in the same loop by just adding in different counters and data processing?

What is the most fast and efficient way of doing this? I am attaching my VI that gives me the desired results with one counter? I would appreciate it if anyone can help me with doing the same with two more counters.

 

Thanks

0 Kudos
Message 1 of 4
(2,647 Views)

Will all 3 counters always sample at the same rate?   That's a special case that could let you put all 3 counter tasks into a single producer loop.  There you can combine their data and send it off to the consumer loop which can split it back apart for processing.

 

I'd strongly recommend you start thinking about where you can convert large chunks of block diagram space into re-usable subvi's.  A common rule of thumb is to make the block diagram fit within one screen without scrolling.  I'd suggest you at least try make your producer and consumer loops fit within one screen so that you only need to scroll for the setup and cleanup code to the left and right.

 

If you needed 3 data-producing counter tasks running independently at different rates, you'd want separate producer loops.  That would start nudging you toward separate consumer loops, separate graphs, etc.  It would definitely get more complicated, especially as a self-described beginner.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 4
(2,582 Views)

Thank you for your reply. Yes, all three counters will be sampling at the same rate. But I am not sure as to how I can achieve that. What do you mean by combining and splitting the data? How can I do that?

I know my block diagram is a mess. Since I am new to this, I have been learning it as I progress. I will appreciate any help you can extend with this.

 

Thanks.

 

0 Kudos
Message 3 of 4
(2,559 Views)
Solution
Accepted by MK25

You've got a good start functionally.   The tidying will be really helpful as you look to extend this app to more tasks.

 

 To make all 3 counters sample at the same rate, just set up all 3 counter tasks similar to the 1 you already posted.  The single pulse train can be used to drive sampling on all 3 counter tasks.   The only other thing you need to do to make sure all tasks are synced is to enforce sequencing so that the 3 tasks are all started *before* you start generating the pulse train that gets used as a shared sample clock.

 

Combining and splitting data will be as simple as using "build array" on the producer side to combine the 3 1D arrays into a 2D array with 3 rows, and then using "Index Array" on the consumer side to split back into separate 1D arrays.

 

The two biggest things to do for tidying are:

- start making subvi's out of code that takes up a lot of space.  Sometimes you make subvi's for reusability, sometimes just to make the top level code functionally more clear

- be more careful and diligent about wire routing.  Pretend that every inch of left-to-right wire costs x, every inch of vertical wire costs 2x, every right angle bend costs 5x, and every inch of right-to-left wire costs 10x.  (These are make believe "costs", the main idea is that simple, straight, forward wiring is far preferable to bends and backward wiring).

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 4 of 4
(2,551 Views)