Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1.  
  2. FSM;-------------------------------------------------------------
  3.  
  4. library ieee;
  5. use ieee.std_logic_1164.all;
  6. use ieee.numeric_std.all;
  7.  
  8. ENTITY fsm IS
  9. port ( reset: in std_logic;
  10. clk: in std_logic;
  11. w, c, r: in std_logic;
  12. enable: out std_logic_vector(0 to 1);
  13. licz, drive, creset: out std_logic);
  14. END ENTITY fsm;
  15.  
  16. --
  17. ARCHITECTURE z12 OF fsm IS
  18.  
  19. type stany is (idle, read, write1, write2, compare);
  20. signal state, next_state : stany;
  21. signal req: std_logic_vector(2 downto 0);
  22.  
  23. BEGIN
  24.  
  25. synchrP: process (clk, reset)
  26. begin
  27. if reset='0' then
  28. state <= idle;
  29. elsif (rising_edge(clk)) then
  30. state<= next_state;
  31. end if;
  32. end process;
  33.  
  34. req <= w&c&r;
  35.  
  36. kombP: process(state, req)
  37. begin
  38.  
  39. case state is
  40. when idle =>
  41. if (req="100") then
  42. next_state <= write1; enable <= "10"; licz<='0';
  43. elsif (req="010") then
  44. next_state <= compare; enable<="00"; licz<='1';
  45. elsif (req="001") then
  46. next_state <= read; enable<="00"; licz<='0';
  47. else
  48. next_state <= idle; enable<="00"; licz<='0';
  49. end if;
  50. drive <= '0'; creset <='0';
  51.  
  52. when read =>
  53. if(req = "001") then
  54. next_state <= read;
  55. licz <= '0';
  56. drive <= '1';
  57.  
  58.  
  59. elsif(req = "100") then
  60. next_state <= write1;
  61. drive <= '0';
  62. licz <= '0';
  63.  
  64. elsif(req = "010") then
  65. next_state <= compare;
  66. licz <='1';
  67. drive <= '0';
  68.  
  69.  
  70. end if;
  71.  
  72. enable <="00";
  73.  
  74. creset<='0';
  75.  
  76.  
  77.  
  78. ------------------------------------------------------------
  79.  
  80. when write1 =>
  81. next_state <= write2;
  82. enable<="01";
  83. licz<='0';
  84. drive<='0';
  85. creset <='1';
  86.  
  87.  
  88. ------------------------------------------------------------
  89. when write2 =>
  90. if(req = "100") then
  91. next_state <= write1;
  92. enable <= "10";
  93. licz <='0';
  94.  
  95. elsif(req = "010") then
  96. next_state <= compare;
  97. enable <= "00";
  98. licz <='1';
  99.  
  100. elsif(req = "001") then
  101. next_state <= read;
  102. enable <= "00";
  103. licz <='0';
  104.  
  105.  
  106. else
  107. next_state <= idle;
  108. enable <= "00";
  109. licz <='0';
  110.  
  111. end if;
  112. drive <= '0';
  113. creset <='0';
  114. ---------------------------------------------------------------
  115. when compare =>
  116. if(req = "100") then
  117. next_state <= write1;
  118. licz <= '0';
  119.  
  120. elsif(req = "010") then
  121. next_state <= compare;
  122. licz <='1';
  123.  
  124. elsif(req = "001") then
  125. next_state <= read;
  126. licz <= '0';
  127.  
  128. else
  129. next_state <= idle;
  130. licz<='0';
  131.  
  132. end if;
  133.  
  134. enable <= "00";
  135. drive <= '0';
  136. creset <= '0';
  137.  
  138.  
  139.  
  140. end case;
  141. end process;
  142.  
  143.  
  144. END ARCHITECTURE z12;
  145.  
  146.  
  147.  
  148.  
  149.  
  150. COMPARAGE:-----------------------------------------------------------------
  151.  
  152. library ieee;
  153. use ieee.std_logic_1164.all;
  154. use ieee.numeric_std.all;
  155.  
  156. ENTITY comprange IS
  157. generic (m: integer range 0 to 1024 := 4);
  158. port (reset: in std_logic;
  159. clk : in std_logic;
  160. write, comp, read: in std_logic;
  161. data: inout UNSIGNED (m-1 downto 0));
  162. END ENTITY comprange;
  163.  
  164. --
  165. ARCHITECTURE z12 OF comprange IS
  166.  
  167. component reg
  168. generic (m : integer range 0 to 1024 := 4);
  169. port ( data_in: in UNSIGNED (m-1 downto 0);
  170. reg_out: out UNSIGNED (m-1 downto 0);
  171. clk, enable: in std_logic);
  172. END component;
  173.  
  174. component counter
  175. generic(m: integer range 0 to 1024 := 4);
  176. port(clk, reset: in std_logic;
  177. licz, inc: in std_logic;
  178. count: out UNSIGNED(m-1 downto 0));
  179. END component;
  180.  
  181. component fsm
  182. port (reset: in std_logic;
  183. clk: in std_logic;
  184. w, r, c: in std_logic;
  185. enable: out std_logic_vector(0 to 1);
  186. licz, drive, creset: out std_logic);
  187. END component;
  188.  
  189. component bu3
  190. generic (m : integer :=4);
  191. port ( data_in: in UNSIGNED (m-1 downto 0);
  192. data_out: out UNSIGNED (m-1 downto 0);
  193. drive: in std_logic);
  194. END component;
  195.  
  196. component comp3
  197. port ( data_in: in UNSIGNED (m-1 downto 0);
  198. range1, range2: in UNSIGNED (m-1 downto 0);
  199. inc: out std_logic);
  200. END component;
  201.  
  202.  
  203. signal licz, drive, inc, creset: std_logic;
  204. signal reg1out, reg2out, countout: UNSIGNED(m-1 downto 0);
  205. signal enable: std_logic_vector (0 to 1);
  206.  
  207. BEGIN
  208. --port => sygnal
  209.  
  210. Reg1: reg port map
  211. (
  212. reg_out =>reg1out,
  213. data_in => data,
  214. enable => enable(0),
  215. clk=>clk
  216. );
  217. Reg2: reg port map
  218. (
  219. reg_out =>reg2out,
  220. data_in => data,
  221. enable => enable(1),
  222. clk=>clk
  223. );
  224.  
  225. Buf3s: bu3 port map
  226. (
  227. data_in => countout,
  228. data_out => data,
  229. drive => drive
  230. );
  231.  
  232.  
  233. Control: fsm port map
  234. (
  235. clk => clk,
  236. w => write,
  237. r => read,
  238. c => comp,
  239. enable => enable,
  240. licz => licz,
  241. drive => drive,
  242. reset => reset,
  243. creset => creset
  244. );
  245.  
  246. Count: counter port map
  247. (
  248. clk => clk,
  249. reset => creset,
  250. licz => licz,
  251. inc => inc,
  252. count => countout
  253. );
  254. Compare: comp3 port map
  255. (
  256. data_in => data,
  257. range1 => reg1out,
  258. range2 => reg2out,
  259. inc => inc
  260. );
  261.  
  262. END ARCHITECTURE z12;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement