Calculator Program In Labview

If you are concerned that the project estimators in your company will not understand the concept of LabVIEW nodes, there is another method that some LabVIEW developers have used to translate LabVIEW code complexity metric to equivalent SLOC. In this alternative approach, developers compared the size of LabVIEW code on disk to the footprint of an equivalent C object file. Provided you know the SLOC used to create the C object file, you can convert LabVIEW code to SLOC. In LabVIEW, you can view the memory usage of a VI by going to File»VI Properties»Memory Usage, as shown in Figure 2.
Jan 17, 2012 This video was made by Tektronix (Team 4249) FRC 2012.
Figure 2. The Memory Usage category of VI Properties shows the size of this code on disk, which is 10.0K.
Note: The Memory Usage feature shows not only the size of the LabVIEW code on disk, but also the memory used by the front panel and block diagram objects and the data stored in the VI. When using this method to convert LabVIEW complexity to equivalent SLOC, only include the memory associated with the code.
Note: National Instruments has not uses this SLOC conversion method during software development and cannot offer guidance at this time on a conversion factor from LabVIEW code size to equivalent SLOC.
Square Root Calculator
This will be the final program that you will be doing in the Basic LabVIEW course. It will be calculating the square root of a number, X, and will be using a shift register to do so. You will have the option of doing the program completely on your own after the flowchart is shown below.
Let's go over a few items in the flowchart to better understand what is being sent through the shift register. You can then try to write the LabVIEW code yourself before the code is given to you or you can go straight to the code and enter it from the step-by-step instructions.
- The square root is going to be calculated in a while loop that has a shift register. The while loop will have a termination test and will be covered below.
- The value of X is the number which we are finding the square root of and this value will never change throughout the program. Therefore, we don't want to pass it through the shift register but we do want read it outside of the loop and pass the value through the loop boundary into the loop.
- The value of Y is initially set to 3 and used inside the loop for calculating a new value, Ynew. This means that upon each iteration of the loop the newly calculated value of Ynew is sent back to the loop and picked up as Y. This is probably the most difficult part of a sift register and it may take a little getting used to. Basically you want to take an initial value, calculate a new value, and send the new value back to through the loop.
- The loop keeps iterating until the absolute value of the difference of Y and Ynew is less than or equal to 0.00001. When the difference between those two values is less than 0.00001 the square root value is very accurate and the loop should stop. In LabVIEW we have to wire this condition test into the stop condition.
- After exiting from the while loop we want to print the square root of X and this is stored in Ynew. This means that we run a wire through the while loop boundary to an indicator outside of the loop. The wire takes the value of Ynew and sends it to the indicator. The user will see two things on the screen: a control that has the value, X in the flowchart, that they want to find the square root of and an indicator, Ynew in the flowchart, which has the square root of x.
See if you can write the LabVIEW program for this or you can jump straight to the code. You may find that seeing the code teaches you more than trying to figure it out yourself.
When you write the square root program it requires you do think about the code structure. One advantage of LabVIEW is that you get away from the syntax of the programming language and you get to think about the logic of the program. The most difficult part of LabVIEW programming is that it requires you to know about the dataflow programming but as soon as you write your first program this gets much easier. Lets start with the front panel of the square root program.
In the front panel image above, you can see that there is one control on the left which has the label of 'x'. Then, on the right, is one indicator which has the label of 'square root of x'. Now let's see what the block diagram looks like.
Here are the steps that you need to construct the block diagram.
Daniel and his mother move from New Jersey to California.
- Start with a blank VI and make sure that you have added the control and the indicator and that the names have been changed as shown on the front panel diagram above.
- Add a while loop to your block diagram. You want to make the while loop fairly large so that the code can be added. Make sure that you don't wire the control or the indicator yet. That will come in a few steps.
- We need to add a shift register to the while loop and you do that by right clicking on the while loop boundary and select 'add shift register'.
- Now you are going to add the initial value of y. In the previous page we mentioned that Y is the value that enters the shift register, the value of Ynew is calculated, and the value of Ynew is sent out of the shift register to the next iteration of the loop. We need to initialize the value of Y to 3 and you can do that by adding a numeric constant outside of the while loop and you do that by right clicking in the block diagram and selecting Mathematics -- Numeric --> Numeric Constant. Then make sure that the value in the constant is 3.
- Wire the constant to the shift register and make sure it looks like the block diagram above.
- The top condition is taking the previous value of Y, subtracting the new value of Y from it, taking the absolute value, and comparing that value to 0.00001. The absolute value function is obtained by right clicking on the block diagram and selecting Mathematics --> Numeric. The less than or equal comparison operator is located at Programming --> Comparison --> Less than or equal.
- Add the remaining functions to the block diagram and wire everything like is shown in the block diagram above.
- Now it is time to run the program. Enter a 2 in the control labeled X and press the run arrow. You should get 1.1421 as the output.
Congratulations! You have a complete square root calculator program! If you want to do more with this program, in the next exercise you will modify the square root program to compute the Nth root of a number.