上面是数字跑表计数器模块
仿真图,分十位MH计时到5后仍然继续计数,请大神指点这个问题怎么解决。
下面是程序:
module jishuqi(clk_100hz,reset,pause,MH,ML,SH,SL,MSH,MSL);
input clk_100hz,reset,pause;
output reg [3:0]MH;
output reg [3:0]ML;
output reg [3:0]SL;
output reg [3:0]SH;
output reg [3:0]MSL;
output reg [3:0]MSH;
reg cnt_ms;
reg cnt_s;
always@(posedge clk_100hz or negedge reset)
begin
if(!reset)
begin
MSL<=4'd0;
MSH<=4'd0;
cnt_ms<=1'b0;
end
else
begin
if(!pause)
begin
if(MSL==9)
begin
if(MSH==9)
begin
MSL<=4'd0;
MSH<=4'd0;
cnt_ms<=1'b1;
end
else
begin
MSL<=0;
MSH<=MSH+1'b1;
cnt_ms<=1'b0;
end
end
else
begin
MSL<=MSL+1'b1;
cnt_ms<=1'b0;
end
end
end
end
always@(posedge cnt_ms or negedge reset)
begin
if(!reset)
begin
SL<=4'd0;
SH<=4'd0;
cnt_s<=1'b0;
end
else
begin
if(!pause)
begin
if(SL==9)
begin
if(SH==5)
begin
cnt_s<=1'b1;
SH<=4'd0;
SL<=4'd0;
end
else
begin
cnt_s<=1'b0;
SH<=SH+1'b1;
SL<=4'd0;
end
end
else
begin
SL<=SL+1'b1;
cnt_s<=1'b0;
end
end
end
end
always@(posedge cnt_s or negedge reset)
begin
if(!reset)
begin
ML<=4'd0;
MH<=4'd0;
end
else
begin
if(!pause)
begin
if(ML==9)
begin
if(MH==5)
begin
MH<=4'd0;
ML<=4'd0;
end
else
ML<=4'd0;
MH<=MH+1'b1;
end
else
begin
ML<=ML+1'b1;
end
end
end
end
endmodule
begin1
if(!pause)
begin2
if(ML==9)
begin3
if(MH==5)
begin4
MH<=4'd0;
ML<=4'd0;
end4
else begin5
ML<=4'd0;
MH<=MH+1'b1;
end5
这里是不是少了一个end呢?对应begin3
else
begin6
ML<=ML+1'b1;
end6
end对应if(!pause)的begin2
end对应else的begin1
end对应module的begin
所以说这样的模块写的不好,应该分开写的。ML一个模块。MH一个模块,把verilog当C语言写了。。
一周热门 更多>