Vhdl 可以多次使用信号代替硬编码值吗?
我是一名学习VHDL的学生,有一个非常基本的问题 我读到信号分配不会立即进行。因此,以下操作将无法按预期工作:Vhdl 可以多次使用信号代替硬编码值吗?,vhdl,fpga,modelsim,quartus,Vhdl,Fpga,Modelsim,Quartus,我是一名学习VHDL的学生,有一个非常基本的问题 我读到信号分配不会立即进行。因此,以下操作将无法按预期工作: x <= y; z <= not x; 我习惯于尝试避免代码重复和在其他语言中进行硬编码,因此对上述代码中的opD和functD值进行硬编码让我感到困扰 我想知道的是,我是否可以将这些值分配给一个内部信号,如下所示: architecture struct of mips is signal opD: STD_LOGIC; signal functD
x <= y;
z <= not x;
我习惯于尝试避免代码重复和在其他语言中进行硬编码,因此对上述代码中的opD
和functD
值进行硬编码让我感到困扰
我想知道的是,我是否可以将这些值分配给一个内部信号,如下所示:
architecture struct of mips is
signal opD: STD_LOGIC;
signal functD: STD_LOGIC;
begin
signal opD <= instrD(31 downto 26);
signal functD <= instrD(5 downto 0);
controller: entity work.controller port map(opD => opD,
functD => functD);
datapath: entity work.dataPath port map(opD => opD,
functD => functD);
end;
mips的架构结构是
信号opD:标准逻辑;
信号功能:标准逻辑;
开始
信号opD功能);
datapath:entity work.datapath端口映射(opD=>opD,
functD=>functD);
结束;
这是否会按预期工作(即与上述代码块工作完全相同),或者是否会因使用信号而导致某种“延迟”,从而使两个代码块的功能不同
我读到信号分配不会立即进行
这是真的,但我认为你错过了一个重要的点,那就是知道它们何时发生。当生成信号的进程遇到wait语句或end时,信号会被更新(因为进程末尾的进程敏感度列表中有一个隐式等待)
所以,如果你把你的例子放在一个有时钟的过程中,它不会像你期望的那样工作,但是在一个具有正确灵敏度列表的组合过程中是完全有效的
architecture rtl of example is
signal y_r : std_logic;
signal z_r : std_logic;
signal y : std_logic;
signal z : std_logic;
begin
y <= x; -- immediately updated when x changes
z <= not y; -- immediately updated when y changes, equivalent to z <= not x
process(clk)
begin
if rising_edge(clk) then
y_r <= x; -- y is updated when the clock rise, once this process finishes
z_r <= not y_r; -- y still have the value it had when the process started executing
end if;
end process;
end architecture rtl;
我读到信号分配不会立即进行
这是真的,但我认为你错过了一个重要的点,那就是知道它们何时发生。当生成信号的进程遇到wait语句或end时,信号会被更新(因为进程末尾的进程敏感度列表中有一个隐式等待)
所以,如果你把你的例子放在一个有时钟的过程中,它不会像你期望的那样工作,但是在一个具有正确灵敏度列表的组合过程中是完全有效的
architecture rtl of example is
signal y_r : std_logic;
signal z_r : std_logic;
signal y : std_logic;
signal z : std_logic;
begin
y <= x; -- immediately updated when x changes
z <= not y; -- immediately updated when y changes, equivalent to z <= not x
process(clk)
begin
if rising_edge(clk) then
y_r <= x; -- y is updated when the clock rise, once this process finishes
z_r <= not y_r; -- y still have the value it had when the process started executing
end if;
end process;
end architecture rtl;
所以你说你的
y是的,因为在这个过程之外,信号会立即更新。作为参考,两者都按预期工作,只是没有按您的预期工作;)所以你说你的y是的,因为在这个过程之外,信号会立即更新。作为参考,两者都按预期工作,只是没有按您的预期工作;)
architecture struct of mips is
alias opD is instrD(31 downto 26);
alias functD is instrD(5 downto 0);
begin
controller: entity work.controller port map(opD => opD,
functD => functD
datapath: entity work.dataPath port map(opD => opD,
functD => functD;
end;