首页 > 解决方案 > vhdl 程序中的指令模块如何工作?

问题描述

我对以下程序只有一个疑问:

process(clk)
        variable cuenta : integer range 0 to 255 := 0;
    begin
        if clk = '1' and clk'event then
            cuenta := (cuenta +1) mod 256;
            if cuenta < D then
                S <= '1';
            else
                S <= '0';
            end if;
        end if;
    end process;

上表cuenta:= (cuenta+1) mod 256,值cuenta达到255?,我的意思是cuenta它不是一直都是 0 吗?D只是 0 到 255 之间的一个值。谢谢,我希望有人可以帮助我解决这个可能很简单的问题。

标签: vhdlfpga

解决方案


我用测试台重新创建了您的代码,如果您运行它,您将能够告诉 cuenta 只是将 1 添加到其中,然后模块由 256 设计。我停止了增量,现在它只是一个驱动的信号。

获取更多信息可能有助于实际解决您的问题。希望我添加的内容有所帮助。

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;


entity cuenta is
port(
    clk       : in std_logic;
    reset     : in std_logic;
    D         : in std_logic_vector(7 downto 0);
    cuenta    : in std_logic_vector(8 downto 0);
    modulo_in : in std_logic_vector(8 downto 0);
    S         : out std_logic
);

end cuenta;

architecture behav of cuenta is

    signal cuenta_q : std_logic_vector(8 downto 0);

begin
 process(clk)
    begin
        if rising_edge(clk) then
           if reset = '1' then
              cuenta_q <= (others => '0');
              S <= '0';
           elsif reset = '0' then
              cuenta_q <= std_logic_vector(unsigned(cuenta + 1) mod unsigned(modulo_in));
              if cuenta_q < D then
                 S <= '1';
              else
                 S <= '0';
              end if;
           end if;
       end if;
    end process;

end behav;


library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;

entity tb_cuenta is
end tb_cuenta;



architecture tb of tb_cuenta is

   signal clk       : std_logic := '1';
   signal reset     : std_logic := '1';
   signal D         : std_logic_vector(7 downto 0);
   signal cuenta    : std_logic_vector(8 downto 0);
   signal modulo_in : std_logic_vector(8 downto 0);
   signal S         : std_logic;

begin

    D         <=  x"F0";
    cuenta    <= "000100000";
    modulo_in <= "100000000";

    clk   <= not clk after 50 fs;
    reset <= '0' after 200 fs;

ceunta_inst : entity work.cuenta 
   port map(
        clk => clk,
    reset => reset,
    D => D,
    cuenta => cuenta,
    modulo_in => modulo_in,
    S => S
   );

end tb;

推荐阅读