vhdl - 如何以通用方式编写此代码(使用可以在每个项目中递增的计数器的状态机)
问题描述
我正在尝试以通用方式编写此代码。有没有办法用通用表达式替换数字。(1,2,3..max) “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;
解决方案
有点变通,但是您可以将所有变量放入一个数组中,然后从该数组中选择变量吗?您必须将变量放入数组中。我没有尝试编译它,但它应该看起来像这样。
假设输出是一个 slv(7 downto 0) 并且你有通用的 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;
另一种方法是以某种方式使用生成语句。您可以尝试使用它来查看是否可以创建一个从设定范围内列出数字和列表的过程。
G1: for I in 0 to N generate
-- Component instances and/or process
end generate G1;
推荐阅读
- reactjs - 如何防止 material-ui 包覆盖我的应用程序样式?
- vba - 我在使用 VBA 转 PDF Adobe Acrobat DC 时遇到问题“不支持此类接口”错误
- scala - 关于 Spark,在哪些情况下我们希望每个工作节点中有多个执行器?
- css - bookdown:更改定理类型块标签的颜色
- uwp - 在 UWP TextBlock 内的 Run 上更改光标
- asp.net-core - 验证不解析的值时模型绑定器崩溃
- graph - Neo4J 自我查找
- reactjs - 如何为img标签设置默认图像以防src在反应中无效
- javascript - 使用 heroku API 调用 DELETE config-vars 的端点
- r - 使用广义估计方程对具有总体偏移的结果进行建模