gpt4 book ai didi

process - VHDL : Multiple rising_edge detections inside a process block

转载 作者:行者123 更新时间:2023-12-02 21:05:34 25 4
gpt4 key购买 nike

我对 VHDL(以及一般的数字电路)还很陌生,我正在尝试使用 BCD 样式 block 实现两位数的计数器。该电路的外部有一些按钮,按下这些按钮时,会将感兴趣的数字加一(很像闹钟)。这是一个异步操作,会在某种形式的编辑模式下发生(外部强制)。我编写的代码在没有“elsifrising_edge(digitUp1)then”和“elsifrising_edge(digitUp1)then” block 的情况下工作正常,但包含它们时会失败。我真的不知道为什么它不起作用或如何修复它。不断出现错误,例如“无法在此时钟边缘实现分配的寄存器”、“无法推断 count2[3] 的寄存器,因为其行为取决于多个不同时钟的边缘”和“无法推断寄存器” count2[3]”位于 MinuteCounter.vhd(21),因为它在时钟边沿之外不保存其值”。任何帮助将不胜感激。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;

-- ToDo: ENFORCE ON ALL COUNTERS (externally) LOGIC TO PAUSE AT MAX/MIN

entity MinuteCounter is
port( clockIn, digitUp1, digitUp2, reset, counting, countUp : in std_logic;
clockOut : out std_logic;
BCD1, BCD2 : out std_logic_vector(3 downto 0));
end MinuteCounter;

architecture structure of MinuteCounter is
signal count1, count2 : std_logic_vector(3 downto 0);
signal carryOut : std_logic;
begin

process( clockIn, digitUp1, digitUp2, countUp, reset, counting)
begin

-- Asynchronous reset
if reset = '1' then
count1 <= "0000";
count2 <= "0000";

-- What to run when there's an active edge of the clock
elsif rising_edge(clockIn) then

-- Code to run when timer is running
if counting = '1' then

-- What to do when counting up
if countUp = '1' then
if ((count1 = "1001") and (count2 = "0101")) then
count1 <= "0000";
count2 <= "0000";
if carryOut = '0' then
carryOut <= '1';
else
carryOut <= '0';
end if;
elsif count1 = "1001" then
count1 <= "0000";
count2 <= count2 + 1;
else
count1 <= count1 + 1;
end if;

-- What to do when counting down (This logic is hard to understand)
else
if ((count1 = "0000") and (count2 = "0000")) then
count1 <= "1001";
count2 <= "0101";
if carryOut = '0' then
carryOut <= '1';
else
carryOut <= '0';
end if;
elsif count1 = "0000" then
count1 <= "1001";
count2 <= count2 - 1;
else
count1 <= count1 - 1;
end if;
end if;

-- When counting is disabled, but there is an active edge (do nothing)
else
count1 <= count1;
count2 <= count2;
end if;

-- Code to run when entering values (will not be run if counting = '1') << Externally enforced
elsif rising_edge(digitUp1) then
if count1 = "1001" then
count1 <= "0000";
count1 <= count1 + 1;
else
count1 <= count1 + 1;
end if;

-- Code to run when entering values (will not be run if counting = '1') << Externally enforced
elsif rising_edge(digitUp2) then
if count2 = "0101" then
count2 <= "0000";
count2 <= count2 + 1;
else
count2 <= count2 + 1;
end if;

-- What to do when there is no active edge or other events (nothing)
else
count1 <= count1;
count2 <= count2;
end if;

end process;

-- Assign outputs
BCD1 <= count1;
BCD2 <= count2;
clockOut <= carryOut;

end structure;

最佳答案

问题标题中解释了“为什么它不起作用”:进程 block 内的多个上升沿检测

VHDL是为了描述硬件而设计的,没有响应多个时钟信号的基本电路元件。所以你不能那样描述电路。

那么如何解决这个问题呢?

您将电路转换为任何单个进程仅具有一个时钟信号的电路(如果您正确使用,还可以选择一个异步复位信号)。这可以使用真实的寄存器和触发器来实现。

两种方法是:

  1. 多个进程,使用信号在它们之间进行通信
  2. 单个进程,使用单个时钟,在主时钟沿采样其他信号。

在这些之间做出正确的决定需要对设计有一定的整体了解。

这里听起来好像所有三个时钟信号实际上都是按钮按下,而不是一个快速时钟。因此,您不能保证按下另一个按钮时会有时钟沿。

因此,这是前进的多种方法之一:制作一个时钟信号(在进程之外),它将覆盖所有三个输入事件。

my_clock <= clockIn or digitUp1 or digitUp2;

现在您可以使用此时钟重写该过程:

process(my_clock, reset) is
begin
if reset = '1' then
-- reset actions
elsif rising_edge(my_clock) then
-- what caused this event?
if digitUp1 = '1' then -- bump digit 1
elsif digitup2 = '1' then -- bump digit 2
else -- count normally
endif;
end if;
end process;

注释:

  1. 由于这是一个正确的同步过程,因此只有时钟和复位属于敏感列表。
  2. 虽然这在某种意义上可行,但可能不是客户想要的:例如,如果他按住所有三个按钮会发生什么?您可能想探索其他设计方法。

关于process - VHDL : Multiple rising_edge detections inside a process block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19879960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com