|
module counter256_2(clk,q, reset,clock);
input clock; //system clock;
input reset;
input clk;
output[7:0] q;
reg[7:0] count;
reg[1:0] state;
parameter idle=2'b00, low=2'b01, high=2'b11;
initial
begin
count = 8'd0;
state = idle;
end
assign q[7:0] = count[7:0];
always @(posedge clock )
begin
if(!reset)
begin
count <= 8'd0;
state <= idle;
end
else
begin
case(state)
idle:
if(!clk)begin
//count<= 8'd0; //statemachine goes wrong when it exists;
state <= low;
end
else
begin
//count<= 8'd0; //statemachine goes wrong when it exists;
state <= idle;
end
low:
if(clk)begin
count <= count + 8'd1;
state <= high;
end
else
begin
count <= count;
state <= low;
end
high:
if(!clk)begin
count <= count;
state <= low;
end
else
begin
count <= count;
state <=high;
end
default:
begin
count <=count;
state <= state;
end
endcase
end
end
endmodule
用来实现0:255的计数
中间注释两行不去掉时count频繁清零
两个不同的状态机的生成的原理图pdf 附件 里
求解 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|