sequence_dectect.v
上传用户:saul_905
上传日期:2013-11-27
资源大小:184k
文件大小:2k
源码类别:

VHDL/FPGA/Verilog

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////
  2. ////////Module name:sequence_detect                                                      ////////
  3. ////////Function         :detect the sequence  101110 in the data stream////////
  4. ////////Author             :Xiaoming Chen                                                         ////////
  5. ////////Date                 :18/12/2002                                                             ////////
  6. /////////////////////////////////////////////////////////////////
  7. `timescale 1ns/100ps
  8. module sequence_dectect(in,         //the input data stream
  9.                                                 out,        //the output signal when detect a 101110 sequence
  10.                                                 clock,     //clock signal
  11.                                                 reset);  //reset signal
  12.                                                 
  13. input                     in,clock,reset;
  14. output                  out;
  15. reg          [2:0]     state;
  16. wire                      out;
  17. parameter          START=3'b000,          //the initial state
  18.                              A         =3'b001,          //state A
  19.                              B         =3'b010,          //state B
  20.                              C         =3'b011,          //state C
  21.                              D         =3'b100,          //state D
  22.                              E         =3'b101,          //state E
  23.                              F         =3'b110;          //state F
  24.                 
  25.  assign out=(state==E&&in==0)?1:0;    
  26.             
  27.  always@(posedge clock or negedge reset)
  28.     if(!reset)
  29.               begin
  30.               state<=START;
  31.               end
  32.      else
  33.          casex(state)
  34.                START : if(in==1) state<=A;
  35.                
  36.                 A    : if(in==0) state<=B;
  37.                        else      state<=A;
  38.                        
  39.                 B    : if(in==1) state<=C;
  40.                        else      state<=A;
  41.                        
  42.                 C    : if(in==1) state<=D;
  43.                        else      state<=B;
  44.                        
  45.                 D    : if(in==1) state<=E;
  46.                        else      state<=B;
  47.                        
  48.                 E    : if(in==0) state<=F;
  49.                        else      state<=A;
  50.                        
  51.                 F    : if(in==1) state<=C;
  52.                        else      state<=A;
  53.                        
  54.                 default:state=START;
  55.           endcase
  56.                                        
  57. endmodule