【问题标题】:How does this VHDL code work?这个 VHDL 代码是如何工作的?
【发布时间】:2017-04-21 09:54:57
【问题描述】:

我本来只想在下面的来源帖子中发表评论,但我还没有这个特权,所以我想我可能会问一个问题,以便得到一些澄清。

how to delay a signal for several cycles in vhdl

基本上我需要在我的 VHDL 项目的行为中为这个进程实现 2 个时钟周期延迟(代码如下所示):

  process(font_address(0), font_address(1), font_address(2), font_address(3),font_address(4), font_address(5), font_address(6), font_address(7),vga_hcount(0), vga_hcount(1),vga_hcount(2),CLK)

begin




--if (CLK'event and CLK = '1') then
  -- a_store <= a_store(1 downto 0) & a;
  -- a_out <= a_store(1 downto 0);
 --end if;

if (CLK'event and CLK = '1') then
case vga_hcount(2 downto 0) is
when "000" => font_bit <= font_data(7);
when "001" => font_bit <= font_data(6);
when "010" => font_bit <= font_data(5);
when "011" => font_bit <= font_data(4);
when "100" => font_bit <= font_data(3);
when "101" => font_bit <= font_data(2);
when "110" => font_bit <= font_data(1);
when "111" => font_bit <= font_data(0);
when others => font_bit <= font_data(0);
end case;
end if;



end process;

正如你所看到的,我已经做到了,在处理中的信号分配之前,它需要一个时钟周期延迟,由围绕信号分配的 if 语句提供,但我似乎无法创建一个可合成的尽管阅读了上面链接的已回答问题,但仍有 2 个时钟脉冲延迟

当我注释包围 case 的 if 语句并取消注释以下代码块时

 if (CLK'event and CLK = '1') then
 a_store <= a_store(1 downto 0) & a;
 a_out <= a_store(1 downto 0);
 end if;

取自本问题开头给出的链接,我收到以下错误:

[Synth 8-690] 分配宽度不匹配;目标有 2 位,源有 3 位 ["U:/Computer organization lab/vga/vga_prac.vhd":304]

此错误消息中引用的目标是 a_store 向量,源是 a_store 和 a 的串联。

这是在我将逻辑 1 分配给 a 并将 a_store 和 a_out 创建为具有 2 个元素的 std_logic_vectors 之后(因为我想要两个时钟周期的延迟)。我认为我收到此错误的原因是因为即使在阅读了这个问题几个小时后,我似乎仍然无法理解它实际上应该如何产生 2 个时钟周期的延迟。

起初我认为可能是 1 位通过 a_store 向量进行迭代,直到 MSB 为 1,然后将该向量应用于 a_out 但查看它在 if 语句中的事实,我看不到这两行代码是如何执行不止一次的。如果这是真的,我将不得不进行一些测试以确保 a_out 在其 MSB 中有 1。

通常我会继续前进,但经过大量搜索后,我找不到比这更简单的解决方案,尽管我并不完全理解它应该如何工作。

如果有人可以澄清这一点或建议对我的程序进行修改,这将产生所需的延迟,那就太好了。

提前致谢,

西蒙。

【问题讨论】:

  • 进程敏感度列表中有很多不必要的名字。只需要CLK
  • 您声称从另一个问题复制/粘贴的代码实际上是不同的。
  • Martin 对您的链接问题的回答显示a_store &lt;= a_store(store'high-1 downto 0) &amp; a; 给出了正确答案。在递减范围内 (downto) 'high 给出左边界的索引值。对于具有两个元素 1 到 0 的数组子类型,这将是 a_store(0 到 0) 具有一个元素的数组值。你的问题是你没有忠实地执行马丁的回答。您还可以提供 MCVe 以便声明可见。还有font_bit &lt;= font_data(to_integer(unsigned(not vga_hcount(2 downto 0)))); 一个 8 输入多路复用器。

标签: vhdl


【解决方案1】:

首先,第一个代码效率不高,可以简化为

use ieee.numeric_std.all;
[...]

process(CLK)
begin
    if rising_edge(CLK) then
        font_bit <= font_data(7 - to_integer(unsigned(vga_hcount(2 downto 0))));
    end if;
end process;

对于第二部分,错误说明了一切。你说 a_store 有 2 位(或者你称之为“元素”),那么你可以想象 a_store(1 downto 0) &amp; aa_store 的两位 + a 的 1 位 = 3 位。您不能将 3 位分配给 2 位。那怎么合适?分配a_out 时同样的问题:2 位如何适合 1 位?

因此:

if (CLK'event and CLK = '1') then
    a_store <= a_store(0) & a;
    a_out <= a_store(1);
end if;

【讨论】:

  • 感谢您的反馈,当我回到实验室时,我会进行此更改,看看它是否正常工作。
  • 这仅适用于我必须将 a_store(1 downto 0) 分配给 a_out 而不是您在这里所做的。不过还是谢谢。
  • @burton01 由于您没有提供完整的代码,这可能是真的。我只是建议了正常的两个时钟延迟的代码。
猜你喜欢
  • 2010-12-13
  • 2013-04-23
  • 2015-04-09
  • 2013-07-24
  • 2014-03-26
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多