In: Electrical Engineering
Using the following VHDL code for an 8 bit adder, make the sum be displayed on the seven segment display of an Elbert V2 Spartan 3A FPGA Board.
VHDL:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity state_bit_adder is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
D : in
STD_LOGIC;
Enable : out
STD_LOGIC_vector (2 downto 0);
input: in
std_logic_vector(7 downto 0);
SUM: out
std_logic_vector(8 downto 0));
end state_bit_adder;
architecture Behavioral of state_bit_adder is
type statetype is (start, secondstate);
signal state, nextstate: statetype;
signal tempsum1, tempsum: STD_LOGIC_VECTOR (8 downto 0);
begin
Enable <= "110";
process(clk, reset)
begin
if(reset ='0') then
state <= start;
elsif rising_edge(clk) then
state <= nextstate;
end if;
end process;
process(state, input, D)
begin
case (state) is
when start =>
tempsum1 <= ('0'&input);
if (D = '0') then
nextstate <= secondstate;
end if;
when secondstate =>
tempsum <= ('0'&input);
if (D = '0') then
nextstate <= start;
end if;
end case;
end process;
SUM <= tempsum1 + tempsum;
End Behavioral;
Constraint File:
###Clock
NET "clk" LOC = P129 | IOSTANDARD = LVTTL | PERIOD = 12 MHz;
NET "D" CLOCK_DEDICATED_ROUTE = FALSE;
############Input push buttons
NET "reset" LOC = P80 | IOSTANDARD = LVTTL | DRIVE = 8 | SLEW =
FAST | PULLUP;
NET "D" LOC = P79 | IOSTANDARD = LVTTL | DRIVE = 8 | SLEW = FAST |
PULLUP;
###########output LED
NET "SUM[7]" LOC = P46 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[6]" LOC = P47 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[5]" LOC = P48 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[4]" LOC = P49 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[3]" LOC = P50 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[2]" LOC = P51 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[1]" LOC = P54 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[0]" LOC = P55 | IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW =
FAST;
NET "SUM[8]" LOC = P117 | IOSTANDARD = LVTTL | SLEW =
SLOW | DRIVE = 12;
NET "Enable[0]" LOC = P120 | IOSTANDARD = LVTTL | SLEW
= SLOW | DRIVE = 12;
NET "Enable[1]" LOC = P121 | IOSTANDARD = LVTTL |
DRIVE = 8;
NET "Enable[2]" LOC = P124 | IOSTANDARD = LVTTL |
DRIVE = 8;
#####################################################################################################
## DP Switches
#####################################################################################################
NET "input[0]" LOC = P70 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[1]" LOC = P69 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[2]" LOC = P68 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[3]" LOC = P64 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[4]" LOC = P63 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[5]" LOC = P60 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[6]" LOC = P59 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[7]" LOC = P58 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
The VHDL code will changed as given below to include the seven segment display. Here, the output SUM is displaye in the seven segment display as hexadecimal.
VHDL Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity state_bit_adder is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
D : in
STD_LOGIC;
input: in std_logic_vector(7 downto 0);
Enable : out
STD_LOGIC_vector (2 downto 0);
Seven_Segment_Display : out STD_LOGIC_VECTOR (7 downto 0));
end state_bit_adder;
architecture Behavioral of state_bit_adder is
type statetype is (start, secondstate);
signal state, nextstate: statetype;
signal tempsum1, tempsum,SUM: STD_LOGIC_VECTOR (8 downto 0);
signal bcd0,bcd1,bcd2: STD_LOGIC_VECTOR (3 downto 0);
variable Seven_Segment_Display_output : std_logic_vector (7 downto 0) := (others => '1');
begin
Enable <= "110";
process(clk, reset)
begin
if(reset ='0') then
state <= start;
elsif rising_edge(clk) then
state <= nextstate;
end if;
end process;
process(state, input, D)
begin
case (state) is
when start =>
tempsum1 <= ('0'&input);
if (D = '0') then
nextstate <= secondstate;
end if;
when secondstate =>
tempsum <= ('0'&input);
if (D = '0') then
nextstate <= start;
end if;
end case;
end process;
SUM <= tempsum1 + tempsum;
process(SUM)
begin
--display 1st digit (LSD)
bcd0<=SUM(3 downto 0);
Enable <= "110";
case bcd0 is
when 0 => Seven_Segment_Display_output(7 downto 0)
:= B"00000010";
when 1 => Seven_Segment_Display_output(7 downto 0) :=
B"10011110";
when 2 => Seven_Segment_Display_output(7 downto 0) :=
B"00100100";
when 3 => Seven_Segment_Display_output(7 downto 0) :=
B"00001100";
when 4 => Seven_Segment_Display_output(7 downto 0) :=
B"10011000";
when 5 => Seven_Segment_Display_output(7 downto 0) :=
B"01001000";
when 6 => Seven_Segment_Display_output(7 downto 0) :=
B"01000000";
when 7 => Seven_Segment_Display_output(7 downto 0) :=
B"00011110";
when 8 => Seven_Segment_Display_output(7 downto 0) :=
B"00000000";
when 9 => Seven_Segment_Display_output(7 downto 0) :=
B"00011000";
when 10 => Seven_Segment_Display_output(7 downto 0) :=
B"00010000";
when 11 => Seven_Segment_Display_output(7 downto 0) :=
B"11000000";
when 12 => Seven_Segment_Display_output(7 downto 0) :=
B"01100010";
when 13 => Seven_Segment_Display_output(7 downto 0) :=
B"01000010";
when 14 => Seven_Segment_Display_output(7 downto 0) :=
B"00001100";
when 15 => Seven_Segment_Display_output(7 downto 0) :=
B"00011100";
when others => Seven_Segment_Display_output(7 downto 0) :=
B"11111111";
end case;
Seven_Segment_Display(7 downto 0) <= Seven_Segment_Display_output(7 downto 0);
--display 2nd digit
Enable <= "101";
bcd1<=SUM(7 downto 4);
case bcd1 is
when 0 => Seven_Segment_Display_output(7 downto 0)
:= B"00000010";
when 1 => Seven_Segment_Display_output(7 downto 0) :=
B"10011110";
when 2 => Seven_Segment_Display_output(7 downto 0) :=
B"00100100";
when 3 => Seven_Segment_Display_output(7 downto 0) :=
B"00001100";
when 4 => Seven_Segment_Display_output(7 downto 0) :=
B"10011000";
when 5 => Seven_Segment_Display_output(7 downto 0) :=
B"01001000";
when 6 => Seven_Segment_Display_output(7 downto 0) :=
B"01000000";
when 7 => Seven_Segment_Display_output(7 downto 0) :=
B"00011110";
when 8 => Seven_Segment_Display_output(7 downto 0) :=
B"00000000";
when 9 => Seven_Segment_Display_output(7 downto 0) :=
B"00011000";
when 10 => Seven_Segment_Display_output(7 downto 0) :=
B"00010000";
when 11 => Seven_Segment_Display_output(7 downto 0) :=
B"11000000";
when 12 => Seven_Segment_Display_output(7 downto 0) :=
B"01100010";
when 13 => Seven_Segment_Display_output(7 downto 0) :=
B"01000010";
when 14 => Seven_Segment_Display_output(7 downto 0) :=
B"00001100";
when 15 => Seven_Segment_Display_output(7 downto 0) :=
B"00011100";
when others => Seven_Segment_Display_output(7 downto 0) :=
B"11111111";
end case;
Seven_Segment_Display(7 downto 0) <= Seven_Segment_Display_output(7 downto 0);
--display 3rd digit (MSD)
Enable <= "011";
bcd2<=SUM(9 downto 8);
case bcd2 is
when 0 => Seven_Segment_Display_output(7 downto 0)
:= B"00000010";
when 1 => Seven_Segment_Display_output(7 downto 0) :=
B"10011110";
when 2 => Seven_Segment_Display_output(7 downto 0) :=
B"00100100";
when 3 => Seven_Segment_Display_output(7 downto 0) :=
B"00001100";
when 4 => Seven_Segment_Display_output(7 downto 0) :=
B"10011000";
when 5 => Seven_Segment_Display_output(7 downto 0) :=
B"01001000";
when 6 => Seven_Segment_Display_output(7 downto 0) :=
B"01000000";
when 7 => Seven_Segment_Display_output(7 downto 0) :=
B"00011110";
when 8 => Seven_Segment_Display_output(7 downto 0) :=
B"00000000";
when 9 => Seven_Segment_Display_output(7 downto 0) :=
B"00011000";
when 10 => Seven_Segment_Display_output(7 downto 0) :=
B"00010000";
when 11 => Seven_Segment_Display_output(7 downto 0) :=
B"11000000";
when 12 => Seven_Segment_Display_output(7 downto 0) :=
B"01100010";
when 13 => Seven_Segment_Display_output(7 downto 0) :=
B"01000010";
when 14 => Seven_Segment_Display_output(7 downto 0) :=
B"00001100";
when 15 => Seven_Segment_Display_output(7 downto 0) :=
B"00011100";
when others => Seven_Segment_Display_output(7 downto 0) :=
B"11111111";
end case;
Seven_Segment_Display(7 downto 0) <= Seven_Segment_Display_output(7 downto 0);
end process;
End Behavioral;
Constraint File:
############Clock 12MHz
NET "clk" LOC=P129 | IOSTANDARD = LVTTL | PERIOD=12MHz;
NET "D" CLOCK_DEDICATED_ROUTE = FALSE;
############Input push buttons
NET "reset" LOC = P80 | IOSTANDARD = LVTTL | DRIVE = 8 | SLEW =
FAST | PULLUP;
NET "D" LOC = P79 | IOSTANDARD = LVTTL | DRIVE = 8 | SLEW = FAST |
PULLUP;
###########Output Seven Segment Display
NET " Seven_Segment_Display[7]" LOC = P117 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
NET " Seven_Segment_Display[6]" LOC = P116 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
NET " Seven_Segment_Display[5]" LOC = P115 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
NET " Seven_Segment_Display[4]" LOC = P113 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
NET " Seven_Segment_Display[3]" LOC = P112 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
NET " Seven_Segment_Display[2]" LOC = P111 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
NET " Seven_Segment_Display[1]" LOC = P110 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
NET " Seven_Segment_Display[0]" LOC = P114 |
IOSTANDARD = LVTTL | DRIVE = 8;#| SLEW = FAST;
###Seven Segment Display Enable
NET "Enable[0]" LOC = P120 | IOSTANDARD = LVTTL | SLEW
= SLOW | DRIVE = 12;
NET "Enable[1]" LOC = P121 | IOSTANDARD = LVTTL |
DRIVE = 8;
NET "Enable[2]" LOC = P124 | IOSTANDARD = LVTTL |
DRIVE = 8;
###########DP Switches
NET "input[0]" LOC = P70 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[1]" LOC = P69 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[2]" LOC = P68 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[3]" LOC = P64 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[4]" LOC = P63 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[5]" LOC = P60 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[6]" LOC = P59 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;
NET "input[7]" LOC = P58 | PULLUP | IOSTANDARD = LVTTL | SLEW =
FAST | DRIVE = 8;