Previous Assignment

A06: RPN Calculator

Next Assignment  
 


Due:  Friday, February 14 by 4:00 p.m. in the PLAB DropBox

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:

  • A QUIT button that will turn off the calculator (by exiting the LabVIEW VI).

  • A register to enter a new value onto the stack and an ENTER button that will place the contents of this register onto the stack.  Notice that the example will also place the value in the register on the stack if the Enter key on the PC KEYBOARD is depressed.  Also you do not have to click the mouse inside the register to begin typing numbers into it.  See if you can figure out how to add these features for the praise and admiration of your peers (and to get a perfect score).

  • The stack operations buttons:

    • DROP - Removes the top value from the stack (if it exists).

    • DUP - Pushes a duplicate copy of the top value onto the stack.

    • CLEAR - Clears the entire stack contents.

    • SWAP - Swaps the two top values on the stack.

  • The unary (one argument) operators:  SIN, COS, TAN, ASIN, ACOS, ATAN, SQRT, LN, 1/x,  x^2, e^x and +/- (changes sign of top of stack).

  • The four binary (two argument) arithmetic operators (+, -, * and /).  Others could be added like y^x for example.

  • The stack contents should be displayed on the front panel.

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.