J'ai essayé de faire un compteur BCD sur EDA Playground en utilisant icarus verilog pour la simulation. Dans mon premier essai, j'ai codé le always
sans utiliser le bloc begin
y end
mots-clés :
module bcdcounter(out, clock, reset);
output [3:0] out;
input clock, reset;
reg [3:0] outstate= 4'd0;
reg [1:0] state= 2'd0;
always@(posedge reset)
case(state)
2'd0: state <=2'd1;
2'd1: state <=2'd2;
2'd2: state <=2'd0;
endcase
always@(posedge clock or state)
if(!state)
outstate <= 4'd0;
if(state == 2'd1)
if(outstate != 4'd9)
outstate <= outstate +4'd1;
else
outstate <= 4'd0;
if(state == 2'd2)
outstate <= outstate;
assign out = outstate;
endmodule
et la sortie suivante a été générée pendant que je vérifiais :
design.sv:21: syntax error
design.sv:21: error: Invalid module instantiation
design.sv:23: syntax error
design.sv:23: error: Invalid module instantiation
design.sv:25: syntax error
design.sv:25: error: Invalid module instantiation
Exit code expected: 0, received: 1
Mais, une fois que j'ai ajouté quelques begin
y end
mots-clés, il a fonctionné sans erreur :
module bcdcounter(out, clock, reset);
output [3:0] out;
input clock, reset;
reg [3:0] outstate= 4'd0;
reg [1:0] state= 2'd0;
always@(posedge reset)
case(state)
2'd0: state <=2'd1;
2'd1: state <=2'd2;
2'd2: state <=2'd0;
endcase
always@(posedge clock or state)
begin
if(!state)
outstate <=4'd0;
if(state==2'd1)
begin
if(outstate!=4'd9)
outstate<= outstate+4'd1;
else outstate<= 4'd0;
end
if(state==2'd2)
outstate<=outstate;
end
assign out = outstate;
endmodule
Quand devons-nous utiliser le begin
y end
des mots-clés dans les modules de conception ? Toute aide serait appréciée.