08-10-2009 04:46 AM
Im following an example to count the number of loops my program has done. However it doesnt seem to work. Ive attached a DBL indicator to the i in the while loop of the block diagram. I have attached the program below.
Regards, Sam
Solved! Go to Solution.
08-10-2009 04:56 AM
Hi Sam,
why did you start a new thread if this is your solution
http://forums.ni.com/ni/board/message?board.id=170&thread.id=430766&jump=true?
Mike
08-10-2009 05:00 AM
Hi Sam,
why did you start a new thread if this is your solution
http://forums.ni.com/ni/board/message?board.id=170&thread.id=430766&jump=true?
Mike
Mike,
Maybe this is another while loop and not the same used in that thread and he just want to get a confirmation on whether it will work the same way........
08-10-2009 05:06 AM
The while loop counter starts at zero, so if you want to know the numebr of loop iterations, you will need to add 1 to the loop counter.
Your loop will also only run one time if the STOP button is not pressed since you have the while loop condifitional terminal set to continue if true. If you press the button before you run the code, it will only run twice, because you have the boolean set to latch, so when the loop reads the boolean, it will switch back to false and stop the loop.
I think you want to change the conditional terminal back to stop if true.
08-10-2009 05:10 AM
thanks, worked like a dream
Sam
08-11-2009 11:54 AM - edited 08-11-2009 11:55 AM
Hi Sam,
Just some additional observations/tips on your code...
1. I notice that you have a standard stop button going into a "run if true" stop condition of the while loop. In this cercumstance it is common to have the stop condition set as "stop if true". You can change this by right clicking the stop terminal and enabling the "stop if true" property. Obviously, it somewhat depends on your design preferences.
2. If you have any issues with the application, perhaps you notice that it is taking over your processor resources, you should add some execution timing into the while loop. You will find the timing functions in the block diagrams functions palette (programming > timing). The Wait (or "wait until next ms") functions will provide your application with "down time", which means that the processor can execute other tasks.
3. To elaborate what MikeS81 correctly stated, insert an incriment before the numeric indicator as shown below to get the actual number of cycles (i.e. the count terminal of the "while" and "for" loops are 0 indexed). Also note that I have changed the representation of the count to interger (blue). You do not need floating point precision when displaying the incriment count, as a while loop can only execute a "whole number" of times.
I hope this has been useful to you Sam. Thanks for your post, Rich R