什么';这个VHDL代码-BCD计数器有什么问题?

什么';这个VHDL代码-BCD计数器有什么问题?,vhdl,modelsim,quartus,Vhdl,Modelsim,Quartus,我现在正在学习VHDL,我有一个非常简单的家庭作业-我需要构建一个同步BCD计数器,它将从0计数到9,当它达到9时,将返回到0。我想做一点实验,所以我决定不使用传统的方式(至少在我看来是这样)编写代码(使用if、elseif),而是使用when-else语句(主要是因为计数器从0到9,一旦达到9,就必须返回到0) IEEE库; 使用IEEE.std_logic_1164.all; 实体同步计数器为 端口(rst、clk:标准逻辑); 终端实体; 介绍了同步计数器的结构实现 信号计数器:整数范围0

我现在正在学习VHDL,我有一个非常简单的家庭作业-我需要构建一个同步BCD计数器,它将从0计数到9,当它达到9时,将返回到0。我想做一点实验,所以我决定不使用传统的方式(至少在我看来是这样)编写代码(使用if、elseif),而是使用when-else语句(主要是因为计数器从0到9,一旦达到9,就必须返回到0)

IEEE库;
使用IEEE.std_logic_1164.all;
实体同步计数器为
端口(rst、clk:标准逻辑);
终端实体;
介绍了同步计数器的结构实现
信号计数器:整数范围0到10;
开始

计数器它可能无法解释为什么它从0变为2。请把你的测试台代码贴在前面。但是,您的代码很糟糕。此代码转换为此,并附有注释:

process(rst, clk, counter)
begin
    if rst = '1' then -- Asynchronous reset, so far so good
        counter <= 0;
    elsif clk'event and clk = '1' then -- Rising edge, we got an asynchronous flip-flop?
        counter <= counter + 1;
    elsif counter = 10 then -- What is this!?! not an asynchronous reset, not a synchronous reset, not a clock. How does this translate to hardware?
        counter <= 0;
    end if;
end process;
过程(rst、clk、计数器)
开始
如果rst='1',那么——异步重置,目前为止还不错

也在测试台上反向放置。(你的代码有一个问题,需要很好的简化来解决,但这与你在模拟中看到的情况无关。)如果合成工具支持,基本方法是有效的(有些可能不支持)@BrianDrummond我没有使用它。我刚刚用Quartus编译了代码,在Modelsim中打开了一个新项目,并添加了vhdl文件。您看到的信号来自Modelsim中的“force”功能。那么跳转到2可能与发出这些命令的顺序有关,对此我不能再作进一步评论。然而,对于一个没有异步竞争条件的简单计数器,try
counter实际上会转换为一个等价的进程,其最终语句为
wait on rst,clk,counter而不是过程敏感度列表。见IEEE标准1076-2008,11.6并发信号分配声明,第6 e)段。它提供了两个异步重置条件,这不是顺序存储推断语句的定义形式,并且正如您所说的,可能并不总是符合条件。请参阅IEEE Std 1076.6-2004(已撤销),6.1.3.2使用单个等待语句的边缘敏感存储。我还将使用您的流程语句作为修复,这只是一个细节。
process(rst, clk, counter)
begin
    if rst = '1' then -- Asynchronous reset, so far so good
        counter <= 0;
    elsif clk'event and clk = '1' then -- Rising edge, we got an asynchronous flip-flop?
        counter <= counter + 1;
    elsif counter = 10 then -- What is this!?! not an asynchronous reset, not a synchronous reset, not a clock. How does this translate to hardware?
        counter <= 0;
    end if;
end process;
process(rst, clk)
begin
    if rst = '1' then -- Asynchronous reset
        counter <= 0;
    elsif clk'event and clk = '1' then
        if counter = 9 then -- Synchronous reset
            counter <= 0;
        else
            counter <= counter + 1;
        end if;
    end if;
end process;