状态机基础知识












VL25 输入序列连续的序列检测
`timescale 1ns/1ns
module sequence_detect(
input clk,
input rst_n,
input a,
output reg match
);
//这题就是普通的状态机,需要注意的是:
// @当输入不能跳转到下一个状态时,可以复用前面的序列
// @这题是的Moore状态机,输出只和当前状态有关
//定义状态空间(状态参数、状态寄存器)
parameter IDLE = 0 ;
parameter S0 = 1 ;
parameter S1 = 2 ;
parameter S2 = 3 ;
parameter S3 = 4 ;
parameter S4 = 5 ;
parameter S5 = 6 ;
parameter S6 = 7 ;
parameter S7 = 8 ;
reg [3:0] curr_state,next_state;
// 1.打一拍更新现态
always@(posedge clk or negedge rst_n) begin
if(~rst_n) begin
curr_state <= IDLE;
end else begin
curr_state <= next_state;
end
end
// 2.组合逻辑根据现态和输入生成次态
always@(*) begin
case(curr_state)
IDLE : next_state = (a == 0) ? S0 : IDLE ;
S0 : next_state = (a == 1) ? S1 : S0 ;
S1 : next_state = (a == 1) ? S2 : S0 ;
S2 : next_state = (a == 1) ? S3 :

最低0.47元/天 解锁文章
8489

被折叠的 条评论
为什么被折叠?



