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.
Solved! Go to Solution.
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.
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.
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).