Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. library IEEE;
  2.  
  3. use IEEE.std_logic_1164.all;
  4. use IEEE.std_logic_arith.all;
  5.  
  6. entity MPY8 is
  7. port(mpy : in std_logic; --set the clk and the multiply variable to the ones in std_logic
  8. a,b : in std_logic_vector(7 downto 0); -- a and b need to each be 8 bits
  9. rdy: out std_logic; --the output for MUL8 to signify it's finished multiplying
  10. prod: out std_logic_vector(15 downto 0)); --actual 16bit number (result)
  11. end MPY8;
  12.  
  13. architecture Multiply of MPY8 is
  14. type state is (WT, S1, S2, S3, S4, S5, S6, S7);
  15. signal new_state : state; --need this signal to communicate with state transition process and asserted outputs.
  16. signal done : boolean; --when rdy is changed (when finished multiplying) in state transition process, change this and we will check in asserted outputs.
  17. signal clk : std_logic;
  18. signal test1, test2, test3, test4, test5 : boolean;
  19.  
  20. signal M_temp, NegM_temp : std_logic_vector(8 downto 0);
  21. signal P_temp : std_logic_vector(17 downto 0);
  22. begin
  23. --STATE TRANSITION PROCESS
  24. process is --define any local variables after this and before 'begin'
  25. variable curr_state : state := S7;
  26.  
  27.  
  28. begin
  29. if clk = '1' then --positive edge triggered clock
  30. case curr_state is
  31. when WT =>
  32. if mpy='1' then curr_state := S1;
  33. end if;
  34. when S1 =>
  35. if test1 then curr_state:= S6;
  36. elsif test2 then curr_state := S2;
  37. elsif test3 then curr_state := S3;
  38. elsif test4 then curr_state := S4;
  39. elsif test5 then curr_state := S5;
  40. end if;
  41. when S2 =>
  42. curr_state := S6;
  43. when S3 =>
  44. curr_state := S6;
  45. when S4 =>
  46. curr_state := S6;
  47. when S5 =>
  48. curr_state := S6;
  49. when S6 =>
  50. if done = false then curr_state := S1;
  51. elsif done = true then curr_state := S7;
  52. end if;
  53. when S7=>
  54. if mpy = '0' then curr_state := WT;
  55. end if;
  56. end case;
  57. new_state <= curr_state;
  58. end if;
  59. wait on clk;
  60. end process;
  61.  
  62.  
  63.  
  64.  
  65. -- Asserted Outputs process
  66. process is
  67. variable P : std_logic_vector(17 downto 0);
  68. variable M , NegM : std_logic_vector(8 downto 0);
  69. variable I : integer;
  70. variable rdy_val : std_logic;
  71. variable prod_val: std_logic_vector (15 downto 0);
  72. begin
  73. case new_state is
  74. -- assigned output values go here
  75. when WT =>
  76. P(17 downto 9) := "000000000";
  77. P(8 downto 1) := a;
  78. P(0) := '0';
  79. M(7 downto 0) := b;
  80. M(8) := b(7);
  81.  
  82. -- to get NegM
  83. NegM := (not M) + "000000001"; -- this should work
  84. I := 0;
  85. prod_val := "ZZZZZZZZZZZZZZZZ";
  86. rdy_val := '0'; -- I think this might be a mistake. I think ready is supposed to be set to '0' here.
  87.  
  88. --evaluate tests to be used
  89.  
  90. test1 <= ( P(2 downto 0) = "000" ) or ( P(2 downto 0) = "111" );
  91. test2 <= ( P(2 downto 0) = "001" ) or ( P(2 downto 0) = "010" );
  92. test3 <= ( P(2 downto 0) = "011" );
  93. test4 <= ( P(2 downto 0) = "100" );
  94. test5 <= ( P(2 downto 0) = "101" ) or ( P(2 downto 0) = "110" );
  95.  
  96. M_temp <= M;
  97. NegM_temp <= NegM;
  98. when S1 =>
  99. I := I + 1;
  100. done <= not (I < 4);
  101.  
  102. when S2 =>
  103. P(17 downto 9) := P(17 downto 9) & M(8 downto 0);
  104.  
  105. when S3 =>
  106. P(17 downto 9) := P(17 downto 9) & (M(8 downto 0) sll 1);
  107.  
  108. when S4 =>
  109. P(17 downto 9) := P(17 downto 9) & (NegM(8 downto 0) sll 1);
  110.  
  111. when S5 =>
  112. P(17 downto 9) := P(17 downto 9) & NegM(8 downto 0);
  113.  
  114. when S6 =>
  115. P := P sra 2;
  116.  
  117. when S7 =>
  118. prod_val := P(16 downto 1);
  119. rdy_val := '1';
  120.  
  121. end case;
  122.  
  123. prod <= prod_val; -- deliver output values to signal
  124. rdy <= rdy_val;
  125. P_temp <= P;
  126. wait on new_state;
  127. end process;
  128.  
  129. process is
  130. begin
  131. clk <= '0', '1' after 20 ns;
  132. wait for 40 ns;
  133. end process;
  134.  
  135. end Multiply;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement