0% found this document useful (0 votes)
37 views13 pages

Practice Coursework - Simple Digital Calculator

Uploaded by

Simon Atkinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views13 pages

Practice Coursework - Simple Digital Calculator

Uploaded by

Simon Atkinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Simon Atkinson

Simple Digital Calculator


System planning

The goal of this project is to create a simple digital calculator that can perform basic arithmetic
functions such as addition, subtraction, multiplication, and division. The system should also have error
detection to ensure that any invalid numbers aren’t entered or that there aren’t any overflow errors (if
the value is above 255). A power-saving mode could also be implemented in order to reduce energy
consumption. The device should be as simple to use as possible, with each button performing a single
function and reliably producing a consistent output.

There are, of course, many systems already on the market, with many newer models being quite
advanced and involving graphical displays. Although it seems that basic calculators such as the one
detailed in this project are still the most popular due to their ease of use and energy e iciency, with
some of them even being able to run on small solar panels. Therefore, simplicity and low power usage
are key aspects of this project.

 The output will consist of three 7-segment displays to create three digits to display numbers
from 0 to 255 with leading zeros.
 There should be 10 input buttons for each number (0-9).
 There should be 7 separate operation buttons for addition, subtraction, multiplication, division,
execute, backspace, and reset.
 The device should also be able to store the previously calculated answer for further calculations.
 The calculator must only accept inputs between 0 and 255. or an error state will be triggered.
 Division by zero should also be detected and result in an error state.
 As there is no way to display negative numbers, they should result in an error.
 The current status of the calculator should be displayed by 2 LEDs:
o Green for ON
o Red for ERROR
 The calculator should go into power-saving mode after a set amount of time (1 min) by turning
o the displays.
 It should be able to resume full function after any button is pressed during sleep mode.
 The output should be consistent and be infinitely repeatable.
 The current draw of the circuit should be comparable to the current draw of basic calculators
already on the market (≈10 mA).

Development:

Circuit Diagram Subsystems:

The first step in the development process was designing a fully accurate circuit diagram that can later
be used as a reference for the physical prototype. There are three main subsystems: input, processing,
and output.
Here is the output and
processing subsystem
circuit. I used three 7-
segment displays,
each connected to a
7447 display driver.
Every driver requires 4
data pins (for 10
digits), except for the
third digit, which can
never be above 2
(number limit is 255),
and so only 2 pins are
needed. The BI pin is
used to turn o the
display after a set
delay. The A2 pin
controls two status
LEDs.

This is the input portion


of the circuit. It
consists of a matrix of
DPST switches which
are all connected to a
voltage divider to get 4
di erent reference
voltages (1.25V, 2.50V,
3.75V, 5.00V). I can set
two pins (A0 and A1) to
these values to act as
the X and Y axes to
create a coordinate
system. This way it only
uses two analogue pins
for 16 inputs. It also has
a reset switch
connected to A5. Note
that these pins are also
pulled to ground by two
100 kΩ resistors, so
that it isn’t floating
when none of the
switches are pressed.
Full circuit diagram:
Flowchart:

The next step was to create a working flowchart diagram that includes all the design requirements. The
flowchart was designed to consist of a main loop which handles all the other sub-procedures. This was
done so that it’s easier to understand and modify later in the future.

This is the main loop of my flowchart. The first thing it does is check if the clear switch is still being
pressed, as otherwise it will get into a loop of resetting itself. It then initialises the output pins and outputs
the input variables to all the displays (no data has been entered yet, so all of the input variables are 0). It
then checks for a button press which stores numerical values (0-9) in varV and stores the operation index
in var0 (this will be further explained in the input subsystem). If a number is pressed, then it is stored
and then displayed. If an operation is selected, then it activates the corresponding subprocedure.
If a mathematical operation is selected (1-4), then it sets itself up for the second number required for the calculation. If
execute is pressed, then it will perform the set mathematical operation with the stored numbers. If backspace is
entered, then it deletes one of the digits and returns to a previous point in the flowchart. Then if none of the cases match,
the clear/reset button must have been pressed. This entire procedure is done 3 times for each digit and once more for
the operation input.

This is the Check Inputs procedure, which is probably the most used, as it records any button presses by reading the
two analogue pins (A0, A1) and checking what that value represents. It also hands over input detection while sleeping
(var T > 59) to the timing loop, so that an action is made while coming out sleep. It then stores the button pressed into
one of two variables: varV for numerals and varO for operations. This table describes what each value represents:
0 1 2 3 4 5 6 7 8 9
var V = 0 var V = 1 var V = 2 var V = 3 var V = 4 var V = 5 var V = 6 var V = 7 var V = 8 var V = 9
Addition Subtraction Multiplication Division Execute Backspace Clear
var O = 1 var O = 2 var O = 3 var O = 4 var O = 5 var O = 6 var O = 7
These two processes run in parallel to the
main process seen above. The one on the
right is a simple timer that increments a
time variable (varT) every second (making
sure there is no overflow error). The
process on the left resets the timer and
turns on the displays when any button is
pressed by checking whether A0 isn’t low.
If the timer reaches 60 seconds, the
displays are turned o by pulling A3 low.

These three functions store the


currently pressed numeral button
(varV) into the variables A, B, and C,
where each represents one digit of a
three-digit number (A is the least
significant). The digits also must be
all shifted up to make space for the
new digit. I also look for an input error
by making sure that when it
combines the three digits during
execution, there won’t be an overflow
error.

These functions are called


when the backspace button
is pressed at di erent
points in the main loop.
They simply shift each digit
down and reset the most
significant digit.
This display function is called at the
beginning of the main loop and every time
there is a change in value of the variables A,
B, and C. It first combines the binary values
of A and B, which are up to 4-bit numbers, to
make an 8-bit number which can be sent to
the displays with one command. It then
manually checks the third digit (variable C)
for what value it is and sends the appropriate
binary number to the display drivers.

This simple function


is called when an
error occurs. It
simply turns on the
red LED by pulling
A2 low and loops
the check inputs
function until the
clear button (7) is
pressed.

The Second Number function is called after a


mathematical operation has been selected. It first
checks to see whether it is being called correctly. As
this calculator doesn’t support multiple numbers
being calculated at once, it will output an error if a
third number is attempted to be added. This is tracked
with the variable Q. It then moves all the digits
recorded for the first number to a new set of variables
(D, E, F) and clears the old variables so new values can
be entered into them. The mathematical operation
chosen is then saved in the variable M, so that we can
use later in the execution function.
This is the execution function, and it is ran when button 5 is pressed.
It first sets Q to 0, so that the second number function can be run
again and further calculations can be made on the result. It then
stores the digits from one number (A, B, and C) into the variable P and
the same for the digits D, E, and F into the variable S. It checks what
mathematical operation it should use executes them and stores the
result in the R variable. Error checks are also made to make sure
there is never a negative result (which would result in an overflow) or
division by zero. It then runs the Set Output variables function and
reset the variables V and O.

This last function uses the variable R, which


contains the result after execution and separates
the digits in the three variables which are displayed
(A, B, and C).
Simulation Test Results:

I then tested whether the flowchart diagram was working properly by testing it for specific scenarios.
Note that for inputting the require numbers and symbol, I adjusted the pins A0 and A1 to match what
analogue value it would get from the button array.
Test Description Inputs Predicted Output Simulated Results
Status LEDs Simulation is started 5V on pin A2 pin A2 goes high
Any invalid operation 0V on pin A2 pin A2 goes low
Perform addition 5 + 200 Display shows 205 Result variable (varR) = 205

Perform subtraction 16 - 13 Display shows 003 Result variable (varR) = 003


Perform multiplication 6×4 Display shows 024 Result variable (varR) = 024
Perform division 50 ÷ 20 Display shows 002 (2.5 Result variable (varR) = 002
truncated)
Negative result 19 - 20 Red LED on (0V on A2) Result variable (varR) = 000 pin
detection A2 goes low
Division by zero 20 ÷ 0 Red LED on (0V on A2) Result variable (varR) = 000 pin
A2 goes low
Use previous answer 6 + 12 and then + 11 Display shows 029 Result variable (varR) = 029
Reset button Reset pin is set to high Display shows 000 Flowchart restarts and all
variables are cleared
Backspace button Enter 123, then A0 and Display shows 012 Result variable (varR) = 012
A1 values are set for
backspace
Maximum input value Enter 256 Red LED on (0V on A2) Result variable (varR) = 000 and
pin A2 is OFF
Inactivtity sleep mode Nothing for 60s Display turns off (A3 is low) Time variable (varT) is
incremented 60 times and A3
goes low
Wake from sleep Pull A0 or A1 high Display turns on (A3 is high) A3 goes high

Unfortunately, because I am only simulating the microprocessor, we can only see what values are
stored in memory and what state each pin is at. This means that although all the tests passed
reasonably well, it only shows us whether the processing subsystem is working and fails to show us
how it will interact with the output and input subsystems. It is also worth mentioning that during the
tests, it was quite slow in detecting button presses, which may lead to problems in the actual design.
Realisation:

Breadboard template:

After the circuit diagram and flowchart were finalised, I created a breadboard template that I can use
as a reference for the physical circuit.
Physical Circuit:

The final circuit was then ready to build. Unfortunately, it was now that I realised quite late into
development that the switches I thought were DPST were actually SPST, which meant I had to instead
use 2 smaller SPST switches to act as 1 DPST switch. This does make it harder to enter numbers and
actions, but it is still possible as long as the pair of switches are pressed at the same time.
Component list:

 SPST Switches x33 (originally supposed to be 16 DPST switches and 1 SPST switch)
 220 Ω Resistors x5
 1 kΩ Resistors x5
 100 kΩ Resistors x2
 Green LED
 Red LED
 7-segment displays x3
 74 47 Display Drivers x3
 PICAXE 18M2 Microprocessor x1
 Various Wires

Real Test Results:


Test Description Inputs Predicted Output Real Result
Status LEDs Calculator is turned 5V on pin A2 4.36V on pin A2
on
Any invalid operation 0V on pin A2 0.24V on pin A2
Perform addition 5 + 200 Display shows 205 Display eventually showed 205, but on one
attempt 250 was entered instead of 200
Perform 16 - 13 Display shows 003 Display showed 003
subtraction
Perform 6×4 Display shows 024 Display showed 024
multiplication
Perform division 50 ÷ 20 Display shows 002 Display showed 002
(2.5 truncated)
Negative result 19 - 20 Red LED on (0V on A2) 0.24V on pin A2 and RED LED turned on
detection
Division by zero 20 ÷ 0 Red LED on (0V on A2) 0.24V on pin A2 and RED LED turned on
Use previous 6 + 12 and then + 11 Display shows 029 Display showed 029, but had to press EXE
answer twice as it didn’t register the first time.
Reset button Press reset Display shows 000 Displays showed 000
Backspace button Enter 123, then press Display shows 012 Display showed 012
backspace
Maximum input Enter 256 Red LED on (0V on A2) 0.25V on pin A2 and RED LED turned on
value
Inactivtity sleep Nothing for 60s Display turns off Turned off after 58.57s
mode
Wake from sleep Press any button Display turns on Display turned on with the extra button press
not being recorded

Current Draw (mA)


Normal 89.7
Sleeping 60.1

All tests eventually passed, however, there were many times when a button press was not registered,
or it was incorrectly detected as another value by the system. The voltage levels and timing were also
not entirely accurate but are within the right range. In addition, I also recorded the current draw of the
circuit while it was in normal operation and in sleep mode, which shows values higher than expected.
Evaluation:

All things considered, the circuit has succeeded in accomplishing most of my objectives. It can perform
all the mathematical operations I aimed for on any number below 255. The calculator can detect
whether an operation will be impossible (division by 0) or produce a negative number and output an
error accordingly. All functions work as expected, including execute, backspace, and clear. The
inactivity timer also works and turns o the displays after approximately one minute, give or take a few
seconds.

However, there are two objectives that the circuit fails at: reliability and e iciency. Unfortunately, the
device is prone to error while entering numbers and operations. After testing the device a few times, I
found that around 5% of the time, a false command is read. This sometimes makes it quite frustrating
to use and can make it di icult to complete long strings of calculations. This could be remedied by using
DPST switches instead and adding a switch debouncing circuit such as a 555 monostable timer or a
Schmitt trigger. This would stop any fluctuations and produce a clear input signal.

The current draw from the power supply is also quite substantial (almost 90 mA) and is well above what
is currently on the market (10 mA). This could be due to the potential divider solution or possibly due to
the nature of the microprocessor used and the display drivers. Some microprocessors have a built-in
sleep mode which reduces the power consumption significantly. Using one of those might greatly
improve power e iciency.

In conclusion, while the calculator performs its core function well and meets most design goals, further
refinements in hardware would be needed to make it more reliable and e icient.

You might also like