码迷,mamicode.com
首页 > 其他好文 > 详细

序列检测101 状态机实现

时间:2016-07-06 21:28:19      阅读:283      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!