Friday, June 1, 2012

Lizz's Calculator - Design

My girlfriend just graduated from Georgia Tech as a math major. So obviously, she wants a custom calculator for her birthday...

I am planning to design and build a calculator in multiple versions which will have the functionality of a scientific calculator in v1 and a rudimentary graphing calculator in v2. This blog will chronicle the design and build process of Lizz's calculator with an Arduino as the brain.

Functionality (v1)

  • Order of operations including parenthesis
  • Algebra and geometric functions
  • High precision (more accurate than double precision)

Design

Software

The calculator will use a recursive descent parser with 3 stages of pre-parsing to validate and evaluate complex equations. The following context free grammar will define the language of valid equations:


    <S>     : <ex>
    <ex>    : (<ex2>) | <ex2>
    <ex2>   : <arg> | <op2> | <op1>
    <op2>   : <ex> <_op2> <ex>
    <_op2>  : + | - | * | / | ^
    <op1>   : <_op1>( <ex> )
    <_op1>  : SQRT | LOG | LN | <geo>
    <geo>   : <geo2> | ARC<geo2>
    <_geo>  : SIN | COS | TAN
    <arg>   : <num> | <num>.<num> | <const>
    <num>   : [0-9]+
    <const> : E | PI

The pre-parsing processes is defined as follows:

   Pre-Parse Rules:
   ----------------
    1. Surround all { +, - } args with ()'s recursively
        e.g. 8*3^4+PI => (8*3^4)+(PI). Note that recursion
        is used inside other sets of parentheses.
    2. Surround all { *, / } args with ()'s recursively
        e.g. (8*3^4)+(PI) => ((8*3)^4)+(PI). Note that recursion
        is used inside other sets of parentheses.
    3. Remove all unessary parentheses e.g. ((3+4)) => (3+4).
        These will cause a parsing error.
   
   NOTE: that these techniques are used to ensure order of 
   operations. The parentheses force the correct order of 
   operation when using the grammar above i.e. respect user 
   parentheses by using recursion, respect exponents by not 
   surrounding with parentheses, respect *,/ then respect +,- by 
   order of adding extra parentheses.



The software architecture is a simple recursive descent parser.



Electronics

The electronics will use an ATMEGA328 processor (Arduino UNO) for computations. One odd requirement for electronics design is that my girlfriend wanted the calculator "to look as crazy as possible, with wires everywhere!". So, I am make the design a little diluted and more complicated than necessary, hence me building my own 30 button array and 30:5 bit encoder. See schematics and block diagrams below






No comments:

Post a Comment