Vhdl 如何将输出端口连接到输入端口
在顶部模块中,有两个输入,分别为Vhdl 如何将输出端口连接到输入端口,vhdl,Vhdl,在顶部模块中,有两个输入,分别为i1(3向下至0)和i2(3向下至0),这两个输入将降低部件,并从这两个输入再次降低部件。进行一些操作后,我们将从内存单元中获得数据输出(从3到0)。现在我的问题是如何将这个数据连接到i2,以便下次我们只输入一个输入,即i1。i2值将作为先前状态data\u o值,并使用此数据进行迭代 我用VHDL编写了以下代码: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all;
i1(3向下至0)
和i2(3向下至0)
,这两个输入将降低部件,并从这两个输入再次降低部件。进行一些操作后,我们将从内存单元中获得数据输出(从3到0)
。现在我的问题是如何将这个数据连接到i2
,以便下次我们只输入一个输入,即i1
。i2
值将作为先前状态data\u o
值,并使用此数据进行迭代
我用VHDL编写了以下代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity top_Module is
port (
i1 : in std_logic_vector(3 downto 0);
i2 : in std_logic_vector(3 downto 0);
f1 : in std_logic_vector(3 downto 0);
f2 : in std_logic_vector(3 downto 0);
f3 : in std_logic_vector(3 downto 0);
f4 : in std_logic_vector(3 downto 0);
start : in std_logic;
ctrl : in std_logic_vector(3 downto 0);
sel : in std_logic_vector(1 downto 0);
clk : in std_logic;
address : in integer;
rst : in std_logic;
--two main output.
data_o : out std_logic_vector(3 downto 0);
ca : out std_logic;
--fault indication.
d_err : out std_logic;
cid_0 : out std_logic;
cid_1 : out std_logic
);
end top_Module;
architecture error_free of top_Module is
component TMR_Module
port (
i1 : in std_logic_vector(3 downto 0);
i2 : in std_logic_vector(3 downto 0);
f1 : in std_logic_vector(3 downto 0);
f2 : in std_logic_vector(3 downto 0);
f3 : in std_logic_vector(3 downto 0);
start : in std_logic;
ctrl : in std_logic_vector(3 downto 0);
sel : in std_logic_vector(1 downto 0);
clk : in std_logic;
--two main output y and ca;
y : out std_logic_vector(3 downto 0);
ca : out std_logic;
d_err : out std_logic;
cid_0 : out std_logic;
cid_1 : out std_logic);
end component;
type ram_t is array (0 to 255) of std_logic_vector(3 downto 0);
signal z : std_logic_vector(3 downto 0);
signal z1 : std_logic_vector(3 downto 0);
signal ram : ram_t := (others => (others => '0'));
begin
x1 : TMR_Module port map(i1,
i2,
f1,
f2,
f3,
start,
ctrl,
sel,
clk,
z,
ca,
d_err,
cid_0,
cid_1
);
process(Clk)
variable data_i : std_logic_vector(3 downto 0);
variable i :std_logic_vector(3 downto 0);
begin
z1 <= z or f4;
if(rst = '1') then
data_o <= ram(address);
elsif(rising_edge(Clk))then
if(f4 = "0000") then
data_i := z1;
ram(address) <= data_i;
i := ram(address);
else
i := ram(address);
end if;
data_o <= i;
end if;
end process;
end error_free;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.std_logic_arith.all;
实体top_模块为
港口(
i1:标准逻辑向量(3到0);
i2:标准逻辑向量(3到0);
f1:标准逻辑向量(3到0);
f2:在标准逻辑向量中(3到0);
f3:标准逻辑向量(3到0);
f4:标准逻辑向量(3到0);
启动:在标准逻辑中;
ctrl:在标准逻辑向量中(3到0);
sel:标准逻辑向量(1到0);
clk:标准逻辑中;
地址:整数;
rst:标准逻辑中;
--两个主要输出。
数据:输出标准逻辑向量(3到0);
ca:输出标准逻辑;
--故障指示。
d_err:输出标准逻辑;
cid_0:输出标准_逻辑;
cid_1:输出标准_逻辑
);
端头模块;
架构错误(无顶层)模块为
组件TMR_模块
港口(
i1:标准逻辑向量(3到0);
i2:标准逻辑向量(3到0);
f1:标准逻辑向量(3到0);
f2:在标准逻辑向量中(3到0);
f3:标准逻辑向量(3到0);
启动:在标准逻辑中;
ctrl:在标准逻辑向量中(3到0);
sel:标准逻辑向量(1到0);
clk:标准逻辑中;
--两个主输出y和ca;
y:输出标准逻辑向量(3到0);
ca:输出标准逻辑;
d_err:输出标准逻辑;
cid_0:输出标准_逻辑;
cid_1:输出标准_逻辑);
端部元件;
类型ram是标准逻辑向量(3到0)的数组(0到255);
信号z:std_逻辑_向量(3到0);
信号z1:std_逻辑_向量(3到0);
信号ram:ram_t:=(其他=>(其他=>“0”);
开始
x1:TMR_模块端口映射(i1,
i2,
f1,
f2,
f3,
开始
ctrl,
塞尔,
中华电力有限公司,
Z
ca,
呃,
cid_0,
cid_1
);
过程(Clk)
变量数据i:标准逻辑向量(3到0);
变量i:标准逻辑向量(3到0);
开始
z1简单的方法是将“数据”循环回i2
top_模块
,无需对
top\u模块
本身,如果top\u模块
不是最终的top模块
那么,这方面的代码可以如下所示:
i2_or_data <= i2 when (use_i2_not_data = '1') else data_o;
VHDL-2002及更早版本的使用需要内部数据\u o_sig
,因为
因此,无法在模块中读取输出端口
除上述内容外,控制信号use_i2\u not_data
必须为
在使用i2
或data\u o
的条件下,请告诉我您所说的外部“顶部模块”是什么意思?这是否意味着我必须创建另一个位于“顶部模块”顶部的模块?你能更详细地解释一下代码吗?@Ramakanta Chandra:请找到模块内部有选择的更新版本。谢谢你的回复。但这不是我想要的输出。我是stackoverflow的新手,所以我不能发布程序的输出图像(修改后)请你把你的邮箱号码给我好吗?这样我就可以把我真正想要的东西寄给你了。谢谢。
-- Signals for selection between i2 and data_o as i2 port for TMR_Module
signal data_o_sig : std_logic_vector(3 downto 0); -- Internal signal for internal use also
signal use_i2_not_data : std_logic; -- Select between i2 ('1') or data_o ('0')
signal i2_or_data : std_logic_vector(3 downto 0); -- i2 or data_o value
begin
i2_or_data <= i2 when (use_i2_not_data = '1') else data_o_sig;
x1 : TMR_Module port map(i1,
i2_or_data,
...
);
process(Clk)
variable data_i : std_logic_vector(3 downto 0);
begin
z1 <= z or f4;
d_err_buff <= z1(0) and z1(1) and z1(2) and z1(3);
if(rst = '1') then
data_o_sig <= ram(address); -- Drive internal data_o_sig to allow internal use
elsif(rising_edge(Clk))then
if(f4 = "0000") then
data_i := z1;
ram(address) <= data_i;
i <= ram(address);
else
i <= ram(address);
end if;
data_o_sig <= i; -- Drive internal data_o_sig to allow internal use
end if;
end process;
data_o <= data_o_sig; -- Drive output port from internal signal
...