UPC EETAC Bachelor's Degree in Telecommunications Systems and in Network Engineering EEL

Chapter 3 problems

      - D3.6 -

Simple calculator for integer numbers

Products

D3.5

D3.7


1. Specifications

Let us design a simple calculator for 8 digit BCD numbers as integers.

Arithmetic operations solved using hardware were proposed in  D2.6 and D2.13. High level language and microcontrollers offers large advantage for simple and cheap commercial calculators. Here we propose you to start designing a simple one. Let us start with integer numbers and leave floating point number for another project that you may like to tackle in summer time if you have interest in this subject.

Simple calculator
Symbol

Fig. 1. The idea of a simple calculator. Symbol and some suggested connections to start the design phase #1.

Three basic operations: addition, (+)  R = A + B; subtraction (-) R = A - B; multiplication (x)  R = A x B.

Division  R = A / B is another operation that can be studied in other design phases.

Typical calculator usage:  (1) Power ON, do nothing (idle); (2) Capture and represent operand A; (3) select operation key; (4) capture and represent operand B; (5) click "=" key to perform the operation and show its result.

Proteus includes several calculator circuits for microcontrollers that you can analyse to get ideas. However, because the specific goal of this assignment is to learn the course content, we will follow our CSD plan imagining the circuit as a dedicated processor controlled by a FSM that governs the capturing of input data, the execution of operations and the output of results in 7-segment displays or an LCD screen.

Fig. 2. Open and play with a Proteus sample project on calculators.

 

2. Planning

Let us build the product organising several design phases, and several steps within each phase when necessary.

Design phase #1: basic features. Only two digits per operand. Three arithmetic operations.

Solve the circuit for the design step #1. Only when it is fully tested working correctly and reported, solve the design step #2.

- Design step #1. Keypad encoder and basic calculator.

The encoder may be: (A) type Enc_16_4, or (B) type P6 Matrix_encoder_16key. Choose your preference, even though we recommend the matrix keyboard to practice Chapter 2 materials. This is the "matrix_keypad.pdsprj" model.

keypad

Fig. 3. Modelling and simulating the matrix keypad in Proteus helps to comprehend the task the FSM must perform to encode the key pressed.

Certainly, a subproject for this design will be interface to the matrix keypad, the idea if scanning rows and reading columns, it will be used for reading one key at a time when required by the application. This Matrix_encoder_16key is a tutorial on such design. 

Project location:

C:\CSD\P10\Calc_s1\(files)

Project source files:

Calc.pdsprj, Calc.c

a) Draw the hardware schematic necessary for step #1. Keypad including sign key "+/-", operation keys "+", "-" and "x", "=". 460 Hz external CLK oscillator to scan the keypad. 4-digit multiplexed BCD outputs. Reset circuit MCLR_L, and primary 8 MHz quartz crystal oscillator. Explain how to configure the inputs and outputs in init_system().

What pins will be read? How many external interrupts are required in this step#1?

b) Draw the hardware-software diagram indicating the required RAM variables. 

c) Draw the state diagram for the FSM indicating state transitions and outputs. Fig. 3 shows some initial ideas on how to organise calculator operations in a similar way we have implemented other similar circuits in VHDL or C.

Idea on the top FSM

Fig. 3. Example state diagram to start developing and testing in Proteus. 

d) Draw the truth tables and their equivalent flowcharts for state_logic() and output_logic() functions.

e) What is the interrupt service routine ISR() used in this application? Draw its flowchart.

f) Develop and test (debugging) the project capturing the hardware circuit in Proteus and writing the C source code. You must use the watch window to monitor RAM variables from the very beginning. Remember: one step at a time to be sure that your hardware and software works as planned.

 


- Design step #2. 4-digit multiplexed display system (MDS) to represent results.

Copy the step #1 hardware and source software files into de new location.

Project location:

C:\CSD\P10\Calc_s2\(files)

Project source files:

Calc.pdsprj, Calc.c

a) Draw the hardware schematic necessary for step #2. Explain how to configure it in init_system().

Explain what is new in sections b), c), d), e), f)

Develop and test the new feature in Proteus. Indeed, applying teamwork you can tackle both design steps simultaneously because the operands and results to be multiplexed may be simulated variable values.

 



Design phase #2: LCD display

Let us add an LCD display as studied in P11 to this application. The idea is to replace the MDS by the LCD to represent operands and results as ASCII characters on the screen.

Project location:

C:\CSD\P11\Calc\(files)

Project source files: "Calc_LCD.pdsprj", "Calc_LCD.c"

g) Enhance the schematic from the previous design phase #1 to replace the 7-segment digits and to include an LCD attached to PORTD as studied in tutorials.

h) Enhance the software and the source file to drive the LCD.

In this design phase you can learn the LCD interface step by step. For instance:

- Design step #1. Print ASCII messages on the LCD. For instance "Operand A = ", "Result = ", etc.


- Design step #2. Print numeric information, operands and results.

Develop and test the new feature in Proteus.

 




Design phase #3: Using TMR2 peripheral subsystem.

The 460 Hz external CLK is replaced by the internal 8-bit TMR2 peripheral to scan the keypad (TMR2IF). Discuss the main features of this peripheral and its applications.

Project location:

C:\CSD\P12\Calc_LCD_TMR2\(files)

Project source files:

Calc_LCD_TMR2.pdsprj, Calc_LCD_TMR2.c

 

i) Calculate TMR2 parameters required to generate the same Lamp output frequency of 1.5 kHz.  In this way the external CLK signal can be eliminated and the application runs in the same way. 

Develop and test the new feature.

 


Discuss how to enlarge the calculator to 8 digit.