如何更新结构 VHDL 代码中时钟上升沿的输出?
how to update the output on the rising edge of the clock in structural VHDL code?
我有这个非常简单的 16 位和门,用 VHDL 以结构形式编写:
文件已上传 here.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and_16bit is
Port (
A : in std_logic_vector(15 downto 0);
B : in std_logic_vector(15 downto 0);
Clk : in STD_LOGIC;
--Rst : in STD_LOGIC;
C : out std_logic_vector(15 downto 0) );
end and_16bit;
architecture Behavioral of and_16bit is
component and_1bit is
Port (
A : in std_logic;
B : in std_logic;
C : out std_logic );
end component;
signal s : std_logic_vector(15 downto 0);
begin
ands: for i in 15 downto 0 generate
and_1bit_x: and_1bit port map (A => A(i), B => B(i), C => s(i));
end generate;
process(Clk)
begin
if rising_edge(Clk) then
C <= s;
end if;
end process;
end Behavioral;
为了在时钟的上升沿更新输出,我定义了这个"s"信号。我想知道这是否是更新结构 VHDL 代码输出的正确方法?我应该怎么做才能为第一个输出转义未知输出?
任何评论都会有很大帮助。
最好将顺序过程放入一个子模块中,并在顶层实例化它(and_16bit
)。那么你的顶层将更加结构化。
您可以像 and_1bit
一样为每个位创建一个实例。
比如这个模块是1位寄存器
entity dff_1bit is
Port (
D : in std_logic;
Clk : in std_logic;
Q : out std_logic );
end dff_1bit;
architecture Behavioral of dff_1bit is
begin
process(Clk)
begin
if rising_edge(Clk) then
Q <= D;
end if;
end process;
end Behavioral;
然后您可以在 and_16bit
中实例化它,在同一个 generate
块中。
dff_1bit_x: dff_1bit port map (D => s(i), Clk => Clk, Q => C(i));
我有这个非常简单的 16 位和门,用 VHDL 以结构形式编写: 文件已上传 here.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and_16bit is
Port (
A : in std_logic_vector(15 downto 0);
B : in std_logic_vector(15 downto 0);
Clk : in STD_LOGIC;
--Rst : in STD_LOGIC;
C : out std_logic_vector(15 downto 0) );
end and_16bit;
architecture Behavioral of and_16bit is
component and_1bit is
Port (
A : in std_logic;
B : in std_logic;
C : out std_logic );
end component;
signal s : std_logic_vector(15 downto 0);
begin
ands: for i in 15 downto 0 generate
and_1bit_x: and_1bit port map (A => A(i), B => B(i), C => s(i));
end generate;
process(Clk)
begin
if rising_edge(Clk) then
C <= s;
end if;
end process;
end Behavioral;
为了在时钟的上升沿更新输出,我定义了这个"s"信号。我想知道这是否是更新结构 VHDL 代码输出的正确方法?我应该怎么做才能为第一个输出转义未知输出?
任何评论都会有很大帮助。
最好将顺序过程放入一个子模块中,并在顶层实例化它(and_16bit
)。那么你的顶层将更加结构化。
您可以像 and_1bit
一样为每个位创建一个实例。
比如这个模块是1位寄存器
entity dff_1bit is
Port (
D : in std_logic;
Clk : in std_logic;
Q : out std_logic );
end dff_1bit;
architecture Behavioral of dff_1bit is
begin
process(Clk)
begin
if rising_edge(Clk) then
Q <= D;
end if;
end process;
end Behavioral;
然后您可以在 and_16bit
中实例化它,在同一个 generate
块中。
dff_1bit_x: dff_1bit port map (D => s(i), Clk => Clk, Q => C(i));