Advertisement
Guest User

DD lab 5

a guest
Oct 16th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  4.  
  5. entity sv_seg is
  6. port (bcd : in std_logic_vector(3 downto 0); --BCD input
  7. segment7 : out std_logic_vector(6 downto 0)); -- 7 bit decoded output.;
  8. end sv_seg;
  9.  
  10. architecture behavior of sv_seg is
  11. BEGIN
  12. segment7 <= "1000000" when bcd = "0000" else
  13. "1111001" when bcd = "0001" else
  14. "0100100" when bcd = "0010" else
  15. "0110000" when bcd = "0011" else
  16. "0011001" when bcd = "0100" else
  17. "0010010" when bcd = "0101" else
  18. "0000010" when bcd = "0110" else
  19. "1111000" when bcd = "0111" else
  20. "0000000" when bcd = "1000" else
  21. "0010000" when bcd = "1001" else
  22. "-------";
  23. end behavior;
  24.  
  25.  
  26.  
  27.  
  28. library IEEE;
  29. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  30. use IEEE.STD_LOGIC_1164.ALL;
  31.  
  32.  
  33. entity sorter is
  34. port( clk,sort,reset : in std_logic ;
  35. weight : in std_logic_vector(9 downto 0);
  36. grp1, grp2, grp3, grp4 : buffer std_logic_vector(3 downto 0);
  37. seg1, seg2, seg3, seg4 : out std_logic_vector (6 downto 0);
  38. cur_grp : out std_logic_vector ( 2 downto 0));
  39. end sorter;
  40.  
  41.  
  42. Architecture ps_behavior of sorter is
  43.  
  44. signal l_sort : std_logic :='1';
  45. component sv_seg
  46. port( bcd : in std_logic_vector (3 downto 0);
  47. segment7: out std_logic_vector (6 downto 0));
  48. end component;
  49.  
  50. Begin
  51.  
  52. s7a: sv_seg port map (grp1,seg1);
  53. s7b: sv_seg port map (grp2,seg2);
  54. s7c: sv_seg port map (grp3,seg3);
  55. s7d: sv_seg port map (grp4,seg4);
  56.  
  57. process(clk, sort, reset)
  58. begin
  59.  
  60. if (reset = '0') then
  61. grp1 <= (others => '0' );
  62. grp2 <= (others => '0' );
  63. grp3 <= (others => '0' );
  64. grp4 <= (others => '0' );
  65. cur_grp <= (others => '0');
  66. elsif (clk'event and clk = '1') then
  67. if (sort = '1' and l_sort = '0') then
  68. if (weight > 800) then
  69. grp4 <= 1 + grp4;
  70. cur_grp <= "100";
  71. elsif (weight > 500) then
  72. grp3 <= 1 + grp3;
  73. cur_grp <= "011";
  74. elsif (weight > 200) then
  75. grp2 <= 1 + grp2;
  76. cur_grp <= "010";
  77. elsif (weight > 0) then
  78. grp1 <= 1 + grp1;
  79. cur_grp <= "001";
  80. else cur_grp <= (others => '0');
  81. end if;
  82. end if;
  83. l_sort <= sort;
  84. end if;
  85. end process;
  86. end ps_behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement