Binary Pattern Detector

Embed Size (px)

Citation preview

  • 7/29/2019 Binary Pattern Detector

    1/5

    1 of 5

    Johannah Mae D. Abestano ECE 195

    Binary Pattern Detector Finite State Machine

    Finite State Diagram

    At state IDLE if the input is 0, then it goes to the first state, which is state 0. Otherwise, it remains in the IDLE

    state. At state 0, if the input is 0, it remains at state 0. However, if the input is 1, then it proceeds to state 1. At state 1 if

    the input is 0, then it goes back to state 0, else, if the input is 1, it goes to state 2. At state 2, if the input is 1, it goes to

    state 3, else it goes back to state 0. At state 3, if the input is 0, it goes to state 4, else it goes to state IDLE. At state 4, if

    the input is 0, it goes to State 0. Else, it goes to state 1. Thus completing the cycle of the state machine.

    Wave Form Diagram

    Detect pattern 01110

  • 7/29/2019 Binary Pattern Detector

    2/5

    2 of 5

    BinaryPatternDetector.v

    `timescale1ns/1ps//////////////////////////////////////////////////////////////////////////////////// Company: MSU-IIT// Engineer: Johannah Mae D. Abestano//// Create Date: 07:37:37 02/01/2013// Design Name:// Module Name: BinaryPatternDetector// Project Name: BinaryPatternDetector// Target Devices: Any

    // Tool versions: Any// Description: Detects binary pattern in the input stream which is 01110.//// Dependencies: N/A//// Revision: 0001// Revision 0.01 - File Created// Additional Comments: N/A////////////////////////////////////////////////////////////////////////////////////module BinaryPatternDetector(

    clk,stream,rst,enable,

    detected);

    /* PORT DECLARATION */input clk;input stream;input rst;input enable;output detected;

    /* INPUT WIRES */wire clk;wire stream;wire rst;wire enable;

    /* PARAMETERS */// list of states. please refer to the FSM diagram in the// documentation of this code.parameter SS_IDLE =6'b000001;parameter STATE_0 =6'b000010;parameter STATE_1 =6'b000100;parameter STATE_2 =6'b001000;parameter STATE_3 =6'b010000;parameter STATE_4 =6'b100000;

    /* INTERNAL REGISTERS, NEITHER INPUT NOR OUTPUT */// current state INTERNAL variable. neither OUTPUT nor INPUT,

  • 7/29/2019 Binary Pattern Detector

    3/5

    3 of 5

    // just an internal variable to hold the current state of the// finite state machine.reg[5:0] current_state;reg[5:0] nxt_state;

    assign detected =((current_state==STATE_4 && nxt_state==STATE_0)||(current_state==STATE_4 && nxt_state==STATE_1));

    always@(posedge clk ornegedge rst)beginif(rst)begin

    current_state

  • 7/29/2019 Binary Pattern Detector

    4/5

    4 of 5

    BinaryPatternDetector_tb.v

    `timescale1ns/1ps

    ////////////////////////////////////////////////////////////////////////////////// Company: MSU-IIT// Engineer: Johannah Mae D. Abestano//// Create Date: 07:40:04 02/01/2013// Design Name: BinaryPatternDetector// Module Name: BinaryPatternDetector/BinaryPatternDetector_tb.v

    // Project Name: BinaryPatternDetector// Target Device: Any// Tool versions: Any// Description: Detects binary pattern in the input stream which is 01110.//// Verilog Test Fixture created by ISE for module: BinaryPatternDetector//// Dependencies://// Revision: 0001// Revision 0.01 - File Created// Additional Comments://////////////////////////////////////////////////////////////////////////////////

    module BinaryPatternDetector_tb;

    // Inputsreg clk;reg stream;reg rst;reg enable;

    // Outputswire detected;

    // Instantiate the Unit Under Test (UUT)BinaryPatternDetector uut (

    .clk(clk),

    .stream(stream),

    .rst(rst),

    .enable(enable),

    .detected(detected));

    initialbegin// Initialize Inputs. All variables are set to 0.clk =0;stream =0;rst =1;enable =0;

    // Wait 100 ns for global rst to finish#110;

    // Test inputs. Note the enable is 0. so the device should not detect even the// pattern is present. the device is simply turned off in this state.#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =1;#20 stream =0;#20 stream =0;#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =0;

    // Turn on the device by setting enable as 1// and making sure reset is low.enable =1;rst =0;

    // Test stream input. The output detector switch should rise when the pattern// 01110 is detected. The output is low when the pattern is still not detected.

  • 7/29/2019 Binary Pattern Detector

    5/5

    5 of 5

    // note that the device is turned on as noted by the previous comment. so the// device will detect patterns this time.#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =1;#20 stream =0;// 1#20 stream =0;#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =0;#20 stream =0;#20 stream =1;#20 stream =0;#20 stream =1;#20 stream =0;#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =0;#20 stream =0;#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =1;#20 stream =0;// 1#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =1;#20 stream =0;// 1#20 stream =1;#20 stream =1;#20 stream =0;#20 stream =1;#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =0;#20 stream =1;#20 stream =0;

    // reset the device and turn off the device// at the same time.

    rst =1;enable =0;

    // note that the device is turned off based on the previous comment. so regardless// of data in the input stream. the device will not detect any pattern even if there// is any.#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =1;#20 stream =0;#20 stream =0;#20 stream =0;#20 stream =1;#20 stream =1;#20 stream =0;

    $finish;// Finish the simulation run.end

    // This provides the clock of the UUT.

    alwaysbegin#10 clk =!clk;

    end

    endmodule