Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.numeric_std.all;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5.  
  6. entity sorter is
  7. Port( clk : in STD_LOGIC;
  8. weight : in STD_LOGIC_VECTOR(11 downto 0);
  9. reset : in STD_LOGIC;
  10. Grp1 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
  11. Grp2 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
  12. Grp3 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
  13. Grp4 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
  14. Grp5 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
  15. Grp6 : out STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
  16. currentGrp : out STD_LOGIC_VECTOR(2 downto 0));
  17. end sorter;
  18.  
  19. architecture Behavioral of sorter is
  20.  
  21. signal temp1 : unsigned(7 downto 0) := "00000000";
  22. signal temp2 : unsigned(7 downto 0) := "00000000";
  23. signal temp3 : unsigned(7 downto 0) := "00000000";
  24. signal temp4 : unsigned(7 downto 0) := "00000000";
  25. signal temp5 : unsigned(7 downto 0) := "00000000";
  26. signal temp6 : unsigned(7 downto 0) := "00000000";
  27.  
  28.  
  29. begin
  30.  
  31. process(clk, weight, reset)
  32. begin
  33. if reset = '1' then
  34. Grp1 <= "00000000";
  35. Grp2 <= "00000000";
  36. Grp3 <= "00000000";
  37. Grp4 <= "00000000";
  38. Grp5 <= "00000000";
  39. Grp6 <= "00000000";
  40. temp1 <= "00000000";
  41. temp2 <= "00000000";
  42. temp3 <= "00000000";
  43. temp4 <= "00000000";
  44. temp5 <= "00000000";
  45. temp6 <= "00000000";
  46. currentGrp <= "000";
  47. else
  48. if rising_edge(clk) then
  49. if weight = "000000000000" then
  50. currentGrp <= "000";
  51. elsif(weight >= "000000000001" and weight <= "000011001000") then
  52. temp1 <= temp1 + '1';
  53. Grp1 <= STD_LOGIC_VECTOR(temp1);
  54. currentGrp <= "001";
  55. elsif(weight >= "000011001001" and weight <= "000111110100") then
  56. temp2 <= temp2 + 1;
  57. Grp2 <= STD_LOGIC_VECTOR(temp2);
  58. currentGrp <= "010";
  59. elsif(weight >= "000111110101" and weight <= "001100100000") then
  60. temp3 <= temp3 + 1;
  61. Grp3 <= STD_LOGIC_VECTOR(temp3);
  62. currentGrp <= "011";
  63. elsif(weight >= "001100100001" and weight <= "001111101000") then
  64. temp4 <= temp4 + 1;
  65. Grp4 <= STD_LOGIC_VECTOR(temp4);
  66. currentGrp <= "100";
  67. elsif(weight >= "001111101001" and weight <= "011111010000") then
  68. temp5 <= temp5 + 1;
  69. Grp5 <= STD_LOGIC_VECTOR(temp5);
  70. currentGrp <= "101";
  71. elsif weight > "011111010000" then
  72. temp6 <= temp6 + 1;
  73. Grp6 <= STD_LOGIC_VECTOR(temp6);
  74. currentGrp <= "110";
  75. end if;
  76. end if;
  77. end if;
  78.  
  79. end process;
  80. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement