Encoding VHDL-增量为1(无符号)

Encoding VHDL-增量为1(无符号),encoding,vhdl,counter,increment,fpga,Encoding,Vhdl,Counter,Increment,Fpga,我正在尝试制作一个代码,用1增加输入位。我想使用两段代码样式,但这里的问题是位没有到达输出。有什么想法吗?谢谢 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.numeric_std.ALL; entity increment1 is port( from_ASMD_State_reg : in std_logic_vector(7 downto 0); reset, clk : in std_l

我正在尝试制作一个代码,用1增加输入位。我想使用两段代码样式,但这里的问题是位没有到达输出。有什么想法吗?谢谢

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;


entity increment1 is
    port(
        from_ASMD_State_reg : in std_logic_vector(7 downto 0);
        reset, clk : in std_logic;
        to_mux : out std_logic_vector(7 downto 0)
    );
end increment1;

architecture Behavioral of increment1 is
--signal count : unsigned(7 downto 0);
signal r_reg : unsigned(7 downto 0);
signal r_next : unsigned(7 downto 0);
begin
process(clk, reset)
begin
    if(reset = '1') then
        to_mux <= (others => '0');
    elsif(clk'event and clk = '1') then
        r_reg <= r_next;
    end if;
end process;

r_next <= r_reg + 1;

to_mux <= std_logic_vector(r_reg);

end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.numeric_std.ALL;
实体增量1为
港口(
从状态寄存器:标准逻辑向量(7到0);
复位,时钟:在标准逻辑中;
到多路复用器:输出标准逻辑向量(7到0)
);
末端递增1;
增量1的体系结构是
--信号计数:无符号(7到0);
信号r_reg:无符号(7到0);
信号r_next:无符号(7到0);
开始
过程(时钟、复位)
开始
如果(重置='1'),则
至_mux“0”);
elsif(clk'事件和clk='1'),然后
r_reg您更新的代码几乎正确,但不完全正确。如果您只想递增并注册一个值,那么您只需执行以下操作:

architecture Behavioral of increment1 is
begin

  r_inc <= unsigned(from_ASMD_State_reg) + 1;

  process (clk, reset)
  begin
    if(reset = '1') then
        r_reg <= (others => '0');
    elsif(clk'event and clk = '1') then
        r_reg <= r_inc;
    end if;
  end process;

  to_mux <= std_logic_vector(r_reg);

end Behavioral;

制作一个单独的组件来实现这一点几乎不值得,但您当然可以。

模块中没有使用来自_ASMD_State_reg
,因此如果这是增量的输入,则使用它作为开始。另外,请注意,
to_mux
既在流程内部驱动,也在流程外部驱动,这样的多个驱动程序无法合成,很可能在模拟中生成X;目的可能是在过程中驱动
r\u reg
。最后,如果在流程表达式中直接使用
r\u reg+1
,则可以不使用
r\u next
。@MortenZilmer感谢您的回复。只是想知道如何使用from ASMD_State_reg作为开始?我是否应该将r_reg设置为from_ASMD_State_reg?我应该在哪里做呢?:)这实际上取决于您要实现的功能,因此,首先要制定一个规范,例如一个表格,列出所有不同输入值的预期输出,在此过程中,您可能会了解在设计中必须实现的功能。@MortenZilmer我做了一些更改,并将代码粘贴到我的帖子上。你能看一下我的代码,看看我的代码中是否还有一些愚蠢的东西吗?:)您可能不应该在进程内部分配给
r\u reg
,而应该在
if
块之外。
architecture Behavioral of increment1 is
begin

  r_inc <= unsigned(from_ASMD_State_reg) + 1;

  process (clk, reset)
  begin
    if(reset = '1') then
        r_reg <= (others => '0');
    elsif(clk'event and clk = '1') then
        r_reg <= r_inc;
    end if;
  end process;

  to_mux <= std_logic_vector(r_reg);

end Behavioral;
to_mux <= std_logic_vector(unsigned(from_ASMD_State_reg) + 1);