我将端口信号定义为INOUT
信号。我将端口设置为D锁存器的输出,并且在异常情况下输出未定义。当我没有通过另一个模块运行D锁存器的输出时,一切正常。但是,我需要从d锁存器获取输出信号,并将其用作不同模块的输入。完成此操作后,D锁存器的输出始终未定义。以下是我的代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity top_level is
Port ( a_raw : in STD_LOGIC_VECTOR (3 downto 0);
b_raw : in STD_LOGIC_VECTOR (3 downto 0);
a_latched : inout STD_LOGIC_VECTOR (3 downto 0);
b_latched : inout STD_LOGIC_VECTOR (3 downto 0);
reset : in STD_LOGIC;
load : in STD_LOGIC;
s : in STD_LOGIC_VECTOR (3 downto 0);
out0 : inout STD_LOGIC_VECTOR (3 downto 0);
out1 : inout STD_LOGIC_VECTOR (3 downto 0);
out2 : inout STD_LOGIC_VECTOR (3 downto 0);
out3 : inout STD_LOGIC_VECTOR (3 downto 0);
out4 : inout STD_LOGIC_VECTOR (3 downto 0);
out5 : inout STD_LOGIC_VECTOR (3 downto 0);
flag : inout STD_LOGIC_VECTOR (4 downto 0);
result : inout STD_LOGIC_VECTOR (3 downto 0));
signal numone : STD_LOGIC_VECTOR (3 downto 0) := "0001";
signal test : STD_LOGIC_VECTOR (3 downto 0) := a_latched;
end top_level;
architecture Structure of top_level is
component fulladdsub
Port (
x : inout STD_LOGIC_VECTOR (3 downto 0);
y : inout STD_LOGIC_VECTOR (3 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR (3 downto 0));
end component;
component D_Latch
Port (
D : in STD_LOGIC_VECTOR (3 downto 0);
EN : in STD_LOGIC;
Q : inout STD_LOGIC_VECTOR (3 downto 0));
end component;
begin
stage0: D_Latch port map(D=>a_raw, EN=>load, Q=>a_latched); -- allows load to stop A,B from changing
stage1: D_Latch port map(D=>b_raw, EN=>load, Q=>b_latched);
--stage2: fulladdsub port map(x=>a_latched, y=>b_latched, cin=>'0', sum=>out0); -- A+B
--stage3: fulladdsub port map(x=>a_latched, y=>b_latched, cin=>'1', sum=>out1); -- A-B
stage2: fulladdsub port map(x=>a_latched, y=>numone, cin=>'0', sum=>out2); -- A+1
--stage5: fulladdsub port map(x=>a_latched, y=>numone, cin=>'1', sum=>out3); -- A-1
--stage6: fulladdsub port map(x=>b_latched, y=>numone, cin=>'0', sum=>out4); -- B+1
--stage7: fulladdsub port map(x=>b_latched, y=>numone, cin=>'1', sum=>out5); -- B-1
end Structure;
b_latched
和a_latched
是此处讨论的端口。当我按原样模拟我的代码时,a_latched
总是未定义的(它在stage2中使用),并且b_latched
在它应该被定义时定义。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
当您使用inout时,当您尝试将其用作输入时,您的架构需要明确地将其驱动到'Z'
。同样,包含的体系结构(通常只是一个用于inouts的测试平台)需要在想要读取输出时将其驱动程序设置为'Z'
。
我无法准确确定您的问题是什么,因为您的问题中没有足够的细节;它缺少D_Latch
的实现,无论“另一个模块”是否存在问题。
另外请记住,如果这是针对FPGA目标的,则只应将inout
用于连接到FPGA引脚的顶级端口。这通常是FPGA中唯一具有三态缓冲区的部分(inout
代表硬件)。
如果D_Latch
实际上被写为锁存器,那么如果你从未断言EN
,则输出将是未定义的,因为这就是锁存器应该做的事情。