Guest User

Untitled

a guest
Jul 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. entity control is
  2. Port ( CLR : in std_logic;
  3. CLK : in std_logic;
  4. MX : out std_logic_vector(2 downto 0);
  5. CTRL : out std_logic;
  6. LDA, LDB, LDACC : out std_logic);
  7. end control;
  8.  
  9.  
  10. architecture Behavioral of control is
  11. type state_type is (LDRA,LDRB,ADDA,SUBB,ADDB,INC,CLEAR);
  12. attribute ENUM_ENCODING: STRING;
  13. -- attribute ENUM_ENCODING of state_type: type is "100000 010000 001000 000100 000010 000001";
  14. signal PS,NS : state_type;
  15.  
  16. begin
  17.  
  18. sync_proc: process (CLK,CLR,NS)
  19. begin
  20. if (CLR = '1') then PS <= CLEAR; --the program is reset/stopped
  21. elsif (rising_edge(CLK)) then PS <= NS;
  22. end if;
  23. end process sync_proc;
  24.  
  25. comb_proc: process (PS)
  26. begin
  27. case (PS) is
  28. when LDRA => --register a is loaded
  29. LDA <= '1';
  30. LDB <= '0';
  31. LDACC <= '0';
  32. MX <= "000";
  33. CTRL <= '0';
  34. NS <= LDRB;
  35. when LDRB => --register b is loaded
  36. LDA <= '0';
  37. LDB <= '1';
  38. LDACC <= '0';
  39. MX <= "000";
  40. CTRL <= '0';
  41. NS <= ADDA;
  42. when ADDA => --mux chosen to add A to the value in acc
  43. LDA <= '0';
  44. LDB <= '0';
  45. LDACC <= '1';
  46. MX <= "000";
  47. CTRL <= '0';
  48. NS <= SUBB;
  49. when SUBB => --mux chosen to subtract B to the value in acc
  50. LDA <= '0';
  51. LDB <= '0';
  52. LDACC <= '1';
  53. MX <= "011"; --not B
  54. CTRL <= '1';
  55. NS <= INC;
  56. when INC => --the value mux has chosen is zeros. incrementing by 1
  57. LDA <= '0';
  58. LDB <= '0';
  59. LDACC <= '1';
  60. MX <= "100";
  61. CTRL <= '1';
  62. NS <= ADDB;
  63. when ADDB => --mux chosen to add B to the value in acc
  64. LDA <= '0';
  65. LDB <= '0';
  66. LDACC <= '1';
  67. MX <= "001";
  68. CTRL <= '0';
  69. NS <= LDRA;
  70. when CLEAR =>
  71. LDA <= '0';
  72. LDB <= '0';
  73. LDACC <= '0';
  74. MX <= "000";
  75. NS <= LDRA;
  76. when others => -- the just in case case...
  77. LDA <= '0';
  78. LDB <= '0';
  79. LDACC <= '0';
  80. MX <= "000";
  81. CTRL <= '0';
  82. NS <= LDRA;
  83. end case;
  84. end process comb_proc;
  85. end Behavioral;
Add Comment
Please, Sign In to add comment