Syntax verilog中的操作数

Syntax verilog中的操作数,syntax,syntax-error,verilog,system-verilog,Syntax,Syntax Error,Verilog,System Verilog,我试图使用Verilog实现PID控制器,但在编码过程中遇到了一些问题 我尝试将位置设置为参数,如屏幕截图所示: 但是,我遇到了一个我不知道的错误: 错误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

我试图使用Verilog实现PID控制器,但在编码过程中遇到了一些问题

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

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

错误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],但我仍然面临同样的问题。如何修复此语法错误?

假设
IRL
CIR
IRR
声明为常量类型(如
参数
),则应删除方括号:

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

编译后,只能读取参数值;没有修改。它们是运行时常量。只能在程序块内指定
整数
类型。您可以在声明时给它一个初始值,但它不会自动更新。因此,您需要一个过程赋值或一个具有连续赋值的网络类型

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

更改:

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

或:

或:


也改变了:

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

比例
IRL
CIR
IRR
是输入。完整形式:-IRL=左红外传感器,CIR=中心红外传感器,IRR=右红外传感器。@UnparedElectron:如果您指的是
输入
端口,则这是非法语法。正如我所说,您必须使用常量,而不是变量。
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;