Xilinx FPGA:vivado测试Moore与mealy的区别 序列检测:“101“

`timescale 1ns / 1ps
/*
测试Moore与mealy的区别   序列检测:"101"
*/
module test_moore_mealy(
    input           sysclk          ,
    input           rst_n           ,
    input           din             ,
    output  reg     vaild_re        ,
    output  reg     vaild_ly        
    );
///moore
localparam          IDLE    = 3'd0;
localparam          D_1     = 3'd1;
localparam          D_10    = 3'd3;
localparam          D_101   = 3'd4;
reg     [2:0]       cur_state1,next_state1;
//ate1
always@(posedge sysclk)
    if(!rst_n)
        cur_state1 <= IDLE;
    else
        cur_state1 <= next_state1;
//ate2
always@(*)
    case(cur_state1)
         IDLE  : begin
            if(din == 1)
                next_state1 = D_1;
            else
                next_state1 = cur_state1;
         end   
         D_1   :begin
            if(din == 0)
                next_state1 = D_10;
            else
                next_state1 = cur_state1;
         end 
         D_10  :begin
            if(din == 1)
                next_state1 = D_101;
            else
                next_state1 = IDLE;
         end 
         D_101 :begin
            if(din == 1)
                next_state1 = D_1;
            else
                next_state1 = D_10;
         end
         default:;  
    endcase
//ate3
always@(posedge sysclk)
    if(!rst_n)
        vaild_re <= 0;
    else
        case(cur_state1)
             IDLE  : vaild_re <= 0;
             D_1   : vaild_re <= 0;
             D_10  : vaild_re <= 0;
             D_101 : vaild_re <= 1; 
             default:;         
        endcase  
///mealy
localparam          IDLE_ly    = 3'd0;
localparam          D_1_ly     = 3'd1;
localparam          D_10_ly    = 3'd3;
reg     [2:0]       cur_state2,next_state2;
//ate1
always@(posedge sysclk)
    if(!rst_n)
        cur_state2 <= IDLE_ly;
    else
        cur_state2 <= next_state2;
 //ate2
always@(*)
    case(cur_state2)
         IDLE_ly  : begin
            if(din == 1)
                next_state2 = D_1_ly;
            else
                next_state2 = cur_state2;
         end   
         D_1_ly   :begin
            if(din == 0)
                next_state2 = D_10_ly;
            else
                next_state2 = cur_state2;
         end 
         D_10_ly  :begin
            if(din == 1)
                next_state2 = D_1_ly;
            else
                next_state2 = IDLE_ly;
         end 
         default:;  
    endcase
//ate3
always@(posedge sysclk)
    if(!rst_n)
        vaild_ly <= 0;
    else
        case(cur_state2)
             IDLE_ly  : vaild_ly <= 0;
             D_1_ly   : vaild_ly <= 0;
             D_10_ly  : vaild_ly <= (cur_state2 == D_10_ly && din == 1) ? 1 : 0;
             default:;         
        endcase   
endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值