首页 > 其他 > 详细

序列检测101 状态机实现

时间:2016-07-06 21:27:07      阅读:210      评论:0      收藏:0      [点我收藏+]

module jiance #

(
parameter CNT_NUM = 12500000
)

( clk,rst_n,data, clk_1hz,out);
input clk,rst_n,data;
output reg out,clk_1hz;
reg [1:0] cstate,nstate;
parameter s0=2‘b00,
s1=2‘b01,
s2=2‘b10;

reg [24:0] cnt = 25‘d0;
//reg clk_1hz = 1‘b0;
always@(posedge clk or negedge rst_n) begin
if(!rst_n) begin
cnt <= 25‘d0;
clk_1hz <= 1‘b0;
end else if(cnt>=(CNT_NUM-1)) begin
cnt <= 25‘d0;
clk_1hz <= ~clk_1hz;
end else begin
cnt <= cnt + 25‘d1;
end
end
always@(posedge clk_1hz or negedge rst_n)
if(!rst_n) cstate<=s0;
else cstate<=nstate;
always@(posedge clk_1hz or negedge rst_n)
begin
if(!rst_n)nstate<=s0;
else begin

case(cstate)
s0:nstate <=(data)?s1:s0;
s1:nstate<=(data)?s1:s2;
s2:nstate<=(data)?s1:s0;
default:nstate<=s0;
endcase
end
end
always@(posedge clk_1hz or negedge rst_n)
begin
if(!rst_n)out<=0;
else
case(nstate)
s0:out<=0;
s1:out<=0;
s2:begin if(data==1)out<=1;
else out<=0;end
default:out<=0;
endcase
end
endmodule

序列检测101 状态机实现

原文:http://www.cnblogs.com/xinshuwei/p/5647956.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!