Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.std_logic_1164.all;
- use IEEE.numeric_std.all;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- entity sorter is
- Port( clk : in STD_LOGIC;
- weight : in STD_LOGIC_VECTOR(11 downto 0);
- reset : in STD_LOGIC;
- Grp1 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
- Grp2 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
- Grp3 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
- Grp4 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
- Grp5 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
- Grp6 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
- currentGrp : out STD_LOGIC_VECTOR(2 downto 0));
- end sorter;
- architecture Behavioral of sorter is
- signal temp1 : unsigned(7 downto 0) := "00000000";
- signal temp2 : unsigned(7 downto 0) := "00000000";
- signal temp3 : unsigned(7 downto 0) := "00000000";
- signal temp4 : unsigned(7 downto 0) := "00000000";
- signal temp5 : unsigned(7 downto 0) := "00000000";
- signal temp6 : unsigned(7 downto 0) := "00000000";
- begin
- process(clk, weight, reset)
- begin
- if reset = '1' then
- Grp1 <= "00000000";
- Grp2 <= "00000000";
- Grp3 <= "00000000";
- Grp4 <= "00000000";
- Grp5 <= "00000000";
- Grp6 <= "00000000";
- temp1 <= "00000000";
- temp2 <= "00000000";
- temp3 <= "00000000";
- temp4 <= "00000000";
- temp5 <= "00000000";
- temp6 <= "00000000";
- currentGrp <= "000";
- else
- if rising_edge(clk) then
- if weight = "000000000000" then
- currentGrp <= "000";
- elsif(weight >= "000000000001" and weight <= "000011001000") then
- temp1 <= temp1 + '1';
- Grp1 <= STD_LOGIC_VECTOR(temp1);
- currentGrp <= "001";
- elsif(weight >= "000011001001" and weight <= "000111110100") then
- temp2 <= temp2 + 1;
- Grp2 <= STD_LOGIC_VECTOR(temp2);
- currentGrp <= "010";
- elsif(weight >= "000111110101" and weight <= "001100100000") then
- temp3 <= temp3 + 1;
- Grp3 <= STD_LOGIC_VECTOR(temp3);
- currentGrp <= "011";
- elsif(weight >= "001100100001" and weight <= "001111101000") then
- temp4 <= temp4 + 1;
- Grp4 <= STD_LOGIC_VECTOR(temp4);
- currentGrp <= "100";
- elsif(weight >= "001111101001" and weight <= "011111010000") then
- temp5 <= temp5 + 1;
- Grp5 <= STD_LOGIC_VECTOR(temp5);
- currentGrp <= "101";
- elsif weight > "011111010000" then
- temp6 <= temp6 + 1;
- Grp6 <= STD_LOGIC_VECTOR(temp6);
- currentGrp <= "110";
- end if;
- end if;
- end if;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement