|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
- module cnt10(clk,rst,en,add_sub,q,cout); //十进制计数器
- input clk,rst,en,add_sub;
- reg [3:0]q1,q2;
- reg c1,c2;
- output reg[3:0] q;
- output reg cout;
- always@(posedge clk or posedge rst)
- if(rst)
- begin
- q1<=0;
- c1<=0;
- end
- else
- if(en==0)
- if(add_sub)
- if(q1==9)
- begin q1<=0; c1<=1; end
- else
- begin q1<=q1+4'b0001; c1<=0; end
- else //实现倒计时
- if(q1==0)
- begin q1<=9;c1<=1; end
- else
- begin q1<=q1-4'b0001;c1<=0; end
- always@(posedge clk or posedge rst)
- //实现秒表功能
- begin
- if(rst)
- begin
- q2<=0;
- c2<=0;
- end
- else if(en)
- if(add_sub==0)
- if(q2==9)
- begin q2<=0; c2<=1; end
- else
- begin q2<=q2+4'b0001; c2<=0; end
- end
- always@(posedge clk) //秒表和倒计时互相转换
- begin
- if(en)
- begin q<=q2; cout<=c2; end
- else
- begin q<=q1; cout<=c1; end
- end
- endmodule
- module cnt6(clk,rst,en,add_sub,q,cout);
- input clk,rst,en,add_sub;
- reg [3:0]q1,q2;
- reg c1,c2;
- output reg[3:0] q;
- output reg cout;
- always@(posedge clk or posedge rst)
- if(rst)
- begin
- q1<=0;
- c1<=0;
- end
- else
- if(en==0)
- if(add_sub)
- if(q1==5)
- begin q1<=0; c1<=1; end
- else
- begin q1<=q1+4'b0001; c1<=0; end
- else //实现倒计时
- if(q1==0)
- begin q1<=5;c1<=1; end
- else
- begin q1<=q1-4'b0001;c1<=0; end
- always@(posedge clk or posedge rst)
- //实现秒表功能
- begin
- if(rst)
- begin
- q2<=0;
- c2<=0;
- end
- else if(en)
- if(add_sub==0)
- if(q2==5)
- begin q2<=0; c2<=1; end
- else
- begin q2<=q2+4'b0001; c2<=0; end
- end
- always@(posedge clk) //秒表和倒计时互相转换
- begin
- if(en)
- begin q<=q2; cout<=c2; end
- else
- begin q<=q1; cout<=c1; end
- end
- endmodule
复制代码 问题是:分析不出来为什么从en=1,add_sub=0到en=0,add_sub=1的时候应该是继续加一的,但仿真出来又不是!!!大神你在哪??? |
-
综合模块
-
仿真波形
|