【发布时间】:2016-03-14 04:52:34
【问题描述】:
我正在设计一个 8 位序列检测器。但是下面的代码在modelsim中编译时给了我错误
-- 编译模块 SEQDET ** 错误:F:\Modeltech_pe_edu_10.4a\examples\avlsihw5.v(30):发现一个带有空主体的开始/结束块。这在 SystemVerilog 中是允许的,但在 Verilog 中是不允许的。请寻找任何杂散的分号。 ** 错误:(vlog-13069) ** 解析宏扩展时:'A' 从 F:\Modeltech_pe_edu_10.4a\examples\avlsihw5.v(43) 开始 ** 在 F:\Modeltech_pe_edu_10.4a\examples\avlsihw5.v(43):靠近“;”:语法错误,意外的 ';',期待 ':'。
** 错误:F:\Modeltech_pe_edu_10.4a\examples\avlsihw5.v(46): (vlog-13205) 在“shiftReg”之后的范围内发现语法错误。是否缺少'::'?
Verilog 代码:
module seq_det;
wire SEQ_DETECTED;
reg [0:7] latch;
wire RST_N, SCK;
reg SCK,SDI;
SEQDET s1(SEQ_DETECTED,latch,RST_N,SDI,SCK);
clkGen #(10) cg(SCK);
//TEST at(latch,RST_N,SDI,SEQ_DETECTED,SCK);
endmodule
module SEQDET(.SEQ_DETECTED(SEQ_DETECTED),.latch(PATTERN),.RST_N(RST_N),.SDI(SDI),.SCK(SCK));
`define A 3'b000;
`define B 3'b001;
`define C 3'b100;
reg [7:0] shiftReg;
output SEQ_DETECTED;
input PATTERN;
input RST_N, SDI, SCK;
wire SEQ_DETECTED;
reg [2:0] state;
reg RST_N, SDI;
integer count, match;
initial begin
match = 0;
count = 0;
shiftReg = 8'b00000000;
RST_N = 1;
SEQ_DETECTED = 0;
state = `A;
end
always @(negedge RST_N) begin
PATTERN = {8{1'b0}};
SEQ_DETECTED = 0;
count = 0;
match = 0;
end
always @(posedge SCK)
if ( SCK && RST_N)
case (state)
`A : //begin
while(count <= 8) begin
shiftReg <= shiftReg | SDI ;
shiftReg = shiftReg >> 1;
count = count + 1;
if(count === 8)
if(shiftReg === PATTERN)
match = 1;
else
match = 0;
else ; end
state <= match ? `B : `C ;
//end
`B : //begin
count = 0;
match = 0;
shiftReg = {8{1'b0}};
SEQ_DETECTED = 1;
#20 SEQ_DETECTED = 0;
state <= `A ;
//end
`C : //begin
count = 0;
match = 0;
shiftReg = {8{1'b0}};
state <= `A ;
//end
endcase
endmodule
module clkGen(SCK);
output SCK;
parameter period = 10;
reg SCK;
initial SCK = 0;
always
#(period/2) SCK = ~SCK;
endmodule
【问题讨论】: