|
A06: RPN Calculator |
||||
|
Create a reverse polish notation (RPN) calculator using LabVIEW. In RPN arithmetic the operators follow the arguments that they operate on. For example to write the expression A sin (k x - w t) in RPN one would write k x * w t * - sin A * Notice that in RPN no parenthesis are needed. To implement this type of arithmetic on a calculator one uses a stack. Values are pushed onto the stack from the top and then removed from the top of the stack as needed. This would be a LIFO (Last In First Out) type stack. We will use an array to serve as the stack. In the above example, the value of k would be placed on the stack and then the value of x placed on the stack. The * operator would remove the k and the x and replace these two values with the single value equal to the product k x. Notice that some operators (like sin above for example) will only take one value from the stack and replace it with an altered value. You can test the operation of an RPN calculator using this Demo Version. I've saved this VI without its block diagram to make it more fun for you to figure out how to implement the various features of the calculator. The front panel is depicted below.
Your version is to implement at a minimum the following:
Here are some hints to help get you started. You should use the state machine concept discussed in class to make this VI much easier to implement. The stack (array of real numbers) will be stored in a shift register so that its contents will be available each time through the loop and you can write the new contents to the shift register before finishing the iteration. A snippet of code that will perform the DUP operation (as well as check to make sure that the stack actually contains something to duplicate) is shown below. In the False case (not shown) the contents of the stack are simply wired through the case statement.
|
||||