VHDL:切片数组的各个部分 [英] VHDL: slice a various part of an array

查看:24
本文介绍了VHDL:切片数组的各个部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 STD_LOGIC_VECTOR(0 到 639).在传入信号上,我必须遍历这个向量并获得它的下 2 位.

I have a STD_LOGIC_VECTOR (0 to 639). On an incoming signal I have to iterate through this vector and get next 2 bits of it.

我正在尝试使用整数counter来做类似的事情:

I'm trying to make something like, with an integer counter:

counter := counter+1;
MyVar := Data((counter*2) to ((counter*2)+1));

我得到以下信息:

错误 (10394):module.vhd(227) 处的 VHDL 错误:范围的左边界必须是常数

Error (10394): VHDL error at module.vhd(227): left bound of range must be a constant

upd:@user1155120 提出以下建议:将向量的每一位写入 MyVar 的每一位对应位

upd: the following was suggested by @user1155120: writing every single bit of vector to every single corresponding bit of MyVar

MyVar(0) := Data(counter * 2);
MyVar(1) := Data(counter * 2 + 1);

只要我使用 2 位 MyVar 就可以正常工作,但是如果我想使用 16-32-80 位变量怎么办?问题避免了,但没有解决.

Works fine as long as I use the 2bit MyVar, but what if i want to use a 16-32-80bit variable? Problem avoided, but not solved.

推荐答案

谷歌搜索显示错误消息来自 Quartus II(参见 ID:10394).它提供的 LRM 参考并不是特别有用,这是对合成的限制,您无法为多路复用器定义可变宽度的字长.不够聪明,无法检测到引用计数器的两个边界.

Googling shows the error message is from Quartus II (See ID: 10394). The LRM reference it provides isn't particularly helpful, it's a limitation on synthesis that you can't define a variable width word size for a multiplexer. Not smart enough to detect both bounds are referenced to counter.

如果你分别为 MyVar 的每一位表达一个多路复用器会发生什么?(索引名称而不是切片名称,两个变量赋值给 MyVar(1)MyVar(0)).

What happens if you express a multiplexer for each bit of MyVar separately? (Indexed name instead of slice name, two variable assignments to MyVar(1) and MyVar(0)).

MyVar(0) := Data(counter * 2);
MyVar(1) := Data(counter * 2 + 1);

这个线程需要帮助解决奇怪的错误"范围的左边界必须是常量 " 建议使用循环来分配目标切片范围的每一位,这也是在每个元素的基础上使用索引名称.

This thread need a help with strange error" left bound of the range must be a constant " suggests using a loop to assign each bit of the target slice range, which is also using an indexed name on a per element basis.

for i in MyVar'RANGE loop
    MyVar(i) := Data(counter * 2 + i);
end loop;

counter 只需要索引范围的一半,你总是把它乘以 2.

counter only needs half the index range, you're always multiplying it by 2.

这篇关于VHDL:切片数组的各个部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆