Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_arith.all;
  4.  
  5. entity CTL is
  6. port(
  7. mpy : in std_logic; -- input port declarations
  8. a, b : in std_logic_vector(7 downto 0);
  9. prod : out std_logic_vector(15 downto 0);
  10. rdy: out std_logic);
  11.  
  12. end CTL;
  13.  
  14. architecture behav of CTL is
  15. type state is (WT, S1, S2, S3, S4, S5, S6, S7); -- state type declaration
  16. signal new_state : state; -- new state signal variable
  17.  
  18. signal P: std_logic_vector(17 downto 0);
  19. signal done: boolean;
  20. signal clk: std_logic;
  21. begin
  22. process is
  23. begin
  24. clk<='0','1' after 20 ns;
  25. wait for 40 ns;
  26. end process;
  27. -- state transition process:
  28. process is
  29.  
  30. variable curr_state: state := S7;
  31.  
  32. begin
  33. if clk = '1' then
  34. case curr_state is
  35. -- state transition statements go here.
  36. when WT =>
  37. if mpy = '1' then curr_state := S1;
  38. end if;
  39. when S1 =>
  40. if P(2 downto 0)="000" or P(2 downto 0)="111" then curr_state := S6;
  41. elsif P(2 downto 0)="001" or P(2 downto 0)="010" then curr_state := S2;
  42. elsif P(2 downto 0)="011" then curr_state := S3;
  43. elsif P(2 downto 0)="100" then curr_state := S4;
  44. elsif P(2 downto 0)="101" or P(2 downto 0)="110" then curr_state := S5;
  45. end if;
  46. when S2 =>
  47. curr_state := S6;
  48. when S3 =>
  49. curr_state := S6;
  50. when S4 =>
  51. curr_state := S6;
  52. when S5 =>
  53. curr_state := S6;
  54. when S6 =>
  55. if done = true then curr_state := S7;
  56. elsif done = false then curr_state:=S1;
  57. end if;
  58. when S7 =>
  59. if mpy = '0' then curr_state := WT;
  60. end if;
  61. end case;
  62.  
  63.  
  64. end if;
  65.  
  66. new_state <= curr_state;
  67. wait on clk;
  68. end process;
  69.  
  70. -- asserted outputs process:
  71. process is
  72. variable P_val: std_logic_vector(17 downto 0);
  73. variable prod_val: std_logic_vector(15 downto 0);
  74. variable I: std_logic_vector(1 downto 0);
  75. variable rdy_val : std_logic;
  76. variable done_val : boolean;
  77. variable M, NegM: std_logic_vector (8 downto 0);
  78. begin
  79. case new_state is
  80. -- assigned output values go here.
  81. when WT =>
  82. P_val(17 downto 9) := "000000000";
  83. P_val(8 downto 1) := a;
  84. P_val(0) := '0';
  85. M(8 downto 0) := ('0'&b);
  86. NegM := not(M)+'1';
  87. I := "00";
  88. prod_val := "ZZZZZZZZZZZZZZZZ";
  89. rdy_val := '1';
  90. when S1 =>
  91. done_val := I="11";
  92. I := I + '1';
  93.  
  94. when S2 =>
  95. P_val(17 downto 9) := P_val(17 downto 9) + M(8 downto 0);
  96. when S3 =>
  97. P_val(17 downto 9) := P_val(17 downto 9) + (M(8 downto 0) sll 1);
  98. when S4 =>
  99. P_val(17 downto 9) := P_val(17 downto 9) + (NegM(8 downto 0) sll 1);
  100. when S5 =>
  101. P_val(17 downto 9) := P_val(17 downto 9) + NegM(8 downto 0);
  102. when S6 =>
  103. P_val:= (P sra 2);
  104. when S7 =>
  105. prod_val := P_val(16 downto 1);
  106. rdy_val := '1';
  107.  
  108.  
  109. end case;
  110. P<=P_val;
  111. prod<=prod_val;
  112. rdy<=rdy_val;
  113. done<=done_val;
  114. wait on new_state; -- sensitivity list to restart process
  115. end process;
  116. end behav;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement