Advertisement
Guest User

miau

a guest
May 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 05/04/2019 08:57:33 PM
  6. -- Design Name:
  7. -- Module Name: main - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool Versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20.  
  21.  
  22. library IEEE;
  23. use IEEE.STD_LOGIC_1164.ALL;
  24. use work.all;
  25.  
  26. -- Uncomment the following library declaration if using
  27. -- arithmetic functions with Signed or Unsigned values
  28. --use IEEE.NUMERIC_STD.ALL;
  29.  
  30. -- Uncomment the following library declaration if instantiating
  31. -- any Xilinx leaf cells in this code.
  32. --library UNISIM;
  33. --use UNISIM.VComponents.all;
  34.  
  35. entity main is
  36. Port (
  37. SW : in STD_LOGIC_VECTOR (15 downto 0);
  38. Clk : in STD_LOGIC;
  39. Rst,BTNM,next_number,equals : in STD_LOGIC;
  40. An : out STD_LOGIC_VECTOR (7 downto 0);
  41. Seg : out STD_LOGIC_VECTOR (7 downto 0);
  42. JA : inout STD_LOGIC_VECTOR (7 downto 0)); -- PmodKYPD is designed to be connected to JA
  43. end main;
  44.  
  45. architecture Behavioral of main is
  46. -- pi+0.2 = 4055c28f ; - 403c28f6
  47. signal n1:std_logic_vector(31 downto 0):=x"4048f5c3";
  48. signal n2:std_logic_vector(31 downto 0):=x"3e4ccccd";
  49. signal sgn1,sgn2, zero,sign:std_logic;
  50. signal sgn_entry_1,sgn_entry_2,OANA1,OANA2:std_logic_vector(0 downto 0);
  51. signal exp1,exp2,exp_max,exp_min,dif,final_exp:std_logic_vector(7 downto 0);
  52. signal radix1, radix2:std_logic_vector(22 downto 0);
  53. signal signs:std_logic_vector(1 downto 0);
  54. signal radix_n1, radix_n2, radix_min, radix_max, radix_shifted, radix_entry_1, radix_entry_2,result,shifted_result:std_logic_vector(23 downto 0);
  55. signal ld:std_logic:='1';
  56. signal op:std_logic:='0';
  57. signal shift_exp : STD_LOGIC_VECTOR (9 downto 0);
  58. signal subnormal1,subnormal2, min,out_of_range:std_logic;
  59. signal final_number : std_logic_vector(31 downto 0);
  60. signal dif_10bits: std_logic_vector(9 downto 0);
  61. signal Decode: STD_LOGIC_VECTOR (3 downto 0);
  62. signal overflow:std_logic;
  63. signal btnm_debounced, next_number_debounced, equals_debounced : std_logic;
  64. signal shift_digit : std_logic;
  65. signal Data, fout: STD_LOGIC_VECTOR(31 downto 0);
  66. signal current_digit, show_result: std_logic := '0';
  67. begin
  68.  
  69.  
  70. C0: entity WORK.Decoder port map (clk=>clk, Row =>JA(7 downto 4), Col=>JA(3 downto 0), DecodeOut=> Decode);
  71.  
  72. deb:entity work.debouncer
  73. port map (clk,BTNM,
  74. btnm_debounced
  75. );
  76. deb2:entity work.debouncer
  77. port map (clk,next_number,
  78. next_number_debounced
  79. );
  80. deb3:entity work.debouncer
  81. port map (clk,equals,
  82. equals_debounced
  83. );
  84.  
  85. Conv102: entity InFloat port map ( clk, rst,
  86. btnm_debounced,
  87. Decode,
  88. fout);
  89.  
  90. --process(next_number_debounced, Rst)
  91. --begin
  92. -- if Rst = '1' then
  93. -- current_digit <= '0';
  94. -- elsif next_number_debounced = '1' then
  95. -- if current_digit = '0' then
  96. -- n1 <= fout;
  97. -- else
  98. -- n2 <= fout;
  99. -- end if;
  100. -- current_digit <= not current_digit;
  101. -- end if;
  102. --end process;
  103.  
  104. process(sw,clk)
  105. begin
  106. if (rising_edge(clk)) then
  107. if(sw(1)='1') then n1<=fout;
  108. else n1<=n1;
  109. end if;
  110.  
  111. if(sw(2)='1') then n2<=fout;
  112. else n2<=n2;
  113. end if;
  114. end if;
  115. end process;
  116.  
  117.  
  118. --process(equals_debounced)
  119. --begin
  120. -- if equals_debounced = '1' then
  121. -- show_result <= not show_result;
  122. -- end if;
  123. --end process;
  124. show_result<=sw(3);
  125. op<=sw(0);
  126.  
  127. Number1: entity WORK.numberReg port map(n1,rst,ld,sgn1,exp1,radix1);
  128. Number2: entity WORK.numberReg port map(n2,rst,ld,sgn2,exp2,radix2);
  129.  
  130. Edge1: entity WORK.edge port map(exp1,subnormal1);
  131. Edge2: entity WORK.edge port map(exp2,subnormal2);
  132.  
  133. Comparator_exponenti: entity WORK.comparator_min port map(exp1,exp2,min);
  134.  
  135. Concat_1: entity WORK.concat port map(radix1, subnormal1, radix_n1);
  136. Concat_2: entity WORK.concat port map(radix2, subnormal2, radix_n2);
  137.  
  138. Exponent_maxim: entity WORK.mux_generic generic map(8) port map(exp1,exp2,min,exp_max);
  139. Exponent_minim: entity WORK.mux_generic generic map(8) port map(exp2,exp1,min,exp_min);
  140.  
  141. Diferenta_exp: entity WORK.alu8 port map(exp_max, exp_min, dif);
  142.  
  143. Select_radix_min: entity WORK.mux_generic generic map(24) port map(radix_n2, radix_n1, min, radix_min);
  144. Select_radix_max: entity WORK.mux_generic generic map(24) port map(radix_n1, radix_n2, min, radix_max);
  145.  
  146. dif_10bits <= "00"&dif;
  147. shift_left_min_radix: entity WORK.shift_right_n generic map(24) port map(radix_min,dif_10bits,radix_shifted);
  148.  
  149. select_operands_order1: entity WORK.mux_generic generic map(24) port map(radix_max, radix_shifted, min, radix_entry_1);
  150. select_operands_order2: entity WORK.mux_generic generic map(24) port map(radix_shifted, radix_max, min, radix_entry_2);
  151.  
  152. OANA1(0)<=sgn2;
  153. OANA2(0)<=sgn1;
  154.  
  155.  
  156. select_signs_order1: entity WORK.mux_generic generic map(1) port map(OANA1 , OANA2, min, sgn_entry_1);
  157. select_signs_order2: entity WORK.mux_generic generic map(1) port map( OANA2, OANA1, min, sgn_entry_2);
  158.  
  159. signs<=sgn1 & sgn2;
  160.  
  161. operation: entity WORK.alu port map(radix_entry_1,radix_entry_2,op,signs,zero,sign,result, overflow);
  162.  
  163. normalizare: entity WORK.normalizare port map(result, shift_exp,shifted_result);
  164.  
  165. shift_e: entity WORK.shift_exponent port map(exp_max, shift_exp,out_of_range,final_exp,overflow);
  166.  
  167. final_number<=x"00000000" when zero='1' else sign & final_exp & shifted_result(22 downto 0);
  168.  
  169.  
  170. Data <= final_number when show_result = '1' else fout;
  171.  
  172. displ7seg: entity WORK.displ7seg port map (
  173. Clk => Clk,
  174. Rst => Rst,
  175. Data => Data,
  176. An => An,
  177. Seg => Seg);
  178.  
  179. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement