12-17-2010 11:32 AM
Please refer screenshot. This is how my program is sstructured. All loops are controlled by one STOP control in main.
I am finding it hard to picture or understand how data is updated or read when loop timing is used. I understand for single loops, but when you have parallel loops and loops nested, and loops transferring data within each other, how does it affect sampling, data reading, data displaying and updating etc. I would love an explaination or any equivalent eg that would explain the concept.
FYI, this program works, but I have tried different combinations to make the program faster if it goes, but couldn't infer anything.
Thanks! 🙂
12-17-2010 12:14 PM
The four
12-17-2010 12:23 PM
The four inter loop with Stop 4,5,6 and 7 will need to be re-worked. Your Main VI will not loop until ALL four stops are pressed.
Stop, Stop 2 and Stop 3 could be read from one stop button via locals
But the better option is to use QUEUES and Notifiers to pass data and the stops around your loops
Look at the Producer Consumer example that shipped with LabVIEW
12-17-2010 12:39 PM
For my application, it is easier to program using references than queues. producer and consumer architechure looks appealing but there are no proper examples on NI website to understand dataflow to program using this method. Like I said, I am using just one STOP button which is on main vi to stop ALL the loops. The stops shows individually in each loop are replaced with reference of STOP from main vi.
What you are saying is that my main vi will have just finished the first iteration and when it goes into state 1, it waits until subvi's are completed??
12-17-2010 12:51 PM
@VeeJay wrote:
What you are saying is that my main vi will have just finished the first iteration and when it goes into state 1, it waits until subvi's are completed??
Yes the main vi will not come out of case 1 until ALL four loops stop. If the stop is the same stop as the main loop, than that loop will stop also. So if as you say there is only one STOP then you whole VI stop after it comes out of case '1'
Search for examples using queue not on the NI web site but in the examples that shipped with LabVIEW. There are example of producer/consumer you can use as a starting point.
12-20-2010 12:34 PM
Hi VeeJay,
I would recommend looking at LabVIEW's Application Design Patterns. Here you will be able to find more information on the Producer/Consumer loop as well as other architectures. I am unsure of your application but this may be a good place to start to understand dataflow within LabVIEW.
Lynn
12-20-2010 12:59 PM
Hi Lynn,
Thank you for your reply. I have already gone through this article and it doesnt help so much. I am still looking for a more concrete example that would explain data flow rather than abstract articles. For eg. the coke machine example using queues helped a lot, but this article, not so much.
VJ
12-20-2010 01:43 PM - edited 12-20-2010 01:50 PM
It is all in the dataflow. 🙂
Have you tried running your mock up using execution highlithing?
(Sorry, without seeing the code, I can only comment on the visible cases. There is no telling what else is there!)
(Your ring is at "" and since it is a diagram constant and also outside the loop, it will get read exactly once at the start of the program and hten never again. You show case "1", which therefore never executes. I assume that the case selector will be in a shift register so it can actually vary as a function of state)
In any case, you program is poorly designed in general. Don't stack interactive loops!
12-20-2010 01:57 PM
Also the idea of "run as fast as it can" in loop A is very misguided. You need to put some timing in it, else it will run differently on every single computer, depending on hardware (speed, # of cores, etc). In 10 years, it will run orders of magnitude faster, maybe way too fast.
It will consume all CPU cycles it can possibly get, starving all other code running on your rig.
A loop without timing will grab on to the CPU for multiple iterations, this starving all other loops and making things very irregular once it gives up the CPU for other loops. Even a wait of 0ms allows other things to execute after each iteration.
12-20-2010 02:24 PM - edited 12-20-2010 02:27 PM
- When the program starts, loops A and B will start immediately, while loop C must wait for data from the ring constant, which is nearly instantaneous.
- Loop A and B will run unhindered individually for the duration of the program. Once they stop they cannot restart until the program is started again from the beginning.
- Loop C cannot loop unless a case is encountered that does not have any interactive code and can finish on its own. If the visible case "1" executes at any iteration of loop C, loops D, E, F, and G will start executing. Only if ALL FOUR INNER LOOPS complete, the case frame H is able to complete. Only if case H completes, loop C can go to the next iteration.
- For the program to stop, all loops must complete and stop.
(Your ring is at "" and since it is a diagram constant and also outside the loop, it will get read exactly once at the start of the program and hten never again. You show case "1", which therefore never executes. I assume that the case selector will be in a shift register so it can actually vary as a function of state)
In any case, you program is poorly designed in general. Don't stack interactive loops!
Altenbach, Thank you. This is what I was expecting. Ok now let me elaborate what my program does.
1) I do want loops A and B to run continuously. All loops are controlled by just one "STOP" button on the main vi.
2) Loops A and B are created as separate programs and I have them on the main vi block diagram using their icons and passing main vi controls to them through references.
3) Loop C is the main vi State machine that receives data from loops A and B. Loops A and B update loop C's controls through references.
4) State machine has 5 states -> Initialize, Wait, Pretest, Main Test, Test end. I have just shown the "Main test" case.
5) Flow of states, Initialize --> Wait--> Pretest--> Main Test --> Test End.
6) Loop A constantly acquires analog inputs and passes them to loop C.
7) Loop B constantly reads serial port (RS232) for data from another program and using that data, I trigger Loop C's "Start Pretest" or "Start Main Test" or "End Test"
😎 The case I have shown in Loop C with the 4 loops; each loop I have programmed as a separate vi and pulled down their icons onto that state and again passing main vi controls and indicators to the subvi's as references. Again, all these subvi's are also controlled by the same STOP from the main vi.
9) When this state ends, it goes back to "Wait" state and Wait state is a state where the program is when waiting for user input. User input is obtained from RS232 port. If the user input is "Test ENd", and the same is read on the RS232, Loop B will make "STOP = TRUE" and all the loops will stop and the program ends.
I just wanted to know how the timing works in all these cases. thats why, I indicated loops A, B , D, E ,F,G as loops in the program when actually, they are subvi's or process vi's with their icons just dragged and dropped into the main program.
Loop A: I will acquire analog input samples on USB 6008 at 50ms?
Loop B: runs at 25 ms
Loop C: I have it at 100ms. But is there any use to that?
Loops D,E,F,G: ALl tun at 100ms. They constantly update Loop C's controls and indicators. They dont have indicators or controls of their own.
Thanks a ton.! Now, is this a good design? And Yes, It is a shift register for the State Machine and it does varies as a function of state. I forgot to indicate it here.
V 🙂 J