Verilog 数组语法

发布于 2024-10-14 19:00:06 字数 334 浏览 3 评论 0原文

我是 Verilog 新手,并且遇到了很多麻烦。例如,我想要一个包含八个单元的数组,每个单元都是 8 位宽。以下内容不起作用:

reg [7:0] transitionTable [0:7];
assign transitionTable[0] = 10;

仅执行 transitionTable[0] = 10;transitionTable[0] = 8'h10; 也不起作用 有什么想法吗?

(如果它不明显且不相关:我想制作一个有限状态机,并在数组中指定状态转换,因为这看起来比大规模的情况切换更容易。)

I'm new to Verilog, and am having a lot of trouble with it. For example, I want to have an array with eight cells, each of which is 8 bits wide. The following doesn't work:

reg [7:0] transitionTable [0:7];
assign transitionTable[0] = 10;

neither does just doing transitionTable[0] = 10; or transitionTable[0] = 8'h10; Any ideas?

(In case it is not obvious and relevant: I want to make a finite state machine, and specify the state transitions in an array, since that seems easier than a massive case switch.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

梦在深巷 2024-10-21 19:00:06

使用assign时,您应该将数组声明为wire而不是reg

When using assign you should declare the array as a wire instead of areg.

落在眉间の轻吻 2024-10-21 19:00:06

由于您的目标是设计 FSM,因此无需将状态值存储在数组中。这通常是使用 Verilog parameter's、state 寄存器和带有 case/endcase 语句的 next_state 来完成的。

以下论文显示了一个完整的示例:FSM 基础

Since your goal is to design an FSM, there is no need to store the state values in an array. This is typically done using Verilog parameter's, a state register and a next_state with a case/endcase statement.

The following paper shows a complete example: FSM Fundamentals

归途 2024-10-21 19:00:06

如果这是针对综合:

稍微超出上面回答的内容,您应该遵守标准的 FSM 编码风格,以便工具可以执行更好的优化。正如 Cummings 论文中所述,one-hot 通常最适合 FPGA 设备,事实上 ISE(使用默认设置)会忽略您的编码并实施它认为最能充分利用设备资源的任何方式。无论您选择哪种状态编码,只要它能够识别您的 FSM,这几乎总是会导致单热编码的 FSM。

If this is targeted towards synthesis:

A little beyond what was answered above, there are standard FSM coding styles that you should adhere to so the tools can perform better optimization. As described in the Cummings paper, one-hot is usually best for FPGA devices and in fact ISE(with default settings) will ignore your encoding and implement whatever it thinks will best utilize the resources on the device. This almost invariably results in a one-hot encoded FSM regardless of the state encoding you chose, provided it recognizes your FSM.

心的憧憬 2024-10-21 19:00:06

好的,为了回答您的问题,让我们更深入地了解 Verilog 语法。

首先,要指定位范围,请执行 [MSB:LSB][LSB:MSB]。标准是 MSB:LSB,但这实际上取决于您,但请尽量保持一致。

接下来,在数组实例化中,我们有:

reg WIDTH reg_name NUMBER;

,其中WIDTH是每个元素的“大小”,NUMBER是元素的数量。数组中的元素。

因此,您首先要做:

reg [7:0]transitionTable [7:0];

然后,要分配特定字节(8 位 = 1 字节),请执行以下操作:

initial begin
    transitionTable[0] = 8'h10;
end

一本学习 Verilog 的好书来自 Pong P. Chu 的FPGA Prototyping By Verilog Examples

OK, so to answer your question, let's dig a little deeper into Verilog syntax.

First of all, to specify a range of bits, either do [MSB:LSB] or [LSB:MSB]. The standard is MSB:LSB but it is really up to you here, but try to be consistent.

Next, in array instantiation we have:

reg WIDTH reg_name NUMBER;

where WIDTH is the "size" of each element and NUMBER is the number of elements in the array.

So, you first want to do:

reg [7:0] transitionTable [7:0];

Then, to assign particular bytes (8 bits = 1 byte), do:

initial begin
    transitionTable[0] = 8'h10;
end

A good book to learn Verilog from is FPGA Prototyping By Verilog Examples by Pong P. Chu.

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