我目前正处于一个项目中,我正在尝试设计一个单循环cpu . 我这样做没有任何管道衬里,因为这会大大增加设计的复杂性 . 我学习这个时,我只是采取了婴儿步骤 . 我发现自己陷入了这个部分,我只是试图使用以前制作的组件编写程序计数器(PC) .
我的设计模型看起来像这样picture here . 对不起,不知道为什么它会变暗,但如果点击它就会显示正确 . PC和GPU都是32位组件,所以我假设加法器也是如此 .
这是我给出的代码,我的实现从第41行的begin语句开始 . 现在不要理会它,它只是我尝试的一堆随机乱码 .
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
---------------------------------------------------
entity pc_update is
port( clk: in std_logic; -- clock
incH_ldL: in std_logic; -- increment PC = PC + 4 when high,
-- load PCInput when low
PCInput: in std_logic_vector(31 downto 0); -- external input for PC
InstrAddr: out std_logic_vector(31 downto 0) ); -- instruction address
end entity pc_update;
----------------------------------------------------
architecture pc_update_arch of pc_update is
component register32 is
port( clr: in std_logic; -- async. clear
clk: in std_logic; -- clock
ld: in std_logic; -- load
D: in std_logic_vector(31 downto 0); -- data input
Q: out std_logic_vector(31 downto 0) ); -- data output
end component register32;
component mux2to1_32 is
port( sel: in std_logic; -- selection bit input
X0: in std_logic_vector(31 downto 0); -- first input
X1: in std_logic_vector(31 downto 0); -- second input
Y: out std_logic_vector(31 downto 0)); -- output
end component mux2to1_32;
signal PC_current: std_logic_vector(31 downto 0); -- the current state of PC reg
signal PC_add_4: std_logic_vector(31 downto 0); -- output from the adder
signal PC_next: std_logic_vector(31 downto 0); -- output from the MUX
begin
PC: register32 Port Map(
clk, Q, clr, D);
MUX: mux2to1_32 Port Map(
X0,sel,X1,Y);
process (incH_ldL)
begin
wait until (clk = '1');
if incH_1dL = '0' then
InstrAddr <= X0;
else InstrAddr <= X1;
end if;
end process;
end architecture pc_update_arch;
我对此很新,所以我对信号如何工作只有一个微弱的想法,并且不知道我应该如何将组件实现到设计中 . 我也很困惑,我没有被要求提前 Build 加法器 . 现在是否有必要将其用作猜测的组件?
无论如何,我尝试了不同的东西,偶然发现了搜索,比如你看到的端口映射 . 但我总是遇到某种错误,目前接收的错误是使用了对象Q,clr和D但未声明 . 我如何申报?如果我摆脱这些陈述,错误只是重复对象X0,X1和Y.任何正确方向的帮助将不胜感激 . 多谢你们!
此外,万一你需要它们,寄存器
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
---------------------------------------------------
entity register32 is port(
clr: in std_logic; -- async. clear
clk: in std_logic; -- clock
ld: in std_logic; -- load
D: in std_logic_vector(31 downto 0); -- data input
Q: out std_logic_vector(31 downto 0) ); -- data output
end entity register32;
----------------------------------------------------
architecture register32_arch of register32 is
begin
process(clk, clr)
begin
if clr = '1' then
q <= x"00000000";
elsif rising_edge(clk) then
if ld = '1' then
q <= d;
end if;
end if;
end process;
END register32_arch;
和MUX
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
---------------------------------------------------
entity mux2to1_32 is
port( sel: in std_logic; -- selection bit input
X0: in std_logic_vector(31 downto 0); -- first input
X1: in std_logic_vector(31 downto 0); -- second input
Y: out std_logic_vector(31 downto 0)); -- output
end entity mux2to1_32;
----------------------------------------------------
architecture mux2to1_32_arch of mux2to1_32 is
begin
Y <= X1 when (SEL = '1') else X0;
end architecture mux2to1_32_arch;
EDIT 好的,不知道我是否正确地做了这个,但我重写了这个端口图 . 我有错误的端口名称(sel,clk,X0,X1..etc)被“使用但未初始化 . 所以这就是clr,clk和ld具有初始值的原因 . 再次,不知道这是否正确,但是它让错误消失了 . 我也意识到我从来没有将register32和mux2to1_32 VHDL文件添加到我的项目中,并且在这样做之后摆脱了我遇到的其他错误 .
因此,代码编译时,我已经在项目中包含了用于测试的VWF模拟文件,但我知道结果将是不正确的 .
我不知道所有错误,但我知道我需要用PC_add_4做点什么 . 这个值基本上需要(PC_current 4),但我不知道该怎么做 .
这是更新的代码部分(其他一切都是相同的)
PC: register32 Port Map(
clr => '0',
clk => '0',
ld => '1',
Q => PC_current,
D => PC_next
);
MUX: mux2to1_32 Port Map(
sel => incH_ldL,
X0 => PCInput ,
X1 => PC_add_4,
Y => PC_next
);
process (incH_ldL)
begin
if (rising_edge(clk)) then
if incH_ldL = '0' then
InstrAddr <= PC_current;
else InstrAddr <= PC_add_4;
end if;
end if;
end process;
并且,如果他们帮助,我的错误列表..我猜测引脚相关的错误是因为我还没有任何硬件分配 .
-
警告(10541):pc_update.vhd上的VHDL信号声明警告(38):使用信号“PC_add_4”的隐式默认值,因为从未为信号分配值或显式默认值 . 使用隐式默认值可能会引入意外的设计优化 .
-
警告(10492):pc_update.vhd(61)处的VHDL过程语句警告:在过程语句中读取信号“clk”但不在过程语句的灵敏度列表中
-
警告:输出引脚卡在VCC或GND
-
警告:设计包含34个不驱动逻辑的输入引脚
-
警告:找到32个输出引脚,没有输出引脚负载电容分配
-
警告:尚未指定“保留所有未使用的引脚”设置,并且默认为“作为输出驱动接地” .
-
警告:无法生成编程文件,因为您当前正在评估模式下使用Quartus II软件
-
警告:没有找到时序分析的路径
-
严重警告:66个总针脚的66个针脚没有确切的针脚位置分配
SECOND EDIT 所以是的,我通过添加PC_add_4 <=(PC_current 4)来修复我的代码;在端口映射之后,将"clk"添加到进程敏感性列表中 . 然而,我相信我的模拟中的波形仍然是错误的,如图所示here .
它似乎将incH_lDL视为一个明确的信号,而不是简单地将PCInput传递给InstrAddr . 这很可能是由于我在端口映射中将其设置为默认值“0” . 我之前做过这个,因为它给了我“使用但未声明”的错误 . 我会尝试弄乱它并发布我的发现 .
Third EDIT
我已经编辑了我的代码:
process (incH_ldL, clk)
begin
if rising_edge(clk) then
if (incH_ldL = '0') then
InstrAddr <= PCInput ;
else InstrAddr <= PC_add_4;
end if;
end if;
end process;
我的模拟现在显示当incH_lDL = 0时,PCInput被加载到InstrAddr中,但是,当incH_lDL = 1时,它只是加载值'4',并且在每个时钟周期的开始都没有增加,就像它应该...需要使用PC_current,但我不确定如何....你不能将一个信号分配给另一个信号,如“PC_current <= PCInput” . 我将尝试更多的东西,同时,任何指针将不胜感激 .
FOURTH EDIT 感谢所有人都在读这篇文章,并通过所有的阅读 .
我试图在我的实现中使用PC_next和PC_current,但是遇到了“多个常量驱动程序,用于网络”PC_next“错误 .
我的流程代码:
process (incH_ldL, clk, PC_next, PC_current)
begin
if rising_edge(clk) then
if (incH_ldL = '0') then
PC_next <= PCInput;
else PC_next <= PC_add_4;
end if;
end if;
InstrAddr <= PC_current;
end process;
我知道这个错误这些作业是在循环中进行的吗?我真的不知道接下来会尝试什么 .
1 回答
您在第一个代码中的端口映射需要移植到信号 . 您将组件的端口名称放在端口映射中,这是不正确的 . 您想要做的是创建可以连接这些组件的信号,并将它们放在端口映射字段中(以匹配图像中的连接) .