DP 2 Sol
DP 2 Sol
DP 2 Sol
In this problem, you will use a version of the calculator circuit that uses the S3 boards knob for
input and the LCD display for output. You will find the VHDL for this version of the calculator
on the web site (in the VHDL source area). To get started, create a new project called dp2, copy
all of the provided source files to the project directory and add them all to your project. Note
that the testbench files should be added as simulation only.
The inputMod included in the provided source code uses the knob to control the input value to
the calculator. In this problem, you will be making changes to the inputMod and the
calculator module. First, you are to change the interface to the calculator as specified by the
entity declaration below.
entity calculator is port (
clk: in std_logic;
doit: in std_logic;
op: in std_logic_vector(1 downto 0);
dIn: in word;
result: out word);
end calculator;
The clear, load and add inputs have been replaced with an operation code called op and a
signal called doit. Op specifies which of four operations is to be performed and the operation is
carried out during any clock tick in which doit is high. Specifically, if op=00, the calculator is
cleared, if op=01, a new input value is loaded, if op=10, the input value is added to the stored
value, and if op=11, the input value is subtracted from the stored value. Modify the calculators
architecture to implement this new interface. Be sure to update the comments in the source code
to accurately reflect the new design.
The inputMod interface should also to be changed as indicated by the entity declaration below.
entity inputMod is port (
clk: in std_logic;
-- input signals from buttons and knob on board
btn: in buttons;
knob: in knobSigs;
-- reset signal from btn(0)
reset: out std_logic;
-- inputs to calculator
doit: out std_logic;
op: out std_logic_vector(1 downto 0);
dIn: out word);
end inputMod;
As with the calculator, the clear, load and add signals have been replaced by doit and op.
The inputMod should generate these signals using the knob and buttons. Specifically, when
-1-
btn(3) is held down, turning the knob should cause op to rotate through the four possible
values (the values should increase as the knob turns to the right and decrease as the knob turns
to the left). When btn(3) is not being held down, the knob should control the input value as in
the original version of the circuit. The doit signal should be asserted for one clock tick
whenever btn(2) is pressed down. The reset signal should be generated by btn(0) as in the
original circuit and btn(1) will not be used in the new version.
In addition to modifying inputMod and calculator, you will need to make a few some
changes to top. In particular, you should use the LEDs to display the current operation.
Specifically, when the operation is clear, led(7) should be turned on (and the others off), when
the operation is load, led(6) should be turned on, when the operation is add, led(5) should be
turned on and when the operation is subtract, led(4) should be turned on. You will also need to
modify the wiring of the various components within top.
You should modify the standalone testbench for the calculator circuit (called
testCalculator.vhd) to use the new interface and to exercise all the operations, including
the new subtraction operation. You will also simulate the entire circuit using the provided
testbench called testAll.vhd. Once you are satisfied that your circuit works correctly in
simulation, you should also implement the design on an S3 board in the Urbauer lab and verify
that it works correctly.
Here is what you should turn in. Please include every part, and in the order listed below.
A printed copy of the VHDL for all the circuit components that you modified
(calculator, inputMod, top). Your changes should be highlighted so that they are easy
to identify and the comments in the source code should be updated to accurately reflect the
new design. Your work will be evaluated on the correctness of your VHDL, the readability
of the source code and your comments. This part is worth 25 points.
A printed copy of your modified version of testCalculator.vhd (with appropriate
comments). Your work will be evaluated on the thoroughness of your testbench and your
comments. This part is worth 10 points.
A printed copy of the simulation output from your version of testCalculator.vhd,
with written comments pointing out how the simulation output demonstrates the correct
operation of the circuit at each step. If, for any reason, your circuit does not work correctly,
note that in your comments and explain what you did to try to correct the problem. Your
work will be evaluated on the correctness of the simulation output, the formatting and
organization of the simulation output and your written comments. This part is worth 10
points.
A printed copy of the output from your simulation run using the testbench testAll, with
comments pointing out how the simulation output demonstrates the correct operation of
the circuit at each step. Note that for this part, you must NOT modify the testbench. If, for
any reason, your circuit does not work correctly, note that in your comments and explain
what you did to try to correct the problem. Your work will be evaluated on the correctness
of the simulation output, the formatting and organization of the simulation output and
your written comments. This part is worth 15 points.
-2-
-3-
doit: in std_logic;
-- perform operation now
op: in std_logic_vector(1 downto 0); -- selected operation
dIn: in word;
result: out word);
end calculator;
-- input data
-- output result
architecture a1 of calculator is
signal dReg: word;
begin
process (clk) begin
if rising_edge(clk) then
<=
<=
<=
<=
-4-
end if;
end if;
end process;
result <= dReg;
end a1;
-5-
-- The output doit is asserted for one clock tick by each press
-- of btn(2). The output op specifies one of four operations.
-- It is controlled by the knob when btn(3) is held down.
---------------------------------------------------------------------library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use work.commonDefs.all;
entity inputMod is port (
clk: in std_logic;
-- input signals from buttons and knob on board
btn: in buttons;
knob: in knobSigs;
-- reset signal from btn(0)
reset: out std_logic;
-- inputs to calculator
doit: out std_logic;
op: out std_logic_vector(1 downto 0);
dIn: out word);
end inputMod;
architecture a1 of inputMod is
component debouncer ... end component;
component knobIntf ... end component;
-- current and previous debounced button signals
signal dBtn, prevDB: buttons;
-- debounced knob signals
signal dKnob: knobSigs;
-- outputs from knob interface
signal tick, clockwise : std_logic;
signal delta, knobVal: word;
-6-
end a1;
-7-
imod: inputMod port map(clk, btn, knob, reset, doit, op, dIn);
calc: calculator port map(clk, doit, op, dIn, result);
disp: displayMod port map(clk, reset, dIn, result, lcd);
-- display selected
with op select
led <= "10000000"
"01000000"
"00100000"
"00010000"
operation on LEDs
when
when
when
when
"00",
"01",
"10",
others;
end a1;
-9-
doit: in std_logic;
op: in std_logic_vector(1 downto 0);
dIn: in word;
result: out word);
end component;
signal clk:
std_logic := '0';
begin
-- create instance of calculator circuit
uut: calculator port map(clk, doit,
doit
doit
doit
doit
doit
doit
doit
doit
doit
doit
doit
doit
doit
doit
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
'1';
'0';
'1';
'0';
'1';
'0';
'1';
'0';
'1';
'0';
'1';
'0';
'1';
'0';
op <= "00";
wait for 20
op <= "01";
wait for 20
op <= "10";
wait for 20
op <= "10";
wait for 20
op <= "10";
wait for 20
op <= "10";
wait for 20
op <= "11";
wait for 20
dIn
ns;
dIn
ns;
dIn
ns;
dIn
ns;
dIn
ns;
dIn
ns;
dIn
ns;
- 10 -
doit
doit
doit
doit
doit
doit
doit
doit
<=
<=
<=
<=
<=
<=
<=
<=
'1';
'0';
'1';
'0';
'1';
'0';
'1';
'0';
op <= "11";
wait for 20
op <= "11";
wait for 20
op <= "11";
wait for 20
op <= "00";
wait for 20
dIn
ns;
dIn
ns;
dIn
ns;
dIn
ns;
- 11 -
The simulation results for the run using testCalculator appear below. Note that the op signal near the
center determines the operation to be performed. We start with a clear and a load, which both work
correctly. This is followed by and several add operations, which all produce the correct sums, then a
sequence of subtract operations, which also produce the correct results. Another clear operation is
performed at the end of the sequence.
- 12 -
The first part of the simulation results for the complete circuit appears below. The doit signal is activated
whenever btn(2) is pressed. The first time this happens, op=00 and a clear operation is performed. This is
also reflected in the LED value at the bottom of the window. The knob rotation then causes op to become
1, and then causes din to be incremented, so that when the next operation (a load) is performed, the value
1 is loaded into the calculator.
The middle section of the simulation appears below. This part shows several addition operations, all of
which produce the correct result. Also note that the LEDs display 20, which is what we expect for the
addition operation.
- 13 -
The final section of the simulation appears below. This part has several subtract operations, all of which
produce the correct result. The LEDs also show 10, which is what we expect for the subtraction operation.
The simulation ends with a clear operation which does properly clear the result.
- 14 -