CPU设计开发时钟模块

这学期开的一门课--《计算机设计与实践》。自主设计CPU,用VHDL语言模拟。今晚开始做,由于长期不写VHDL代码了,就一个时钟模块居然错了这么多,唉。
先附上调试正确的代码吧。
View Code
首先提醒注意的是那个 port的语法格式;其次,if..then...elsif..then,这个语句我犯了一个不太明显的错误,就是我把elsif 写出了else if 结果编译器总是报错“ Line 56. parse error, unexpected PROCESS, expecting IF”。其次,在这条语句之后别忘了加上
end if;
同样的有case语句的使用,也务必在使用结束时加上end case;
这之后,代码算是编译通过了,之后加波形,结果出现这个错误:

当时就傻眼了,代码看了无数遍,波形新建了许多还是不对。后来仔细看了一下错误Expecting a type name, found component "time" instead.
意识到会不会是  time ,也就是实体名称的问题,后来一改,果然好使了。至于为什么time就不行,还是没搞懂。下次注意就好了。
哦哦,明天继续。。
 1 library IEEE;
 2 use IEEE.STD_LOGIC_1164.ALL;
 3 use IEEE.STD_LOGIC_ARITH.ALL;
 4 use IEEE.STD_LOGIC_UNSIGNED.ALL;
 5 
 6 ---- Uncomment the following library declaration if instantiating
 7 ---- any Xilinx primitives in this code.
 8 library UNISIM;
 9 --use UNISIM.VComponents.all;
10 
11 entity clk_time is
12      port(
13          clk : in std_logic;
14          rst : in std_logic;
15          EN  : out std_logic_vector( 3 downto 0 )
16      );
17 end clk_time;
18 
19 architecture Behavioral of clk_time is
20 
21 signal tmp : std_logic_vector(3 downto 0);
22  begin
23      process( clk , rst )
24      begin
25          if( rst = '1' ) then
26              tmp <= "0000";
27          elsif ( clk'event and clk = '1' ) then
28              case tmp is
29                  when "0000" => tmp <= "0001";
30                  when "0001" => tmp <= "0010";
31                  when "0010" => tmp <= "0100";
32                  when "0100" => tmp <= "1000";
33                  when "1000" => tmp <= "0001";
34                  when others => null;
35              end case;
36          end if;
37      end process;
38      en <= tmp;
39 
40 end Behavioral;
原文地址:https://www.cnblogs.com/xubenben/p/2757890.html