verilog 中的操作数

Operands in verilog

我正在尝试使用 Verilog 实现 PID 控制器,但我在编码时遇到了一些问题。

我尝试将位置设置为 parameter,如屏幕截图所示:

但是,我遇到了一个我不知道的错误:

错误 1:-

Error (10170): Verilog HDL syntax error at Verilog1.v(16) near text: "[";  expecting an operand. Check for and fix any syntax errors that appear immediately before or at the specified keyword. The Intel FPGA Knowledge Database contains many articles with specific details on how to resolve this error. Visit the Knowledge Database at https://www.altera.com/support/support-resources/knowledge-base/search.html and search for this specific error message number.

错误2:-

Error (10170): Verilog HDL syntax error at Verilog1.v(34) near text: "[";  expecting "@", or an operand. Check for and fix any syntax errors that appear immediately before or at the specified keyword. The Intel FPGA Knowledge Database contains many articles with specific details on how to resolve this error. Visit the Knowledge Database at https://www.altera.com/support/support-resources/knowledge-base/search.html and search for this specific error message number.

我也试过integer position= [0*IRL+1000*CIR+2000*IRR];,但我还是遇到了同样的问题。如何修复此语法错误?

假设IRLCIRIRR被声明为常量类型(如parameter),那么你应该去掉方括号:

parameter position = 0*IRL+1000*CIR+2000*IRR;

编译后,参数值只能读取;未修改。它们是运行时常量。 integer 类型只能在程序块内分配。你可以在声明时给它一个初始值,但它不会自动更新。所以你想要一个过程分配或一个连续分配的网络类型。

方括号 ([]) 用于索引数组或向量切片。它们不能像圆括号 (()) 或大括号 ({}) 那样使用。在你的情况下不需要。

变化:

integer position=  [0*IRL+1000*CIR+2000*IRR];

收件人:

wire [31:0] position=  0*IRL+1000*CIR+2000*IRR;

或:

wire [31:0] position;
assign position=  0*IRL+1000*CIR+2000*IRR;

或:

integer position;
always @* begin
  position=  0*IRL+1000*CIR+2000*IRR;
end

同时更改:

Proportional<= [position/IRL+CIR+IRR]-1000;

收件人:

Proportional<= (position/IRL+CIR+IRR)-1000;