VHDL 中的信号和变量(顺序)- 问题
我有一个信号,这个信号是一个位向量(Z)。位向量的长度取决于输入n,它不是固定的。为了找到长度,我必须做一些计算。我可以在定义变量后定义信号吗?当我这样做时,它给了我错误。如果我将信号保留在变量之前(如下所示),它工作得很好..但我不希望这样.. Z 的长度取决于变量的计算。解决办法是什么?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity BSD_Full_Comp is
Generic (n:integer:=8);
Port(X, Y : inout std_logic_vector(n-1 downto 0);
FZ : out std_logic_vector(1 downto 0));
end BSD_Full_Comp;
architecture struct of BSD_Full_Comp is
Component BSD_BitComparator
Port ( Ai_1 : inout STD_LOGIC; Ai_0 : inout STD_LOGIC;
Bi_1 : inout STD_LOGIC; Bi_0 : inout STD_LOGIC;
S1 : out STD_LOGIC; S0 : out STD_LOGIC
);
END Component;
Signal Z : std_logic_vector(2*n-3 downto 0);
begin
ass : process
Variable length : integer := n;
Variable pow : integer :=0 ;
Variable ZS : integer :=0;
begin
while length /= 0 loop
length := length/2;
pow := pow+1;
end loop;
length := 2 ** pow;
ZS := length - n;
wait;
end process;
end struct;
I have a signal and this signal is a bitvector (Z). The length of the bitvector depends on an input n, it is not fixed. In order to find the length, I have to do some computations. Can I define a signal after defining the variables ? It is giving me errors when I do that. It is working fine If I keep the signal before the variables (that what is showing below) .. but I don't want that .. the length of Z depends on the computations of the variables. What is the solution ?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity BSD_Full_Comp is
Generic (n:integer:=8);
Port(X, Y : inout std_logic_vector(n-1 downto 0);
FZ : out std_logic_vector(1 downto 0));
end BSD_Full_Comp;
architecture struct of BSD_Full_Comp is
Component BSD_BitComparator
Port ( Ai_1 : inout STD_LOGIC; Ai_0 : inout STD_LOGIC;
Bi_1 : inout STD_LOGIC; Bi_0 : inout STD_LOGIC;
S1 : out STD_LOGIC; S0 : out STD_LOGIC
);
END Component;
Signal Z : std_logic_vector(2*n-3 downto 0);
begin
ass : process
Variable length : integer := n;
Variable pow : integer :=0 ;
Variable ZS : integer :=0;
begin
while length /= 0 loop
length := length/2;
pow := pow+1;
end loop;
length := 2 ** pow;
ZS := length - n;
wait;
end process;
end struct;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您正在尝试根据计算结果更改硬件总线的大小?请记住,一旦编译电路并将其刻录到 FGPA 上,所有总线大小都是固定的。 FPGA 可以动态更改其配置,但我猜想很多时候没有必要。我猜想这也很难做到。
也许解释一下你到底想计算什么,也许我们可以想出一种不同的方法。
其他一些事情。我不是 100% 熟悉 VHDL,但是您需要双向端口(
inout
)吗?另外,您似乎没有使用BSD_BitComparator
;或端口X
、Y
或FZ
;或在架构描述中发出Z
信号。Looks like you're trying to change the size of a hardware bus depending on the result of calculation? Remember that once you compile the circuit and burn it on to the FGPA, all your bus sizes are fixed. It's possible to have an FPGA change it's configuration on the fly, but I'd guess that it's not necessary a lot of the time. And I'd guess that it's tricky to do, too.
Maybe explain what exactly you are trying to calculate, and maybe we can come up with a different way of doing it.
A few other things. I'm not 100% familiar with VHDL, but do you need the bi-directional ports (the
inout
s)? Also, you don't seem to be usingBSD_BitComparator
; or portsX
,Y
orFZ
; or signalZ
in your architecture description.它是固定的,它是通用的。一旦您编译并详细说明(即构建)了 FPGA,
n
就固定了。没关系,您可以使用它来定义架构内信号的长度。与其他受访者一样,我不确定您想对流程做什么。您是否正在尝试计算 Z 信号所需的长度?
如果是这样,您可以将其放在一个函数中,并在 Z 的声明中使用该函数:
signal Z:std_logic_vector(calc_z_high_bit(n) downto 0);
It is fixed, it's a generic. Once you've compiled and elaborated (ie built) the FPGA,
n
is fixed. And that's fine, you can use that to define the lengths of signals within the architecture.As with the other respondent, I'm not sure what you're trying to do with your process. Are you trying to calculate the length that the Z signal will need to be?
If so, you can put it in a function, and use the function in the declaration of Z:
signal Z:std_logic_vector(calc_z_high_bit(n) downto 0);
泛型在编译/阐述时是固定的。变量可以在运行时更改。所以,你的目标并不是按照你试图实现的方式直接实现的。
如果要动态指定总线的某些位片,则需要将总线定义为最大的总线,然后使用计算出的 n 来复用所需的总线片。
A generic is fixed at compile/elaboration time. A variable can change during runtime. So, what you are aiming for isn't directly possible they way you are trying to do it.
If you want to dynamically specify some bitslice of the bus, you would need to define the bus to be the biggest it can be, and then use your computed n to mux out the slice of the bus you need.