我正在尝试以一种通用的方式编写这段代码。有没有一种方法可以用泛型表达式代替数字。(1,2,3..max)“最大值”将在每个项目和项目期间发生变化。每次有新的变量时,我都会在代码的末尾多加一行,自己修改数字。
我试着写下max,max -1,max-2,max-3 ..但是当max是泛型时,这是不可以的。
case state_counter is
when max-6 => block_output <= variable_a;
when max-5 => block_output <= variable_b
when max-4 => block_output <= variable_c;
when max-3 => block_output <= variable_d;
.....
when max-1 => block_output <= something;
when max => block_output <= something_else; case state_counter is
when 1 => block_output <= variable_a;
when 2 => block_output <= variable_b
when 3 => block_output <= variable_c;
when 4 => block_output <= variable_d;
.....
when max-1 => block_output <= something;
when max => block_output <= something_else;发布于 2019-11-04 22:14:03
有点变通,但是你能把你所有的变量放到一个数组中,然后从那个数组中选择变量吗?您必须将变量放入数组中。我没有尝试过编译它,但是它应该看起来像这样。
假设输出是slv(7减为0),并且您可以使用genereic MAX来设置大小
architecture A1 of example is
type t_output_array is array (INTEGER range <>) of std_logic_vector(7 downto 0);
signal output_array : t_output_array(1 to MAX);
signal I : integer range 0 to MAX; -- To select in the array
begin
process( CLK )
begin
if Rising_edge( CLK ) then
block_output <= output_array(I);
end if;
end process;
end architecture A1;另一种方法是以某种方式使用generate语句。您可以尝试使用它,看看是否可以创建一个进程,将数字和列表从一个设定的范围中列出。
G1: for I in 0 to N generate
-- Component instances and/or process
end generate G1;https://stackoverflow.com/questions/58678513
复制相似问题