VHDL 中的信号和变量(顺序)- 问题

发布于 2024-09-04 06:09:41 字数 1063 浏览 3 评论 0原文

我有一个信号,这个信号是一个位向量(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丢了幸福的猪 2024-09-11 06:09:41

看起来您正在尝试根据计算结果更改硬件总线的大小?请记住,一旦编译电路并将其刻录到 FGPA 上,所有总线大小都是固定的。 FPGA 可以动态更改其配置,但我猜想很多时候没有必要。我猜想这也很难做到。

也许解释一下你到底想计算什么,也许我们可以想出一种不同的方法。

其他一些事情。我不是 100% 熟悉 VHDL,但是您需要双向端口(inout)吗?另外,您似乎没有使用 BSD_BitComparator;或端口 XYFZ;或在架构描述中发出 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 inouts)? Also, you don't seem to be using BSD_BitComparator; or ports X, Y or FZ; or signal Z in your architecture description.

尤怨 2024-09-11 06:09:41

位向量的长度取决于
输入n,它不固定。

固定的,它是通用的。一旦您编译并详细说明(即构建)了 FPGA,n 就固定了。没关系,您可以使用它来定义架构内信号的长度。

与其他受访者一样,我不确定您想对流程做什么。您是否正在尝试计算 Z 信号所需的长度?

如果是这样,您可以将其放在一个函数中,并在 Z 的声明中使用该函数:

signal Z:std_logic_vector(calc_z_high_bit(n) downto 0);

The length of the bitvector depends on
an input n, it is not fixed.

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);

人间不值得 2024-09-11 06:09:41

泛型在编译/阐述时是固定的。变量可以在运行时更改。所以,你的目标并不是按照你试图实现的方式直接实现的。

如果要动态指定总线的某些位片,则需要将总线定义为最大的总线,然后使用计算出的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文