重置Verilog代码

时间:2015-11-29 20:25:25

标签: verilog

此程序显示S然后关闭然后G然后关闭。该程序有效,但重置不起作用。波形中存在一些错误。我知道时钟到来时y值的问题,但我不知道如何解决它。

module proj200 (output wire [6:0]a2g,output wire [3:0]AN,input wire fastclk,input reset); 
wire slowclk;
wire y;
slow_clock xx(fastclk,slowclk);
yinput za(slowclk,y);
hex7segm zz(slowclk,y,reset,a2g,AN);
endmodule

module slow_clock (input wire fastclk,output wire slowclk);
reg[1:0]period_count=0;
always@(posedge fastclk)
begin

period_count<=period_count+1;

end
assign slowclk=period_count[1];

endmodule




module hex7segm (input wire slowclk,input wire y,input reset,
output reg [6:0]a2g,
output reg [3:0]AN
); 
reg[1:0]x;
always@(*)
begin
if(slowclk==1 && reset==0)
begin x=2;
AN= 4'b1110;
end
else if(slowclk==0 && reset==0)

    begin
x=y;
AN= 4'b1110;
end   

else if(reset==1&& slowclk==0)
    begin 

        x=0;
        AN= 4'b1110;
end

else if(reset==1 && slowclk==1) 
    begin 

        x=0;
        AN= 4'b1110;
        end


case(x)
0: a2g=7'b0100100;
1: a2g=7'b0100000;
2: a2g=7'b1111111;
default: a2g=7'b0100100;
endcase
end
endmodule


module yinput(input wire slowclk,output wire y);
reg[1:0]period_count=0;
always@(posedge slowclk )
begin

period_count<=period_count+1;

end
assign y=period_count[0];

endmodule

1 个答案:

答案 0 :(得分:0)

您的重置当前正在执行任何操作,但屏蔽输出(即,强制xAN为某个默认值)。它对包含period_count的寄存器无效(后者又决定yslowclk)。现在,您需要确定是否需要同步(时钟之后的复位)或异步复位(独立于时钟的复位)。以下是两者的例子:

同步

reg [1:0] period_count; // Dont need this initialization, a reset will do it for you
always @(posedge fastclk) begin
  if (reset)
    period_count <= 0;
  else
    period_count <= period_count+1;
end

异步

reg [1:0] period_count; // Dont need this initialization, a reset will do it for you
always @(posedge fastclk, posedge reset) begin // Note the new item in the sensitivity list
  if (reset)
    period_count <= 0;
  else
    period_count <= period_count+1;
end

请注意,reset必须成为其他模块的输入,您可以将reset从其当前所在的模块中取出,因为该模块只是组合。如果你想要其他一些行为,你将不得不澄清这一点。