重置Verilog代码的输出
该程序先显示S,然后显示off,然后显示G,最后显示off。程序工作正常,但重置不能完美工作。波形中有一些错误。我知道当时钟到来时,y值中的问题,但我不知道如何解决它重置Verilog代码的输出,verilog,Verilog,该程序先显示S,然后显示off,然后显示G,最后显示off。程序工作正常,但重置不能完美工作。波形中有一些错误。我知道当时钟到来时,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);
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
模块proj200(输出线[6:0]a2g,输出线[3:0]AN,输入线fastclk,输入复位);
钢丝慢行;
导线y;
慢时钟xx(快时钟、慢时钟);
银普扎(slowclk,y);
hex7segm zz(慢行、y、复位、a2g、AN);
端模
模块慢时钟(输入线fastclk,输出线slowclk);
reg[1:0]周期计数=0;
始终@(posedge fastclk)
开始
period_count您的重置当前只是屏蔽输出(即,强制x
和AN
为某个默认值)。它对包含period\u count
的寄存器没有任何作用(这反过来决定y
和slowclk
)。现在,您需要确定是要同步(时钟后的重置)还是异步重置(独立于时钟的重置)。以下是两者的示例:
同步的
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
reg[1:0]周期计数;//不需要此初始化,重置将为您完成此操作
始终@(posedge fastclk)开始
如果(重置)
period_count@BaderAloraini你是什么意思?同步块我应该使用单独的模块吗?@BaderAloraini不,我只是重写了你自己的always块(其中你有2个)来实现同步重置。它不需要自己的模块;如果(slowclk==0&&reset==0)开始x=y,则结束else;如果(重置==1&&slowclk==0)开始x=y,则结束else;如果(重置==1&&slowclk==1)开始x=y,则结束else;端盖(x)2'b00:a2g=7'b0100100;2'b01:a2g=7'b0100000;2'b10:a2g=7'b1111111;2'b11:a2g=7'b1111111;默认值:a2g=7'b0100100;endcase end module yinput reg[1:0]周期计数=0;总是@(posedge slowclk或NEGDEDGE slowclk)如果(重置==0)周期计数开始这是我在得到答案之前想到的。知道为什么不对吗。我总是把y赋值给x