08-09-2011 09:24 AM
Greetings All,
My name is Jake, I work in a lab at the University of Wisconsin-Milwaukee. I have learned LabVIEW 2010 in the past few months and designed a code that operates a Oscilloscope and Signal Generator to collect data for Medical Imaging scans.
I'm using a flat-sequence structure to go from step-to-step controlling different parts of the scan. I was wondering if there was a way for labview to time how long it takes to execute different blocks of the flat-sequence structure? (I can upload a jpeg of my code if needed).
Thanks,
-Jake
08-09-2011 10:55 AM
Jake,
Generally, the flat sequence structure is not a good choice for applicatins which will likely need to be changed before the developer retires, which means all applications developed at a university. Having just retired after 24+ years at a university, I can speak with authority on that issue. Please look into the state machine architecture for a more versatile and robust way to program.
To answer your timing question, however, the sequence structure is a good tool for that purpose, and one of the few good places to use a sequence structure. Add a frame before the frame you wish to time. Put a Tick Count function in that frame. Put another frame with Tick Count after the frame being timed. Wire the ouputs to Subtract primitive outside the sequence structure. The difference is the time in milliseconds used by the code in the middle frame.
Lynn
08-09-2011 11:13 AM - edited 08-09-2011 11:15 AM
Here's a quick example to time an operation. Hopefully this will give you a few ideas.
Although like the last person to post, I would certainly recommend reconsidering the use of flat sequence structures. Do some google searches on State machines, you will not look back !
08-09-2011 11:17 AM
Dear Lynn,
Would you be interested in seeing the code that we're running to give me an idea on where to start?
Thank you very much for your help.
-Jake
08-09-2011 11:55 AM
If you post your code we can help drive it in the right direction.
08-09-2011 12:01 PM
Go for it. Post it up here and we can have a look and see what suggestions we can offer.
08-09-2011 12:14 PM
Yes. Posting code is the best way to get help.
If your code works at all, please run it with your instruments so some typical data is displayed. Then Make Current Values Default and save. Post that VI. We do not have your instruments so cannot get data unless you give it to us. Also put comments on the code or in your posting message telling us where things do not work as you would expect.
Lynn
08-09-2011 01:05 PM
Dear All,
Thank you so much for the interest in my problem. Just as a note, I think the timing of the code should be easy enough to do and I shouldnt need help with that. I was actually looking for ideas on how to transform this code into a State Machine in my last post.
Things of importance:
-This code as written operates a stepper motor, oscilloscope, and signal generator, with that said there are many sub vi's it's dependent on that i did not include.
-I was not the first creator of this code, I'm actually the 3rd person to modify it, therefore it's a bit sloppy.
-I did not include data outputs that it gives us. It saves text files that we use Matlab to read in to create sinograms, but all the values on the front panel is what we use for scanning.
Also could someone list some advantages that state machines have over our current code?
Thank you all!
-Jake
08-09-2011 02:37 PM - edited 08-09-2011 02:38 PM
Sequence structres are inflexible, once in them you cannot abort them. If you try to code that feature in you end up with a ton of cases structures in your frames looking for conditions that occured in an earlier frame.
LabVIEW is a data flow language and in general sequence frames violate this and make it more challenging to get parallel code in you applictation.
State machines are a proven architecture which allows you to easily modify your code. They also allow you to easliy make decisions during your processing allowing you to effectively modify the order of execution. They are very easy to maintain and extend. This is VERY challenging in a sequence structure. Passing data is very straightforward in a state machine. Generally shift registers are used to pass the data. Very rearely does something always execute in the same order all the time. Generally you need some decisions in the execution if for nothing other than error handling.
These are just a few things off the top of my head. If you do a search in the forums I'm sure you will find pages and pages of information on why state machines are better than sequennce structures.
08-09-2011 03:56 PM
One way to start the process of transforming this program to a state machine is to:
1. MAKE A BACKUP COPY FIRST.
2. Make sure the backup copy will open and is in a safe place - archived - not on the same computer.
3. The reason I mentioned backups is that when I tried some of the thngs I am about to mention, LV crashed and amny of the changes were lost.
4. Save a copy after each step.
5. The block diagram is over 10000 pixels wide. Somewhere around that width programs become very unstable and above 16000 almost impossible. The style guides recommend that panels and diagrams be kept to the size of one screen.
6. Starting with the innermost sequence structure (six frames in a while loop), context-click on the frame and select Replace with Stacked Sequence Structure. That will reduce the diagram space considerably and will introduce several Sequence Loacal terminals. Save. Then go to 7.
7. Context click again on the frame again and select Replace >> With Case Structure. Save. Connect the "i" terminal of the loop to the case selector teminal. Save.
At this point you will have a broken VI. The Sequence Local terminals do not exist in a case structure so you will need to go in and reconnect those signals appropriately. This probably will mean shift registers and signals wired through all the cases of the case structure. Save while doing this. You may need to open the original to determine where some of those signals go.
Then repeat the conversion to a case structure for the outer sequence structure.
At this point you have something which starts to look like a state machine but still is quite sequential in behavior. Study state machines a bit. Define your staes and the transitions beween states. Create a type-def enum for the states. Add a shift register forstate selection and connect the enum to it. Add the state selection logic in each state.
It may sound complicated but this will be a lot less work than starting over.
Lynn