首页 文章

这个VHDL代码如何工作?

提问于
浏览
0

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

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时钟脉冲尽管阅读了上面提到的已回答的问题,

当我评论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]赋值宽度不匹配; target有2位,source有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 .

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

如果有人可以澄清这个或建议修改我的程序,这将产生所需的延迟,这将是伟大的 .

提前致谢,

西蒙 .

1 回答

  • 2

    首先,第一个代码效率不高,可以减少到

    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位(或者你称之为"elements"),那么你可以想象 a_store(1 downto 0) & aa_store 的1位 a = 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;
    

相关问题