模拟与硬件不匹配

发布于 2024-10-18 01:44:26 字数 2813 浏览 4 评论 0原文

我有一个非常简单的问题,但我不知道出了什么问题。 本质上,在模拟时,整个事情工作得很好,但是,拥有它 硬件给了我错误的结果。基本上我有两个 ctrl 信号 确定实体的行为:

 GET   (ctrl = "00000000") sets register tx to input of op1
 SH1_L (ctrl = "00000001") outputs (op1 << 1) or register tx
                           shifts register tx to the right by 31 bits  (tx >> 31)


  library ieee;
  use ieee.std_logic_1164.all;

  entity test is
  port
  (
    op1    : in  std_logic_vector(31 downto 0);      -- First input operand
    ctrl   : in std_logic_vector(7 downto 0);        -- Control signal
    clk    : in  std_logic;                          -- clock
    res    : out std_logic_vector(31 downto 0)       -- Result
  );
  end;

  architecture rtl of test is

    type res_sel_type is (GET, SH1_L); 

    constant Z : std_logic_vector(31 downto 0) := (others => '0');                        

    signal res_sel  : res_sel_type;
    signal load     : std_logic := '0';
    signal shl      : std_logic := '0';

    signal tx       : std_logic_vector(31 downto 0) := (others => '0');
    signal inp1     : std_logic_vector(31 downto 0) := (others => '0');

  begin

    dec_op: process (ctrl, op1)
    begin  

        res_sel  <= GET;
      load     <= '0';
      shl      <= '0';
      inp1     <= ( others => '0');

      case ctrl is

         -- store operand 
             when "00000000" =>
                inp1    <= op1;             
                load    <= '1';          
                res_sel <= GET;

             -- 1-bit left-shift with carry 
             when "00000001" =>
              inp1    <= op1;
          shl     <= '1'; 
                res_sel <= SH1_L;

             when others =>
                -- Leave default values

             end case;                  

    end process;

    -- Selection of output
    sel_out: process (res_sel, inp1) 
    begin

      case res_sel is

       when GET => NULL;  

       when SH1_L =>
        res  <= ( inp1(30 downto 0) & '0' ) or tx;

         when others =>
            res <= (others => '0');

      end case;

    end process;

    sync: process(clk)
    begin       
     if clk'event and clk = '1' then
          if load = '1' then  
             tx <= op1;
          elsif shl = '1' then
             tx <= Z(30 downto 0) & op1(31);
          end if;      
     end if;
    end process;  

  end rtl;

TESTPROGRAM

GET  0
SH1_L 0xfedcba90    exp. output: 0xfdb97520  act. output = 0xfdb97521
SH1_L 0x7654321f    exp. output: 0xeca8643f  act. output = 0xeca8643e
SH1_L 0x71234567    exp. output: 0xe2468ace  act. output = 0xe2468ace

正如您所看到的,由于某种原因,最后一位是错误的。我必须有一些东西 时序错误,导致寄存器 tx 在实际写入之前先被写入 用于计算输出。

有人知道如何解决这个问题吗?

非常感谢!

I have a very simple problem but I do not get my head around what is going wrong.
Essentially, the whole thing works fine when simulating it, however, having it
in hardware gives me the wrong result. Basically I have two ctrl signals that
determine the behaviour of the entity:

 GET   (ctrl = "00000000") sets register tx to input of op1
 SH1_L (ctrl = "00000001") outputs (op1 << 1) or register tx
                           shifts register tx to the right by 31 bits  (tx >> 31)


  library ieee;
  use ieee.std_logic_1164.all;

  entity test is
  port
  (
    op1    : in  std_logic_vector(31 downto 0);      -- First input operand
    ctrl   : in std_logic_vector(7 downto 0);        -- Control signal
    clk    : in  std_logic;                          -- clock
    res    : out std_logic_vector(31 downto 0)       -- Result
  );
  end;

  architecture rtl of test is

    type res_sel_type is (GET, SH1_L); 

    constant Z : std_logic_vector(31 downto 0) := (others => '0');                        

    signal res_sel  : res_sel_type;
    signal load     : std_logic := '0';
    signal shl      : std_logic := '0';

    signal tx       : std_logic_vector(31 downto 0) := (others => '0');
    signal inp1     : std_logic_vector(31 downto 0) := (others => '0');

  begin

    dec_op: process (ctrl, op1)
    begin  

        res_sel  <= GET;
      load     <= '0';
      shl      <= '0';
      inp1     <= ( others => '0');

      case ctrl is

         -- store operand 
             when "00000000" =>
                inp1    <= op1;             
                load    <= '1';          
                res_sel <= GET;

             -- 1-bit left-shift with carry 
             when "00000001" =>
              inp1    <= op1;
          shl     <= '1'; 
                res_sel <= SH1_L;

             when others =>
                -- Leave default values

             end case;                  

    end process;

    -- Selection of output
    sel_out: process (res_sel, inp1) 
    begin

      case res_sel is

       when GET => NULL;  

       when SH1_L =>
        res  <= ( inp1(30 downto 0) & '0' ) or tx;

         when others =>
            res <= (others => '0');

      end case;

    end process;

    sync: process(clk)
    begin       
     if clk'event and clk = '1' then
          if load = '1' then  
             tx <= op1;
          elsif shl = '1' then
             tx <= Z(30 downto 0) & op1(31);
          end if;      
     end if;
    end process;  

  end rtl;

TESTPROGRAM

GET  0
SH1_L 0xfedcba90    exp. output: 0xfdb97520  act. output = 0xfdb97521
SH1_L 0x7654321f    exp. output: 0xeca8643f  act. output = 0xeca8643e
SH1_L 0x71234567    exp. output: 0xe2468ace  act. output = 0xe2468ace

As you can see, the last bit is wrong for some reason. I must have something
wrong with the timing, so that the register tx is first written before it is acutally
used in the computation of the output.

Anyone an idea how to solve this problem?

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我们只是彼此的过ke 2024-10-25 01:44:26

您是否忘记了过程敏感度列表中的 tx 信号?

Sigasi HDT 的屏幕截图

Didn't you forget the tx signal in your process sensitivity list?

screenshot of Sigasi HDT

幸福不弃 2024-10-25 01:44:26

res 并不是在组合过程中的所有条件下都定义的。因此,您可能会在综合结果中使用逻辑门控锁存器。从来都不是一个好主意。

首先通过提供默认分配来删除它们。

res is not defined under all conditions in a combinatorial process. Therefore, you will presumably have latches gated by logic in the synthesis result. Never a good idea.

Start by removing them by providing a default assignment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文