Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. -------------------------------------------------------------------------------
  5. entity top is
  6. port(
  7. clk_50MHz : in std_logic;
  8. res_o : out std_logic_vector(31 downto 0)
  9. );
  10. end entity top;
  11. -------------------------------------------------------------------------------
  12. architecture top_arch of top is
  13. constant LFSR_LENGTH : positive := (res_o'length - 2) / 2;
  14.  
  15. ----------------------------------------------------------------------------
  16. signal clk_170MHz : std_logic;
  17. signal new_operands : std_logic;
  18.  
  19. -- signals for arithmetic operation
  20. signal a : std_logic_vector(LFSR_LENGTH - 1 downto 0);
  21. signal b : std_logic_vector(LFSR_LENGTH - 1 downto 0);
  22. signal c : std_logic_vector(LFSR_LENGTH - 1 downto 0);
  23. signal d : std_logic_vector(LFSR_LENGTH - 1 downto 0);
  24.  
  25. signal ua : unsigned(LFSR_LENGTH - 1 downto 0);
  26. signal ub : unsigned(LFSR_LENGTH - 1 downto 0);
  27. signal uc : unsigned(LFSR_LENGTH - 1 downto 0);
  28. signal ud : unsigned(LFSR_LENGTH - 1 downto 0);
  29.  
  30.  
  31. -- results
  32. signal result_d : unsigned(res_o'range) := (others => '0');
  33. signal result : unsigned(res_o'range) := (others => '0');
  34.  
  35. signal res1 : unsigned(result_d'length - 3 downto 0) := (others => '0');
  36. signal res2 : unsigned(result_d'length - 3 downto 0) := (others => '0');
  37. signal res3 : unsigned(result_d'length - 3 downto 0) := (others => '0');
  38. signal res4 : unsigned(result_d'length - 3 downto 0) := (others => '0');
  39. signal subres1 : unsigned(result_d'length - 3 downto 0) := (others => '0');
  40. signal subres2 : unsigned(result_d'length - 3 downto 0) := (others => '0');
  41.  
  42.  
  43. ----------------------------------------------------------------------------
  44.  
  45. component clk_gen
  46. port(
  47. clk_170 : out std_logic;
  48. clk_50 : in std_logic
  49. );
  50. end component;
  51.  
  52. ----------------------------------------------------------------------------
  53. begin
  54. ----------------------------------------------------------------------------
  55.  
  56. clk_gen_inst : clk_gen
  57. port map(
  58. clk_170 => clk_170MHz,
  59. clk_50 => clk_50MHz
  60. );
  61.  
  62. new_operands_gen : entity work.ce_gen
  63. generic map(
  64. DIV_FACT => 8
  65. )
  66. port map(
  67. clk => clk_170MHz,
  68. srst => '0',
  69. ce => '1',
  70. ce_o => new_operands
  71. );
  72.  
  73. ----------------------------------------------------------------------------
  74. -- random generators
  75.  
  76. gen_A : entity work.lfsr_gen
  77. generic map(
  78. LFSR_LENGTH => LFSR_LENGTH,
  79. SEED => 1
  80. )
  81. port map(
  82. clk => clk_170MHz,
  83. ena_i => new_operands,
  84. dout_o => a
  85. );
  86.  
  87. gen_B : entity work.lfsr_gen
  88. generic map(
  89. LFSR_LENGTH => LFSR_LENGTH,
  90. SEED => 2
  91. )
  92. port map(
  93. clk => clk_170MHz,
  94. ena_i => new_operands,
  95. dout_o => b
  96. );
  97.  
  98. gen_C : entity work.lfsr_gen
  99. generic map(
  100. LFSR_LENGTH => LFSR_LENGTH,
  101. SEED => 3
  102. )
  103. port map(
  104. clk => clk_170MHz,
  105. ena_i => new_operands,
  106. dout_o => c
  107. );
  108.  
  109. gen_D : entity work.lfsr_gen
  110. generic map(
  111. LFSR_LENGTH => LFSR_LENGTH,
  112. SEED => 5
  113. )
  114. port map(
  115. clk => clk_170MHz,
  116. ena_i => new_operands,
  117. dout_o => d
  118. );
  119.  
  120. ----------------------------------------------------------------------------
  121. -- result output register
  122. calc_register : process(clk_170MHz) is
  123. begin
  124. if rising_edge(clk_170MHz) then
  125. result <= result_d;
  126. end if;
  127. end process calc_register;
  128.  
  129. res_o <= std_logic_vector(result);
  130.  
  131. --------------------------- MODIFY FOLLOWING -------------------------------
  132.  
  133. -- result=(a*b)+(c*d)+(a*c)+(b*d)
  134. s_res : process(clk_170MHz) is
  135.  
  136. begin
  137. if rising_edge(clk_170MHz) then
  138.  
  139. ua<= unsigned(a);
  140. ub<= unsigned(b);
  141. uc<= unsigned(c);
  142. ud<= unsigned(d);
  143.  
  144. res1 <= ua*ub;
  145. res2 <= uc*ud;
  146. res3 <= ua*uc;
  147. res4 <= ub*ud;
  148.  
  149. subres1 <= res1+res2;
  150. subres2 <= res3+res4;
  151.  
  152. end if;
  153. result_d <= to_unsigned(0, result_d'length)+ subres1;
  154. result_d <= to_unsigned(0, result_d'length) + subres2;
  155. end process s_res;
  156.  
  157. ----------------------------------------------------------------------------
  158.  
  159. end architecture top_arch;
  160. -------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement