【问题标题】:"after" not working in Modelsim“之后”在 Modelsim 中不起作用
【发布时间】:2017-11-01 04:12:44
【问题描述】:

我正在尝试在 Modelsim 中制作串行加法器的行为模型。

因此,在设计中,我试图在一个时钟周期后将 Carry_out 传递给 Carry_in。

设计是:

一个位,两个 n 位数字中的每个与进位一起进入加法器。

最初进位为 0,但在下一个时钟周期中,前一位相加产生的进位输出再次作为进位输入传递,并且对接下来的两位进行加法,每个数字一个位。

代码如下:

library ieee;

use ieee.std_logic_1164.all;

entity serial_adder is

    port (a,b: in std_logic;
        s: out std_logic;
        cin,cout: inout std_logic);
end serial_adder;

architecture serial_adder_arch of serial_adder is
begin
    process(a,b,cin,cout)
    begin
    if (a='0' and b ='0' and cin ='0')
    then s <='0';
         cout <='0';
    elsif (a='0' and b ='0' and cin ='1')
    then s <='1';
         cout <='0';
    elsif (a='0' and b ='1' and cin ='0')
    then s <='1';
         cout <='0';
    elsif (a='0' and b ='1' and cin ='1')
    then s <='0';
         cout <='1';
    elsif (a='1' and b ='0' and cin ='0')
    then s <='1';
         cout <='0';
    elsif (a='1' and b ='0' and cin ='1')
    then s <='0';
         cout <='1';
    elsif (a='1' and b ='1' and cin ='0')
    then s <='0';
         cout <='1';
    elsif (a='1' and b ='1' and cin ='1')
    then s <='1';
         cout <='1';
    end if;
    cin <= cout after 50 ps;
    end process;

end serial_adder_arch;

模拟后,我看到我使用“之后”给出的延迟不起作用。我没有延迟,cout 没有被分配给cin

【问题讨论】:

    标签: vhdl modelsim


    【解决方案1】:

    您的模拟器时间分辨率是多少?默认为1ns,延时会四舍五入到分辨率。

    尝试vsim -t 50ps 将分辨率更改为 50ps。

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
    • @brick - 你误解了问题和答案。 after似乎工作,因为默认模拟器时间分辨率为 1ns,after 指定延迟为 50ps,将四舍五入为 0。这是一个常见问题解答,将任何以做这种事情为生的人都知道。 OP 显然很困惑,因为他接受了一个完全不相关的答案。
    【解决方案2】:

    即使你让这段代码在模拟中工作,它也不会合成,因为等待语句。

    请参阅下面的串行加法器代码。

    library ieee;
    use ieee.std_logic_1164.all;
    
    --serial adder for N bits. Note that we dont have to mention N here. 
    entity serial_adder is
        port(Clk,reset : in std_logic; --clock and reset signal
                a,b,cin : in std_logic;  --note that cin is used for only first iteration.
                s,cout : out std_logic  --note that s comes out at every clock cycle and cout is valid only for last clock cycle.
                );
    end serial_adder;
    
    architecture behav of serial_adder is
    
    --intermediate signals.
    signal c,flag : std_logic := '0';
    
    begin
    
    process(clk,reset)
    --we use variable, so that we need the carry value to be updated immediately.
    variable c : std_logic := '0'; 
    begin
    if(reset = '1') then --active high reset
        s <= '0';
        cout <= c;
        flag <= '0';
    elsif(rising_edge(clk)) then
        if(flag = '0') then
            c := cin;  --on first iteration after reset, assign cin to c.
            flag <= '1';  --then make flag 1, so that this if statement isnt executed any more.
        end if; 
        s <= a xor b xor c;  --SUM
        c := (a and b) or (c and b) or (a and c);  --CARRY
    end if;
    end process;
    
    end behav;
    

    如果你喜欢它,那么link 上有测试台代码和解释。

    【讨论】:

    • 嗯,错误实际上是因为我试图将cout 的值直接分配给cin。你的方法奏效了。非常感谢。 :)
    • 如果它不合成又有什么关系呢?问题中没有任何内容表明需要综合。
    猜你喜欢
    • 2013-12-28
    • 2013-11-07
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多