如何在一个时钟中完成“A循环”

时间:2016-08-04 07:58:57

标签: vhdl

我试着找到很多代码来引用。

但是我找不到我需要的解决方案。

任何人都可以帮我找到问题&溶液

非常感谢。

问题是我需要这个代码可以变量。

ero_check_t <= erosion_buf(0)(0)+erosion_buf(0)(1)+erosion_buf(0)(2)+
               erosion_buf(1)(0)+erosion_buf(1)(1)+erosion_buf(1)(2)+
               erosion_buf(2)(0)+erosion_buf(2)(1)+erosion_buf(2)(2);

就像上传码(3 * 3)可以变为下码(2 * 2)。

ero_check_t <= erosion_buf(0)(0)+erosion_buf(0)(1)+
               erosion_buf(1)(0)+erosion_buf(1)(1);

我怎么写?可以使用循环代码吗?

process(rst)
begin
    if rst = '0' then
        ero_check   <= "0000000000";
        ero_check_t <= "0000000000";
    else
        for i in 0 to array_x loop
            for j in 0 to (array_y - 1) loop
                if i = array_x then
                    if j= 0 then
                        ero_check_t  <= ero_check;
                        ero_check    <= "0000000000";
                        exit;
                    end if;
                else
                    ero_check := ero_check + erosion_buf(i)(j);
                end if;
            end loop;
        end loop;
    end if;
end process;

1 个答案:

答案 0 :(得分:0)

简短回答是肯定的。更长的答案是,您可能希望检查您的代码是否完全符合您的要求(并且也存在一些问题)。如果您想要组合逻辑执行此操作:

ero_check_t <= erosion_buf(0)(0)+erosion_buf(0)(1)+erosion_buf(0)(2) + ...
               erosion_buf(1)(0)+erosion_buf(1)(1)+erosion_buf(1)(2) + ...
               erosion_buf(2)(0)+erosion_buf(2)(1)+erosion_buf(2)(2) + ...
               ...

然后这样的事情可以解决问题:

process(erosion_buf)              -- erosion_buf is the only input
  variable e :                    -- the same type as ero_check_t
begin
  e :=                            -- zero (I don't know what type ero_check_t is)
  for i in 0 to array_x-1 loop    -- assuming array_x is the LENGTH of the x dimension
    for j in 0 to array_y-1 loop  -- assuming array_y is the LENGTH of the y dimension
       e := e + erosion_buf(i)(j);                     
    end loop;
  end loop;
  ero_check_t <= e;               -- drive the output signal
end process;

ero_chek变量。这被初始化为零,然后嵌套循环执行所有添加。最后,使用变量ero_check_t的内容驱动信号ero_check