Calculate fmax of Altera design - vhdl
After I finished my design compilation on Quartus, I get multiple result for fmax as shown below. I want to know, what does it means? and How can I calculate the fmax of the all design?.
My design is implementation for the following equation:
for(i = 1; i < 5; i++)
{
T += ( ((Rv[i] - Ru[i]))^2 + ((Iv[i] - Iu[i]))^2 )
}
assume the following:
1. use 4 add-sub, 2 squarer, and eight 21-bit register file(parallel input/output) .
2. finished all operation in 8 clock cycles.
Note: - each adder/subtractor is 21-bit and has a selector pin '1' for add or '0' for sub.
- squarer is 9 bit.
- T is 21 bit.
This is the FSM for my design
According the above, this is my code
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity EDCfunction_TopEntity is
port
(
clk, reset : in std_logic;
Rv1 : in std_logic_vector (8-1 downto 0);
Iv1 : in std_logic_vector (8-1 downto 0);
Ru1 : in std_logic_vector (8-1 downto 0);
Iu1 : in std_logic_vector (8-1 downto 0);
Rv2 : in std_logic_vector (8-1 downto 0);
Iv2 : in std_logic_vector (8-1 downto 0);
Ru2 : in std_logic_vector (8-1 downto 0);
Iu2 : in std_logic_vector (8-1 downto 0);
Rv3 : in std_logic_vector (8-1 downto 0);
Iv3 : in std_logic_vector (8-1 downto 0);
Ru3 : in std_logic_vector (8-1 downto 0);
Iu3 : in std_logic_vector (8-1 downto 0);
Rv4 : in std_logic_vector (8-1 downto 0);
Iv4 : in std_logic_vector (8-1 downto 0);
Ru4 : in std_logic_vector (8-1 downto 0);
Iu4 : in std_logic_vector (8-1 downto 0);
T : out std_logic_vector (21-1 downto 0)
);
end EDCfunction_TopEntity;
architecture behavioral of EDCfunction_TopEntity is
type clock_state is (zero, zero_clk2, one, two, two_clk2, three, three_clk2, four, four_clk2, five, six, seven, eight);
type add_sub_type is array (4-1 downto 0) of std_logic_vector (21-1 downto 0);
type squarer_in_type is array (2-1 downto 0) of std_logic_vector (9-1 downto 0);
type squarer_out_type is array (2-1 downto 0) of std_logic_vector (18-1 downto 0);
signal cc_state, cn_state : clock_state;
signal clk_reg_file, reset_reg_file, s_wr_en : std_logic;
signal add_sub_flage, state_mux : std_logic_vector (4-1 downto 0);
signal dataa_add_sub, datab_add_sub, result_add_sub : add_sub_type;
signal dataa_squarer : squarer_in_type;
signal result_squarer : squarer_out_type;
signal w_addr_reg_file, r_addr_reg_file : std_logic_vector (8-1 downto 0);
signal s_w_data_0, s_w_data_1, s_w_data_2, s_w_data_3, s_w_data_4, s_w_data_5, s_w_data_6, s_w_data_7,
s_r_data_0, s_r_data_1, s_r_data_2, s_r_data_3, s_r_data_4, s_r_data_5, s_r_data_6, s_r_data_7
: std_logic_vector (21-1 downto 0);
alias R0 is s_w_data_0(21-1 downto 0);
alias R0H is s_w_data_0(21-1 downto 10);
alias R0L is s_w_data_0(9 downto 0);
alias R1 is s_w_data_1(21-1 downto 0);
alias R1H is s_w_data_1(21-1 downto 10);
alias R1L is s_w_data_1(9 downto 0);
alias R2 is s_w_data_2(21-1 downto 0);
alias R2H is s_w_data_2(21-1 downto 10);
alias R2L is s_w_data_2(9 downto 0);
alias R3 is s_w_data_3(21-1 downto 0);
alias R3H is s_w_data_3(21-1 downto 10);
alias R3L is s_w_data_3(9 downto 0);
alias R4 is s_w_data_4(21-1 downto 0);
alias R4H is s_w_data_4(21-1 downto 10);
alias R4L is s_w_data_4(9 downto 0);
alias R5 is s_w_data_5(21-1 downto 0);
alias R5H is s_w_data_5(21-1 downto 10);
alias R5L is s_w_data_5(9 downto 0);
alias R6 is s_w_data_6(21-1 downto 0);
alias R6H is s_w_data_6(21-1 downto 10);
alias R6L is s_w_data_6(9 downto 0);
alias R7 is s_w_data_7(21-1 downto 0);
alias R7H is s_w_data_7(21-1 downto 10);
alias R7L is s_w_data_7(9 downto 0);
component lpm_adder_subtractor
port
(
add_sub : IN STD_LOGIC ;
dataa : IN STD_LOGIC_VECTOR (20 DOWNTO 0);
datab : IN STD_LOGIC_VECTOR (20 DOWNTO 0);
result : OUT STD_LOGIC_VECTOR (20 DOWNTO 0)
);
end component;
component lpm_squarer
PORT
(
dataa : IN STD_LOGIC_VECTOR (8 DOWNTO 0);
result : OUT STD_LOGIC_VECTOR (17 DOWNTO 0)
);
end component;
component register_file
port
(
clk, reset : in std_logic;
wr_en : in std_logic;
w_addr : in std_logic_vector (8-1 downto 0);
w_data_0 : in std_logic_vector (21-1 downto 0);
w_data_1 : in std_logic_vector (21-1 downto 0);
w_data_2 : in std_logic_vector (21-1 downto 0);
w_data_3 : in std_logic_vector (21-1 downto 0);
w_data_4 : in std_logic_vector (21-1 downto 0);
w_data_5 : in std_logic_vector (21-1 downto 0);
w_data_6 : in std_logic_vector (21-1 downto 0);
w_data_7 : in std_logic_vector (21-1 downto 0);
r_addr : in std_logic_vector (8-1 downto 0);
r_data_0 : out std_logic_vector (21-1 downto 0);
r_data_1 : out std_logic_vector (21-1 downto 0);
r_data_2 : out std_logic_vector (21-1 downto 0);
r_data_3 : out std_logic_vector (21-1 downto 0);
r_data_4 : out std_logic_vector (21-1 downto 0);
r_data_5 : out std_logic_vector (21-1 downto 0);
r_data_6 : out std_logic_vector (21-1 downto 0);
r_data_7 : out std_logic_vector (21-1 downto 0)
);
end component;
begin
A0 : lpm_adder_subtractor port map (add_sub_flage(0), dataa_add_sub(0), datab_add_sub(0), result_add_sub(0));
A1 : lpm_adder_subtractor port map (add_sub_flage(1), dataa_add_sub(1), datab_add_sub(1), result_add_sub(1));
A2 : lpm_adder_subtractor port map (add_sub_flage(2), dataa_add_sub(2), datab_add_sub(2), result_add_sub(2));
A3 : lpm_adder_subtractor port map (add_sub_flage(3), dataa_add_sub(3), datab_add_sub(3), result_add_sub(3));
S0 : lpm_squarer port map (dataa_squarer(0), result_squarer(0));
S1 : lpm_squarer port map (dataa_squarer(1), result_squarer(1));
U0 : register_file port map (clk, reset_reg_file, s_wr_en, w_addr_reg_file, s_w_data_0, s_w_data_1, s_w_data_2,
s_w_data_3, s_w_data_4, s_w_data_5, s_w_data_6, s_w_data_7, r_addr_reg_file,
s_r_data_0, s_r_data_1, s_r_data_2, s_r_data_3, s_r_data_4, s_r_data_5, s_r_data_6,
s_r_data_7);
process (cc_state, reset, Rv1, Iv1, Ru1, Iu1, Rv2, Iv2, Ru2, Iu2, Rv3, Iv3, Ru3, Iu3, Rv4, Iv4, Ru4, Iu4)
begin
case cc_state is
when zero =>
s_wr_en <= '1';
w_addr_reg_file <= "11111111";
R0H <= std_logic_vector(resize(signed(Rv1), R0H'length));
R0L <= std_logic_vector(resize(signed(Ru1), R0L'length));
R1H <= std_logic_vector(resize(signed(Iv1), R1H'length));
R1L <= std_logic_vector(resize(signed(Iu1), R1L'length));
R2H <= std_logic_vector(resize(signed(Rv2), R2H'length));
R2L <= std_logic_vector(resize(signed(Ru2), R2L'length));
R3H <= std_logic_vector(resize(signed(Iv2), R3H'length));
R3L <= std_logic_vector(resize(signed(Iu2), R3L'length));
R4H <= std_logic_vector(resize(signed(Rv3), R4H'length));
R4L <= std_logic_vector(resize(signed(Ru3), R4L'length));
R5H <= std_logic_vector(resize(signed(Iv3), R5H'length));
R5L <= std_logic_vector(resize(signed(Iu3), R5L'length));
R6H <= std_logic_vector(resize(signed(Rv4), R6H'length));
R6L <= std_logic_vector(resize(signed(Ru4), R6L'length));
R7H <= std_logic_vector(resize(signed(Iv4), R7H'length));
R7L <= std_logic_vector(resize(signed(Iu4), R7L'length));
--clk_reg_file <= '1';
--T <= result_add_sub(0);
cn_state <= zero_clk2;
when zero_clk2 =>
r_addr_reg_file <= "11111111";
cn_state <= one;
when one =>
s_wr_en <= '0';
--w_addr_reg_file <= "00001111";
add_sub_flage(0) <= '0';
add_sub_flage(1) <= '0';
add_sub_flage(2) <= '0';
add_sub_flage(3) <= '0';
--r_addr_reg_file <= "00001111";
dataa_add_sub(0) <= std_logic_vector(resize(signed(s_r_data_0 (21-1 downto 10)), dataa_add_sub(0)'length));
datab_add_sub(0) <= std_logic_vector(resize(signed(s_r_data_0 (9 downto 0)), dataa_add_sub(0)'length));
--s_w_data_0 <= result_add_sub(0);
--w_addr_reg_file <= "00000001";
dataa_add_sub(1) <= std_logic_vector(resize(signed(s_r_data_1 (21-1 downto 10)), dataa_add_sub(1)'length));
datab_add_sub(1) <= std_logic_vector(resize(signed(s_r_data_1 (9 downto 0)), dataa_add_sub(1)'length));
--s_w_data_1 <= result_add_sub(1);
--w_addr_reg_file <= "00000010";
dataa_add_sub(2) <= std_logic_vector(resize(signed(s_r_data_2 (21-1 downto 10)), dataa_add_sub(2)'length));
datab_add_sub(2) <= std_logic_vector(resize(signed(s_r_data_2 (9 downto 0)), dataa_add_sub(2)'length));
--s_w_data_2 <= result_add_sub(2);
--w_addr_reg_file <= "00000100";
dataa_add_sub(3) <= std_logic_vector(resize(signed(s_r_data_3 (21-1 downto 10)), dataa_add_sub(3)'length));
datab_add_sub(3) <= std_logic_vector(resize(signed(s_r_data_3 (9 downto 0)), dataa_add_sub(3)'length));
--s_w_data_3 <= result_add_sub(3);
--w_addr_reg_file <= "00001000";
--T <= result_add_sub(3);
--clk_reg_file <= '1';
--r_addr_reg_file <= "11110000";
cn_state <= two;
--state_mux <= "0001";
when two =>
s_wr_en <= '1';
w_addr_reg_file <= "00001111";
R0 <= result_add_sub(0);
R1 <= result_add_sub(1);
R2 <= result_add_sub(2);
R3 <= result_add_sub(3);
dataa_squarer(0) <= result_add_sub(0) (9-1 downto 0);
dataa_squarer(1) <= result_add_sub(1) (9-1 downto 0);
dataa_add_sub(0) <= std_logic_vector(resize(signed(s_r_data_4 (21-1 downto 10)), dataa_add_sub(0)'length));
datab_add_sub(0) <= std_logic_vector(resize(signed(s_r_data_4 (9 downto 0)), dataa_add_sub(0)'length));
dataa_add_sub(1) <= std_logic_vector(resize(signed(s_r_data_5 (21-1 downto 10)), dataa_add_sub(1)'length));
datab_add_sub(1) <= std_logic_vector(resize(signed(s_r_data_5 (9 downto 0)), dataa_add_sub(1)'length));
dataa_add_sub(2) <= std_logic_vector(resize(signed(s_r_data_6 (21-1 downto 10)), dataa_add_sub(2)'length));
datab_add_sub(2) <= std_logic_vector(resize(signed(s_r_data_6 (9 downto 0)), dataa_add_sub(2)'length));
dataa_add_sub(3) <= std_logic_vector(resize(signed(s_r_data_7 (21-1 downto 10)), dataa_add_sub(3)'length));
datab_add_sub(3) <= std_logic_vector(resize(signed(s_r_data_7 (9 downto 0)), dataa_add_sub(3)'length));
cn_state <= two_clk2;
when two_clk2 =>
cn_state <= three;
when three =>
--s_wr_en <= '1';
w_addr_reg_file <= "11110011";
R0 <= std_logic_vector(resize(signed(result_squarer(0)), R0'length));
R1 <= std_logic_vector(resize(signed(result_squarer(1)), R0'length));
R4 <= result_add_sub(0);
R5 <= result_add_sub(1);
R6 <= result_add_sub(2);
R7 <= result_add_sub(3);
add_sub_flage(0) <= '1';
dataa_add_sub(0) <= std_logic_vector(resize(signed(result_squarer(0)), dataa_add_sub(0)'length));
datab_add_sub(0) <= std_logic_vector(resize(signed(result_squarer(1)), datab_add_sub(0)'length));
dataa_squarer(0) <= s_r_data_2 (9-1 downto 0);
dataa_squarer(1) <= s_r_data_3 (9-1 downto 0);
cn_state <= three_clk2;
when three_clk2 =>
cn_state <= four;
when four =>
w_addr_reg_file <= "00000110";
R0 <= result_add_sub(0);
R1 <= std_logic_vector(resize(signed(result_squarer(0)), R0'length));
R2 <= std_logic_vector(resize(signed(result_squarer(1)), R0'length));
add_sub_flage(1) <= '1';
dataa_add_sub(1) <= std_logic_vector(resize(signed(result_squarer(0)), dataa_add_sub(1)'length));
datab_add_sub(1) <= std_logic_vector(resize(signed(result_squarer(1)), datab_add_sub(1)'length));
dataa_squarer(0) <= s_r_data_4 (9-1 downto 0);
dataa_squarer(1) <= s_r_data_5 (9-1 downto 0);
cn_state <= four_clk2;
when four_clk2 =>
cn_state <= five;
when five =>
w_addr_reg_file <= "00001110";
R1 <= result_add_sub(1);
R2 <= std_logic_vector(resize(signed(result_squarer(0)), R2'length));
R3 <= std_logic_vector(resize(signed(result_squarer(1)), R3'length));
add_sub_flage(2) <= '1';
dataa_add_sub(0) <= R0;
datab_add_sub(0) <= result_add_sub(1);
dataa_add_sub(2) <= std_logic_vector(resize(signed(result_squarer(0)), dataa_add_sub(2)'length));
datab_add_sub(2) <= std_logic_vector(resize(signed(result_squarer(1)), datab_add_sub(2)'length));
dataa_squarer(0) <= s_r_data_6 (9-1 downto 0);
dataa_squarer(1) <= s_r_data_7 (9-1 downto 0);
cn_state <= six;
when six =>
w_addr_reg_file <= "00001111";
R0 <= result_add_sub(0);
R1 <= result_add_sub(2);
R2 <= std_logic_vector(resize(signed(result_squarer(0)), R2'length));
R3 <= std_logic_vector(resize(signed(result_squarer(1)), R3'length));
add_sub_flage(3) <= '1';
dataa_add_sub(0) <= result_add_sub(0);
datab_add_sub(0) <= result_add_sub(2);
dataa_add_sub(3) <= std_logic_vector(resize(signed(result_squarer(0)), dataa_add_sub(2)'length));
datab_add_sub(3) <= std_logic_vector(resize(signed(result_squarer(1)), datab_add_sub(2)'length));
cn_state <= seven;
when seven =>
w_addr_reg_file <= "00000011";
R0 <= result_add_sub(0);
R1 <= result_add_sub(3);
dataa_add_sub(0) <= result_add_sub(0);
datab_add_sub(0) <= result_add_sub(3);
--R0 <= result_add_sub(0);
--T <= result_add_sub(0);
cn_state <= eight;
when eight =>
w_addr_reg_file <= "00000001";
R0 <= result_add_sub(0);
T <= result_add_sub(0);
cn_state <= zero;
end case;
--if(state_mux = "0001") then
--end if;
end process;
process (clk, reset)
begin
reset_reg_file <= reset;
if(reset = '1') then
cc_state <= zero;
elsif (clk'event and clk = '1') then
cc_state <= cn_state;
end if;
end process;
end behavioral;
Any help,
Regards
cc_state is presumably being treated as a clock in your 'combinatorial' process, but your code is too complex to make it obvious why. It's likely that you're reading something before assigning to it, which implies clocked functionality. Your synthesis report will tell you what cc_state is clocking, and why.
You need to rewrite your code to simplify it - this is way too complex. Move out your LPM code into a new module which is unclocked. This should be controlled by your 3-bit state signal. Instantiate this in your top-level clocked module, which should contain only the register file, and a simplified FSM.
You should also think about:
Move the stuff in the architecture declarative region into a package
Make use of subtypes to get rid of all the std_logic_vector stuff
If you end up with a case statement in your combinatorial module, make sure that you set default values for all outputs, or assign in all branches (your existing code doesn't assign to s_wr_en in all branches)
If it still doesn't work, post a much simpler question. Your algorithm isn't relevant to the question.
Related
VHDL: Cache memory output signal not consistent and varies between either halfs of the output being right, but never the whole thing
I hope you guys are well :) I am trying to implement a simple cache memory system, however I am finding myself unable to properly do so. When I attempt to test my read miss/ read hit, I am getting the following result: VHDL Signals. As I understand my design, the Read Miss state should be writing 1011111110101100 however I am either getting 10111111100000000 or 00000010101100. My result seems to fluctuate between both results. s_addr refers to a new instruction from the CPU which starts one process, which in turn starts the state process should there be any changes. I have provided some code. I am unsure of how to proceed. I've walked through my code and I do not understand why it splits the values like that when the output was supposed occur in one go. Finally, I suspect that this may have something to do with the fact that my signals are initially undefined for some reason. Full signal diagram I am not sure why for the first 6ns, the output of s_readdatta is undefined. My tag values stored in test1 and test2 are also undefined and I am not sure why. I would appreciate any insight you guys can offer. Thank you! VHDL code library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use ieee.numeric_bit_unsigned.all; entity cache is generic( ram_size : INTEGER := 32768 ); port( clock : in std_logic; reset : in std_logic; -- Avalon interface -- s_addr : in std_logic_vector (31 downto 0); s_read : in std_logic; s_readdata : out std_logic_vector (31 downto 0); s_write : in std_logic; s_writedata : in std_logic_vector (31 downto 0); s_waitrequest : out std_logic; m_addr : out integer range 0 to ram_size-1; m_read : out std_logic; m_readdata : in std_logic_vector (7 downto 0); m_write : out std_logic; m_writedata : out std_logic_vector (7 downto 0); m_waitrequest : in std_logic; test1: out std_logic_vector (5 downto 0); test2: out std_logic_vector (5 downto 0) ); end cache; architecture arch of cache is -- declare signals here -- 15 bit signal will be of the following form: VDTTTTBBBBBWWbb constant number_of_cache_lines: integer := 128; TYPE t_cache_memory IS ARRAY(number_of_cache_lines-1 downto 0) OF STD_LOGIC_VECTOR(31 downto 0); -- For data requested by CPU signal tag_bits: std_logic_vector (5 downto 0); signal block_index: std_logic_vector (4 downto 0); signal block_index_int: integer; signal word_index: std_logic_vector (1 downto 0); signal word_index_int: integer; -- For data in the cache signal in_cache_tag_bits: std_logic_vector (5 downto 0); signal in_cache_valid_bit: std_logic; signal in_cache_dirty_bit: std_logic; signal temp_s_addr: std_logic_vector(14 downto 0); signal retrieved_address: std_logic_vector (31 downto 0); type t_State is (readHit, writeHit, writeBack, readMiss, writeMiss, idle); signal state: t_State; signal cache_memory: t_cache_memory; begin -- For CPU address temp_s_addr(3 downto 0) <= (others => '0'); temp_s_addr(14 downto 4) <= s_addr (14 downto 4); tag_bits <= s_addr (14 downto 9); block_index <= s_addr (8 downto 4); block_index_int <= 4*to_integer(unsigned(block_index)); word_index <= s_addr (3 downto 2); word_index_int <= to_integer(unsigned(word_index)); process (s_addr) begin if block_index_int /= -2147483648 then retrieved_address <= cache_memory(block_index_int + word_index_int); in_cache_valid_bit <= cache_memory(block_index_int)(15); in_cache_dirty_bit <= cache_memory(block_index_int)(14); in_cache_tag_bits <= cache_memory(block_index_int)(13 downto 8); end if; if s_read = '1' and s_write ='0' then if in_cache_valid_bit = '1' then test1 <= s_addr (14 downto 9); test2 <= in_cache_tag_bits; if in_cache_tag_bits = s_addr (14 downto 9) then state <= readHit; else if in_cache_dirty_bit = '1' then state <= writeBack; else state <= readMiss; end if; end if; else state <= readMiss; end if; elsif s_write = '1' and s_read = '0' then if in_cache_valid_bit = '1' then if tag_bits = in_cache_tag_bits then state <= writeHit; else if in_cache_dirty_bit = '1' then state <= writeBack; else state <= writeMiss; end if; end if; end if; else state <= idle; end if; end process; process(state) begin s_waitrequest <= '1'; case state is -- If CPU is not doing anything when idle => report "No Reads or Writes have occured."; when readHit => report "Read Hit Occured:"; s_readdata <= retrieved_address; -- If write hit when writeHit => report "Write Hit Occured:"; cache_memory(block_index_int + word_index_int)(7 downto 0) <= s_addr(7 downto 0); cache_memory(block_index_int)(13 downto 8) <= tag_bits; cache_memory(block_index_int)(14) <= '1'; cache_memory(block_index_int)(15) <= '1'; cache_memory(block_index_int)(31 downto 16) <= (others => '0'); --state <= idle; -- If cache hit but dirty bit then write-back when writeBack => report "Write Back Occured:"; -- Write back into memory first m_write <= '1'; m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0))); m_writedata <= temp_s_addr(7 downto 0); m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0))) + 4; m_writedata(3 downto 0) <= "0100"; m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0))) + 8; m_writedata(3 downto 0) <= "1000"; m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0))) + 12; m_writedata(3 downto 0) <= "1100"; m_write <= '0'; -- Write to cache cache_memory(block_index_int)(13 downto 8) <= tag_bits; cache_memory(block_index_int)(14) <= '0'; cache_memory(block_index_int)(15) <= '0'; cache_memory(block_index_int)(31 downto 16) <= (others => '0'); --state <= idle; when readMiss => report "Read Miss Occured:"; m_read <= '1'; m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0))); cache_memory(block_index_int)(7 downto 0) <= m_readdata; cache_memory(block_index_int)(31 downto 8) <= (others => '0'); m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0)))+4; cache_memory(block_index_int+1)(7 downto 0) <= m_readdata; cache_memory(block_index_int+1)(31 downto 8) <= (others => '0'); m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0)))+8; cache_memory(block_index_int+2)(7 downto 0) <= m_readdata; cache_memory(block_index_int+2)(31 downto 8) <= (others => '0'); m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0)))+12; cache_memory(block_index_int+3)(7 downto 0) <= m_readdata; cache_memory(block_index_int+3)(31 downto 8) <= (others => '0'); m_read <= '0'; cache_memory(block_index_int)(13 downto 8) <= tag_bits; cache_memory(block_index_int)(14) <= '0'; cache_memory(block_index_int)(15) <= '1'; cache_memory(block_index_int)(31 downto 16) <= (others => '0'); s_readdata<= cache_memory(block_index_int + word_index_int); --state <= idle; -- If write miss when writeMiss => report "Write Miss Occured:"; m_write <= '1'; m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0))) + word_index_int; m_writedata <= s_addr(7 downto 0); m_write <= '0'; m_read <= '1'; m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0))); cache_memory(block_index_int)(7 downto 0) <= m_readdata; cache_memory(block_index_int)(31 downto 8) <= (others => '0'); m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0)))+4; cache_memory(block_index_int+1)(7 downto 0) <= m_readdata; cache_memory(block_index_int+1)(31 downto 8) <= (others => '0'); m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0)))+8; cache_memory(block_index_int+2)(7 downto 0) <= m_readdata; cache_memory(block_index_int+2)(31 downto 8) <= (others => '0'); m_addr <= to_integer(unsigned(temp_s_addr(14 downto 0)))+12; cache_memory(block_index_int+3)(7 downto 0) <= m_readdata; cache_memory(block_index_int+3)(31 downto 8) <= (others => '0'); m_read <= '0'; cache_memory(block_index_int)(13 downto 8) <= tag_bits; cache_memory(block_index_int)(14) <= '0'; cache_memory(block_index_int)(15) <= '1'; cache_memory(block_index_int)(31 downto 16) <= (others => '0'); --state <= idle; end case; s_waitrequest <= '0'; end process; end arch; Testbench Code library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity cache_tb is end cache_tb; architecture behavior of cache_tb is component cache is generic( ram_size : INTEGER := 32768 ); port( clock : in std_logic; reset : in std_logic; -- Avalon interface -- s_addr : in std_logic_vector (31 downto 0); s_read : in std_logic; s_readdata : out std_logic_vector (31 downto 0); s_write : in std_logic; s_writedata : in std_logic_vector (31 downto 0); s_waitrequest : out std_logic; m_addr : out integer range 0 to ram_size-1; m_read : out std_logic; m_readdata : in std_logic_vector (7 downto 0); m_write : out std_logic; m_writedata : out std_logic_vector (7 downto 0); m_waitrequest : in std_logic; test1: out std_logic_vector (5 downto 0); test2: out std_logic_vector (5 downto 0) ); end component; component memory is GENERIC( ram_size : INTEGER := 32768; mem_delay : time := 10 ns; clock_period : time := 1 ns ); PORT ( clock: IN STD_LOGIC; writedata: IN STD_LOGIC_VECTOR (7 DOWNTO 0); address: IN INTEGER RANGE 0 TO ram_size-1; memwrite: IN STD_LOGIC; memread: IN STD_LOGIC; readdata: OUT STD_LOGIC_VECTOR (7 DOWNTO 0); waitrequest: OUT STD_LOGIC ); end component; -- test signals signal reset : std_logic := '0'; signal clk : std_logic := '0'; constant clk_period : time := 1 ns; signal s_addr : std_logic_vector (31 downto 0); signal s_read : std_logic; signal s_readdata : std_logic_vector (31 downto 0); signal s_write : std_logic; signal s_writedata : std_logic_vector (31 downto 0); signal s_waitrequest : std_logic; signal m_addr : integer range 0 to 2147483647; signal m_read : std_logic; signal m_readdata : std_logic_vector (7 downto 0); signal m_write : std_logic; signal m_writedata : std_logic_vector (7 downto 0); signal m_waitrequest : std_logic; signal test1: std_logic_vector (5 downto 0); signal test2: std_logic_vector (5 downto 0); begin -- Connect the components which we instantiated above to their -- respective signals. dut: cache port map( clock => clk, reset => reset, s_addr => s_addr, s_read => s_read, s_readdata => s_readdata, s_write => s_write, s_writedata => s_writedata, s_waitrequest => s_waitrequest, m_addr => m_addr, m_read => m_read, m_readdata => m_readdata, m_write => m_write, m_writedata => m_writedata, m_waitrequest => m_waitrequest, test1 => test1, test2 => test2 ); MEM : memory port map ( clock => clk, writedata => m_writedata, address => m_addr, memwrite => m_write, memread => m_read, readdata => m_readdata, waitrequest => m_waitrequest ); clk_process : process begin clk <= '0'; wait for clk_period/2; clk <= '1'; wait for clk_period/2; end process; test_process : process begin REPORT "***Initializing***"; s_read <= '0'; s_write <= '0'; s_addr <= "00000000000000000000000000000000"; wait for clk_period; report "Initializing Zero complete..."; report "***Start Testing***"; report "Read Miss Test:"; s_read <= '1'; s_write <= '0'; s_addr <= "11111111111111111111111110101111"; wait for clk_period; assert s_readdata(7 downto 0) = m_readdata report "DATA NOT IN CACHE"; wait for clk_period; report "Read Hit Test:"; s_read <= '1'; s_write <= '0'; s_addr <= "11111111111111111111111110101111"; wait for clk_period; assert s_readdata(7 downto 0) = m_readdata report "DATA NOT IN CACHE"; wait for clk_period; end process; end;
VHDL - Want to create a simple divider
I'm using Vivado 2018.2 I want to make a simple divider, say the input is 153 and the constant is 53. So with 153/53, I want to see 2 and the remainder 47. The code I have so far errors out (sequential). entity divider_main is port( dividend: in std_logic_vector(7 downto 0); remainder: out std_logic_vector(5 downto 0); quotient: out std_logic_vector(2 downto 0) ); end divider_main; architecture Behavioral of divider_main is signal dividend_signal: signed(7 downto 0); signal remainder_signal: std_logic_vector(5 downto 0); signal fifty_three: signed(7 downto 0); signal count: unsigned(2 downto 0); begin dividend_signal <= signed(dividend); fifty_three <= "00011101"; count <= "000"; process(dividend, dividend_signal) is begin if dividend_signal < fifty_three then remainder(5 downto 0) <= std_logic_vector(dividend_signal(5 downto 0)); quotient <= std_logic_vector(count); dividend_signal <= "00000000"; count(2 downto 0) <= "000"; else count <= count + 1; dividend_signal <= dividend_signal - fifty_three; quotient(2 downto 0) <= "000"; remainder <= "000000"; end if; end process; end Behavioral; I'm new to vhdl so let me know what I am doing wrong!
Getting correct values for few inputs. Not for all combinations in a 4*4 multiplier
I am writing a code for 4*4 multiplier. Although, i am getting correct values for few inputs, it gives me wrong values for few other. Please suggest me what logical errors are present here as i am unable to spot them library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity multiplier is Port ( a : in std_logic_vector (3 downto 0); b : in std_logic_vector (3 downto 0); result : out std_logic_vector (7 downto 0)); end multiplier; architecture Behavioral of multiplier is signal P0: std_logic_vector(7 downto 0); signal P1: std_logic_vector(7 downto 0); signal SP1: std_logic_vector(7 downto 0); signal P2: std_logic_vector(7 downto 0); signal SP2: std_logic_vector(7 downto 0); signal P3: std_logic_vector(7 downto 0); component genericadder Port ( a : in std_logic_vector(3 downto 0); b : in std_logic_vector(3 downto 0); sum : out std_logic_vector (4 downto 0)); end component; begin result(0) <= a(0) and b(0); P0(0) <= a(0) and b(1); P0(1) <= a(0) and b(2); P0(2) <= a(0) and b(3); P0(3) <='0'; P0(4) <= a(1) and b(0); P0(5) <= a(1) and b(1); P0(6) <= a(1) and b(2); P0(7) <= a(1) and b(3); ga_for : genericadder port map( a =>P0( 3 downto 0), b =>P0( 7 downto 4), sum =>P1(4 downto 0)); result(1)<= P1(0); SP1<= std_logic_vector(shift_right(unsigned(P1),1)); P1(4) <= a(2) and b(0); P1(5) <= a(2) and b(1); P1(6) <= a(2) and b(2); P1(7) <= a(2) and b(3); ga_for1 : genericadder port map( a =>SP1( 3 downto 0), b =>P1( 7 downto 4), sum =>P2(4 downto 0)); result(2) <= P2(0); SP2<= std_logic_vector(shift_right(unsigned(P2),1)); P2(4) <= a(3) and b(0); P2(5) <= a(3) and b(1); P2(6) <= a(3) and b(2); P2(7) <= a(3) and b(3); ga_for2 : genericadder port map( a =>SP2( 3 downto 0), b =>P2( 7 downto 4), sum =>P3(4 downto 0)); result(3)<=P3(0); result(4)<=P3(1); result(5)<=P3(2); result(6)<=P3(3); result(7)<=P3(4); end Behavioral; entity genericadder is generic ( n : Integer:=4 ); Port ( a : in STD_LOGIC_VECTOR (n-1 downto 0); b : in STD_LOGIC_VECTOR (n-1 downto 0); sum : out STD_LOGIC_VECTOR (n downto 0)); end genericadder; -- The genericadder is made up of full adders. Please let me know the error. I am really unable to move ahead
LFSR doesn't generate random values during simulation
I am new to VHDL, but have some idea. I made this LFSR but don't know why it is stuck between the initial seed value and the other XOR value. I am working with Altera Quartus 16 Lite and ISim. library ieee; use ieee.std_logic_1164.all; --creating a galois LFSR entity LFSR is port ( clk : in std_logic; rst : in std_logic; en : in std_logic; rdm_out : out std_logic_vector(15 downto 0); rdm_out_a : out std_logic_vector(7 downto 0); rdm_out_b : out std_logic_vector(7 downto 0); lfsr_Done : out std_logic --lfsr done ); end entity LFSR; architecture behavioral of LFSR is signal temp_out : std_logic_vector(15 downto 0) := (0 => '1' ,others => '0'); --initial value as seed signal temp_done : std_logic; begin process (clk, rst) begin if rising_edge (clk) then --module operates only when enabled if (rst = '1') then temp_out <= (0 => '1' ,others => '0'); temp_done <= '0'; elsif (en = '1') then temp_out <= temp_out(15 downto 11) & (temp_out(10) xor temp_out(0)) & temp_out(9 downto 5) & (temp_out(4) xor temp_out(0)) & temp_out(3 downto 0); --temp_out <= (temp_out(15) xor temp_out(0)) & (temp_out(14) xor temp_out(0)) & temp_out(13) & (temp_out(12) xor temp_out(0)) & temp_out(11 downto 4) & (temp_out(3) xor temp_out(0)) & temp_out(2 downto 0); temp_done <= '1'; end if; end if; end process; rdm_out <= temp_out(15 downto 0); rdm_out_a <= temp_out(15 downto 8); rdm_out_b <= temp_out(7 downto 0); lfsr_Done <= temp_done; end architecture behavioral;` The commented out temp_out is actual feedback (taps are 16,15,13, and 4) as I checked with random taps but still no improvement. And the testbench I used is this: library ieee; use ieee.std_logic_1164.all; entity lfsr_tb is end lfsr_tb; architecture test_bench of lfsr_tb is component LFSR port ( clk : in std_logic; rst : in std_logic; en : in std_logic; rdm_out : out std_logic_vector(15 downto 0); rdm_out_a : out std_logic_vector(7 downto 0); rdm_out_b : out std_logic_vector(7 downto 0); lfsr_Done : out std_logic ); end component; signal clk1: std_logic; signal rst1: std_logic; signal en1 : std_logic; signal rdm_out1 : std_logic_vector(15 downto 0); signal rdm_out_a1 : std_logic_vector(7 downto 0); signal rdm_out_b1 : std_logic_vector(7 downto 0); signal lfsr_Done1 : std_logic ; begin mapping: LFSR port map( clk => clk1, rst => rst1, en => en1, rdm_out => rdm_out1, rdm_out_a => rdm_out_a1, rdm_out_b => rdm_out_b1, lfsr_Done => lfsr_Done1 ); clock: process begin clk1 <= '0'; wait for 10 ps; clk1 <= '1'; wait for 10 ps; end process; reset: process begin rst1 <= '1'; wait for 10 ps; rst1 <= '0'; en1 <= '1'; wait for 800 ps; end process; end test_bench; This is the result I am getting:
Yes it was not shifting but this is one is working now. temp_out(15) <= temp_out(0);-- shifting bit temp_out(14) <= temp_out(15); temp_out(13) <= temp_out(14) xor temp_out(0); temp_out(12) <= temp_out(13) xor temp_out(0); temp_out(11) <= temp_out(12); temp_out(10) <= temp_out(11) xor temp_out(0); temp_out(9 downto 0) <= temp_out(10 downto 1); Hope it helps others. Thanks guys
i have a vhdl code that take a 16 bit binary converts it to 5 bcd(4bit) how can i connect each bcd with a display?
i have a code that take a 16 bit binary converts it to 5 bcd(4bit) how can i connect each bcd with a display? the bcd 0 has to connect to the display 0 (seven segment display) so that the binary number is going to convert to decimal and display it on 5 seven segment displays library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity binary_bcd is generic(N: positive := 16); port( clk, reset: in std_logic; binary_in: in std_logic_vector(N-1 downto 0); bcd0, bcd1, bcd2, bcd3, bcd4: out std_logic_vector(3 downto 0) ); end binary_bcd ; architecture behaviour of binary_bcd is type states is (start, shift, done); signal state, state_next: states; signal binary, binary_next: std_logic_vector(N-1 downto 0); signal bcds, bcds_reg, bcds_next: std_logic_vector(19 downto 0); -- output register keep output constant during conversion signal bcds_out_reg, bcds_out_reg_next: std_logic_vector(19 downto 0); -- need to keep track of shifts signal shift_counter, shift_counter_next: natural range 0 to N; begin process(clk, reset) begin if reset = '1' then binary <= (others => '0'); bcds <= (others => '0'); state <= start; bcds_out_reg <= (others => '0'); shift_counter <= 0; elsif falling_edge(clk) then binary <= binary_next; bcds <= bcds_next; state <= state_next; bcds_out_reg <= bcds_out_reg_next; shift_counter <= shift_counter_next; end if; end process; convert: process(state, binary, binary_in, bcds, bcds_reg, shift_counter) begin state_next <= state; bcds_next <= bcds; binary_next <= binary; shift_counter_next <= shift_counter; case state is when start => state_next <= shift; binary_next <= binary_in; bcds_next <= (others => '0'); shift_counter_next <= 0; when shift => if shift_counter = N then state_next <= done; else binary_next <= binary(N-2 downto 0) & 'L'; bcds_next <= bcds_reg(18 downto 0) & binary(N-1); shift_counter_next <= shift_counter + 1; end if; when done => state_next <= start; end case; end process; bcds_reg(19 downto 16) <= bcds(19 downto 16) + 3 when bcds(19 downto 16) > 4 else bcds(19 downto 16); bcds_reg(15 downto 12) <= bcds(15 downto 12) + 3 when bcds(15 downto 12) > 4 else bcds(15 downto 12); bcds_reg(11 downto 8) <= bcds(11 downto 8) + 3 when bcds(11 downto 8) > 4 else bcds(11 downto 8); bcds_reg(7 downto 4) <= bcds(7 downto 4) + 3 when bcds(7 downto 4) > 4 else bcds(7 downto 4); bcds_reg(3 downto 0) <= bcds(3 downto 0) + 3 when bcds(3 downto 0) > 4 else bcds(3 downto 0); bcds_out_reg_next <= bcds when state = done else bcds_out_reg; bcd4 <= bcds_out_reg(19 downto 16); bcd3 <= bcds_out_reg(15 downto 12); bcd2 <= bcds_out_reg(11 downto 8); bcd1 <= bcds_out_reg(7 downto 4); bcd0 <= bcds_out_reg(3 downto 0); end behaviour; test bench LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY tb_bcd IS END tb_bcd; ARCHITECTURE behavior OF tb_bcd IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT binary_bcd PORT( clk : IN std_logic; reset : IN std_logic; binary_in : IN std_logic_vector(15 downto 0); bcd0 : OUT std_logic_vector(3 downto 0); bcd1 : OUT std_logic_vector(3 downto 0); bcd2 : OUT std_logic_vector(3 downto 0); bcd3 : OUT std_logic_vector(3 downto 0); bcd4 : OUT std_logic_vector(3 downto 0) ); END COMPONENT; --Inputs signal clk : std_logic := '0'; signal reset : std_logic := '0'; signal binary_in : std_logic_vector(15 downto 0) := (others => '0'); --Outputs signal bcd0 : std_logic_vector(3 downto 0); signal bcd1 : std_logic_vector(3 downto 0); signal bcd2 : std_logic_vector(3 downto 0); signal bcd3 : std_logic_vector(3 downto 0); signal bcd4 : std_logic_vector(3 downto 0); -- Clock period definitions constant clk_period : time := 10 ns; BEGIN -- Instantiate the Unit Under Test (UUT) uut: binary_bcd PORT MAP ( clk => clk, reset => reset, binary_in => binary_in, bcd0 => bcd0, bcd1 => bcd1, bcd2 => bcd2, bcd3 => bcd3, bcd4 => bcd4 ); -- Clock process definitions clk_process :process begin clk <= '0'; wait for clk_period/2; clk <= '1'; wait for clk_period/2; end process; -- Stimulus process stim_proc: process begin -- hold reset state for 100 ns. reset <= '1'; wait for 100 ns; reset <= '0'; binary_in <= "0000000000001111"; wait for 200 ns; binary_in <= "0000000001001111"; wait for 200 ns; binary_in <= "0000000001111111"; wait for 200 ns; binary_in <= "0000111101001111"; wait for 2000 ns; end process; END;