【问题标题】:Addition of single bits in VHDL在 VHDL 中添加单个位
【发布时间】:2021-04-21 18:51:23
【问题描述】:

我一直在尝试编写一个添加单个位的组合电路。当我模拟我的代码时,我从我的临时寄存器中得到未知值(“U”)。我正在添加我的代码以供参考。如果我遗漏了什么或者我的逻辑是错误的,请纠正我。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity serial_adder is
    Port ( a : in std_logic;
           b : in std_logic;
           c : in std_logic;
           d : in std_logic;
           e : in std_logic;
           f : in std_logic;
           g : in std_logic;
           h : in std_logic;
           sum : out std_logic_vector (3 downto 0));
end serial_adder;

architecture Behavioral of serial_adder is
    signal temp1, temp2, temp3, temp4 : std_logic_vector (1 downto 0);
    signal temp5, temp6, temp9 : std_logic_vector (2 downto 0);
    signal temp7, temp8 :std_logic_vector (1 downto 0);
begin
    process (a,b,c,d,e,f,g,h)
    begin
        temp1(0) <= a or b;
        temp2(0) <= c or d;
        temp3(0) <= e or f;
        temp4(0) <= g or h;
        temp7 <= temp1 or temp2;
        temp8 <= temp3 or temp4;
        temp9 <= temp5 or temp6;

        if (a = b and temp1(0) /= a) then
            temp1(1) <= not temp1(0);
        else
            temp1(1) <= '0';
        end if;
    
        if (c = d and temp2(0) /= c) then
            temp2(1) <= not temp2(0);
        else
            temp2(1) <= '0';
        end if;

        if (e = f and temp3(0) /= e) then
            temp3(1) <= not temp3(0);
        else
            temp3(1) <= '0';
        end if;
    
        if (g = h and temp4(0) /= g) then
            temp4(1) <= not temp4(0);
        else
            temp4(1) <='0';
        end if;
    
        if (temp1(1) = temp2(1) and temp7(1) /= temp1(1)) then
            temp5 <= ('1' ,temp7(1), temp7(0));
        end if;
     
        if (temp3(1) = temp4(1) and temp8 (1) /= temp3(1)) then
            temp6 <= ('1' ,temp8(1), temp8(0));
        end if;   
     
        if (temp5(2) = temp6(2) and temp9(2) /= temp5(2)) then
            sum <= ('1', temp9(2), temp9(1), temp9(0));
        end if;
    
    end process;
end Behavioral;

【问题讨论】:

  • 你的模拟是做什么的?
  • 结果是 U,所有温度信号都显示 U 值。我添加了模拟图像。
  • 在进程暂停之前,信号不会更新。如果你需要一个在赋值后立即更新的数据对象,你需要一个变量。
  • 但是进程外的变量应该是共享的吧?
  • 你只有一个进程,没有其他并发语句。外面是什么?请注意,在您的进程中评估 temp1、temp2、temp3、temp4、temp5、temp6、temp7、temp8 和 temp9 时,它们都不在进程敏感度列表中。添加这些将无济于事,您还有logic problems

标签: vhdl vivado


【解决方案1】:

信号都是“U”,因为进程从未被访问过。

根据您的敏感度列表,该过程仅在输入信号上执行

process (a,b,c,d,e,f,g,h)

考虑到这一点,这些信号都没有改变要完成的过程的值。

在您的测试台中尝试更改其中一个信号的输入值,并且应该执行该过程来更改您的输出值。

【讨论】:

  • 我更改了我的敏感度列表。我在列表中添加了所有临时信号,并在计算总和后,将其分配给进程块外的总和。但是,它仍然显示出一些问题
  • @user15725054 “一些问题”是什么意思?请编辑您的问题(问题下方有一个小链接),添加更改的源,并显示确切的问题。或者,如果它与问题无关,请发布一个新问题。
  • 使用 process (all) 并为 VHDL-2008 进行模拟/编译。自 2008 年以来,VHDL 中已弃用敏感度列表。
  • IEEE Std 1076-2008 11.3 Process statement "如果进程敏感性列表是使用保留字all指定的,那么等待语句的敏感性列表是通过取通过应用以下规则,从流程中的每个语句构造的集合的并集...” 完全不推荐使用,并且可能有充分的理由手动指定敏感度列表。每个进程至少执行一次,使这个答案无效。敏感性列表意味着等待语句作为带有敏感性子句的最后一条语句(10.2 等待语句)。
  • 对不起,我不得不写一个答案,我没有足够的声誉来评论别人的帖子......你能张贴你的意思的图片吗?
【解决方案2】:

当您在流程中不使用任何时钟时,不确定您要通过流程实现什么。通常(至少根据我的经验)您要么使用带时钟的进程(如果情况下通常会重置),要么使用在进程之外执行的组合逻辑。

在 FPGA 中,只有当敏感度列表中的信号发生变化时,进程中的逻辑才会“执行”/“分析”。另一方面,进程外的 VHDL 代码是用逻辑门(即没有时钟触发器,但是和/或/...门等)实现的,因此会不断更新,几乎是即时的。 如果您使用进程并忘记了敏感度列表中的信号,或者在进程中使用了不允许与 FPGA 逻辑正确合成的奇怪 VHDL 代码(即,在您的示例中没有时钟的进程),它可能在模拟器中工作,但不是在 FPGA 中。

话虽如此,我建议将您的问题转换为时钟进程:

    architecture Behavioral of serial_adder is
        -- define signals...
    begin
        process (clk)
        begin
            if rising_edge(clk) then
                if reset = '1' then
                    -- reset signal to their default level:
                    temp1(0) <= '0';
                    -- ...
                    
                else
                    -- here goes your main code:
                    temp1(0) <= a or b
                    -- ...
                    if (a = b and temp1(0) /= a) then
                        temp1(1) <= not temp1(0);
                    else
                        temp1(1) <= '0';
                    end if;
                    -- ...

                end if;
            end if;
        end process;
    end Behavioral;

...或者使用纯逻辑,即将 if-else 替换为 when-else (what is the difference)

architecture Behavioral of serial_adder is
    -- define signals...
begin
    temp1(0) <= a or b;
    -- ...
    
    temp1(1) <= not temp1(0)    when ((a = b) and (temp1(0) /= a))
           else '0';
    -- ...
    
end Behavioral;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多