5
Pattern Recognizer: 01110 Verilog Code for Device `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 15:51:40 01/09/2013 // Design Name: // Module Name: PatternRecognizer // Project Name: PatternRecognizer // Target Devices: Any // Tool versions: // Description: You may use information at // http://www.asic-world.com/tidbits/verilog_fsm.html // Using Single Always For Sequential, Combo And Output Logic // // Dependencies: Johannah :D // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module PatternRecognizer( input clock, input pattern, input reset, input enable, output recognizer );

Verilog Binary Pattern Recognizer Finite State Machine Application

Embed Size (px)

DESCRIPTION

A simple Verilog Implementation of a Binary Pattern Recognizer. The Finite state machine diagram is also included for reference. Also, the Waveforms are there as a guide for the final output.

Citation preview

Page 1: Verilog Binary Pattern Recognizer Finite State Machine Application

Pattern Recognizer: 01110

Verilog Code for Device

`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 15:51:40 01/09/2013 // Design Name: // Module Name: PatternRecognizer // Project Name: PatternRecognizer // Target Devices: Any // Tool versions: // Description: You may use information at // http://www.asic-world.com/tidbits/verilog_fsm.html // Using Single Always For Sequential, Combo And Output Logic // // Dependencies: Johannah :D // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module PatternRecognizer( input clock, input pattern, input reset, input enable, output recognizer );

Page 2: Verilog Binary Pattern Recognizer Finite State Machine Application

parameter IDLE = 5'b00001; parameter STATE0 = 5'b00010; parameter STATE1 = 5'b00100; parameter STATE2 = 5'b01000; parameter STATE3 = 5'b10000; reg recognizer; reg[4:0] state; always @(posedge clock) begin if (enable && !reset) begin case (state) IDLE: if (!pattern) begin state <= STATE0; recognizer <= 0; end else begin recognizer <= 0; end STATE0: if (pattern) begin state <= STATE1; recognizer <= 0; end else begin recognizer <= 0; state <= STATE0; end STATE1: if (pattern) begin state <= STATE2; recognizer <= 0; end else begin recognizer <= 0; state <= STATE0; end STATE2: if (pattern) begin state <= STATE3; recognizer <= 0; end else begin recognizer <= 0; state <= STATE0; end STATE3: if (pattern) begin state <= IDLE; recognizer <= 1; end else begin state <= STATE0; recognizer <= 1; end default: state <= IDLE; endcase end else begin state <= IDLE; recognizer <= 0; end end endmodule

Verilog Code for Test Bench

`timescale 1ns / 1ps //////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 16:15:31 01/09/2013 // Design Name: PatternRecognizer

Page 3: Verilog Binary Pattern Recognizer Finite State Machine Application

// Module Name: D:/ACADS/ECE 195/PatternRecognizer/PatternRecognizer_tb.v // Project Name: PatternRecognizer // Target Device: // Tool versions: // Description: // // Verilog Test Fixture created by ISE for module: PatternRecognizer // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // //////////////////////////////////////////////////////////////////////////////// module PatternRecognizer_tb; // Inputs reg clock; reg pattern; reg reset; reg enable; // Outputs wire recognizer; // Instantiate the Unit Under Test (UUT) PatternRecognizer uut ( .clock(clock), .pattern(pattern), .reset(reset), .enable(enable), .recognizer(recognizer) ); initial begin // Initialize Inputs clock = 0; pattern = 0; reset = 0; enable = 0; // Wait 100 ns for global reset to finish #100; // Add stimulus here #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0;

Page 4: Verilog Binary Pattern Recognizer Finite State Machine Application

#20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; enable = 1; reset = 0; // Add stimulus here #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; reset = 1; enable = 0;

Page 5: Verilog Binary Pattern Recognizer Finite State Machine Application

// Add stimulus here #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 0; #20 pattern = 1; #20 pattern = 1; #20 pattern = 1; $finish; end always begin #10 clock = !clock; end endmodule

References

http://www.asic-world.com/tidbits/verilog_fsm.html Using Single Always For Sequential, Combo And Output Logic http://www-inst.eecs.berkeley.edu/~cs150/Documents/FSM.pdf http://www.cse.nd.edu/courses/cse20221/www/handouts/L17_FSM%20Design%20Example%20with%20Verilog.pdf