Upload
bangon-kali
View
218
Download
0
Embed Size (px)
Citation preview
7/29/2019 Byte Pattern Detector
1/11
1 of 11
Johannah Mae D. Abestano ECE 195
Four Byte Pattern Detector
// Description: Detects binary pattern in the input stream which is:// 8'h56// 8'hAB// 8'h89// 8'h7F
Finite State Machine Diagram
At IDLE state, if the input is 56, then it FSM moves to STATE 0. However, if input is something else, it remains at
IDLE state. At STATE 0, if the input is 56, it remains there, however, if the input is AB it proceeds to STATE 1, if not among
both, the FSM goes back to IDLE state. At STATE 1, if the input is 89, then the FSM moves to STATE 2, else if the input is
56 then it goes back to STATE 0, however if the input is not 89 nor 56 then it goes back to IDLE state. At state 2, if the
input is 7F, the FSM moves to state 3, else if the input is 56 the FSM moves to STATE 0, otherwise if neither of both, the
it goes back to STATE IDLE. At STATE 3, if the input is 56, then the output is 1, and the FSM moves to STATE 0. However,
if the input is something else, then the output is still 1 but the FSM moves to STATE IDLE. This completes the cycle of the
FSM Machine.
7/29/2019 Byte Pattern Detector
2/11
2 of 11
Wave Form Views
7/29/2019 Byte Pattern Detector
3/11
3 of 11
Source Code BytePattern_detector_tb.V
`timescale1ns/1ps
//////////////////////////////////////////////////////////////////////////////////// Company: MSU-IIT// Engineer: Johannah Mae D. Abestano//// Create Date: 07:37:37 02/01/2013// Design Name:// Module Name: BytePattern_detector_tb
// Project Name: BytePattern_detector// Target Devices: Any// Tool versions: Any// Description: Detects binary pattern in the input stream which is:// 8'h56// 8'hAB// 8'h89// 8'h7F//// Test bench with embedded stimulus.// Dependencies: N/A//// Revision: 0001// Revision 0.01 - File Created// Additional Comments: N/A////////////////////////////////////////////////////////////////////////////////////
module BytePattern_detector_tb;
// Inputsreg clk;reg[7:0] stream;reg rst;reg enable;
// Outputswire detected;
// Instantiate the Unit Under Test (UUT)BytePattern_detector uut (
.clk(clk),
.stream(stream),
.rst(rst),
.enable(enable),
.detected(detected));
initialbegin// Initialize Inputsclk =0;stream =0;
// since the enable variable is 0, then the device is in the off state.rst =1;enable =0;
// Wait 4 ns for global rst to finish#4;
// turn on the device.enable =1;rst =0;#1;
// at 2 units time interval, input these stream values. // OUT#2 stream =8'hAA;#2 stream =8'hBB;#2 stream =8'hCC;#2 stream =8'hDD;// 0
7/29/2019 Byte Pattern Detector
4/11
4 of 11
#2 stream =8'h56;#2 stream =8'hAB;#2 stream =8'h89;#2 stream =8'h7F;// 1#2 stream =8'hAE;#2 stream =8'h11;#2 stream =8'h22;#2 stream =8'hD3;// 0#2 stream =8'hAA;#2 stream =8'hBB;#2 stream =8'hCC;#2 stream =8'hDD;// 0#2 stream =8'h56;#2 stream =8'hAB;#2 stream =8'h89;#2 stream =8'h7F;// 1
#2 stream =8'hAE;#2 stream =8'hAE;enable =0;rst =1;
#2 stream =8'hAE;#2 stream =8'h11;#2 stream =8'h22;#2 stream =8'hD3;// 0#2 stream =8'h56;#2 stream =8'hAB;#2 stream =8'h89;#2 stream =8'h7F;// 1
enable =1;rst =0;
#2 stream =8'h56;#2 stream =8'hAB;#2 stream =8'h89;#2 stream =8'h7F;// 1#2 stream =8'hAE;#2 stream =8'h11;#2 stream =8'h22;#2 stream =8'hD3;// 0#2 stream =8'hAA;#2 stream =8'hBB;#2 stream =8'hCC;#2 stream =8'hDD;// 0
$finish;
end
// this block of code provides clock frequency for the device.alwaysbegin
#1 clk =!clk;
end
endmodule
7/29/2019 Byte Pattern Detector
5/11
5 of 11
Source Code BytePattern_detector.V
`timescale1ns/1ps
//////////////////////////////////////////////////////////////////////////////////// Company: MSU-IIT// Student: Johannah Mae D. Abestano//// Create Date: 07:37:37 02/01/2013// Design Name:
// Module Name: BytePattern_detector// Project Name: BytePattern_detector// Target Devices: Any// Tool versions: Any// Description: Detects binary pattern in the input stream which is:// 8'h56// 8'hAB// 8'h89// 8'h7F// Dependencies: N/A//// Revision: 0001// Revision 0.01 - File Created
// Additional Comments: N/A////////////////////////////////////////////////////////////////////////////////////
module BytePattern_detector(clk,stream,rst,enable,detected
);
input clk;input stream;
input rst;input enable;output detected;
// parameter settings for the current states.parameter SS_IDLE =5'b00001;parameter STATE_0 =5'b00010;parameter STATE_1 =5'b00100;parameter STATE_2 =5'b01000;parameter STATE_3 =5'b10000;
// paramter settings for the pattern of the input byte stream that must// be detected.
parameter PATTERN_0 =8'h56;parameter PATTERN_1 =8'hAB;parameter PATTERN_2 =8'h89;parameter PATTERN_3 =8'h7F;
// this is the input stream. declared as an 8bit wire.wire[7:0] stream;
// this is the current state INTERNAL variable. This stores the current state// of the finite state machine.reg[4:0] state;
7/29/2019 Byte Pattern Detector
6/11
6 of 11
reg[4:0] nxt_state;
assign detected =((state==STATE_3 && nxt_state==SS_IDLE)||(state==STATE_3 &&nxt_state==STATE_0));
// the code that follows is heavily based on the finite state machine diagram// in the documentation of this project. please refer to the diagram and its// following discussion on its operation.always@(posedge clk ornegedge rst)begin
if(rst)begin
state
7/29/2019 Byte Pattern Detector
7/11
7 of 11
default:nxt_state
7/29/2019 Byte Pattern Detector
8/11
8 of 11
Wave View using Memory File
In this simulation the test bench receives data from an external memory file containing testbench data.
7/29/2019 Byte Pattern Detector
9/11
9 of 11
Source Code BytePatternDetector_tb_mem.V
`timescale1ns/1ps
////////////////////////////////////////////////////////////////////////////////// Company:// Engineer://// Create Date: 15:16:16 02/08/2013// Design Name: BytePattern_detector
// Module Name:C:/Users/Bangonkali/Downloads/BytePattern_detector/BytePattern_detector/BytePattern_detector_tb_mem.v// Project Name: BytePattern_detector// Target Device:// Tool versions:// Description://// Verilog Test Fixture created by ISE for module: BytePattern_detector//// Dependencies://// Revision:
// Revision 0.01 - File Created// Additional Comments://////////////////////////////////////////////////////////////////////////////////
module BytePattern_detector_tb_mem;
// Inputsreg clk;reg[7:0] stream;reg rst;reg enable;
// Memory Blocks. Instantiate a memory space 8 bits wide and 92
// entries tall.reg[7:0] memory [92:0];
// the variable holding the number of memory entries to read from// an external file.integer mem_max;
// a variable holding the current address of the memory being// pushed to the stream input.integer counter;
// Outputswire detected;
// Instantiate the Unit Under Test (UUT)BytePattern_detector uut (
.clk(clk),
.stream(stream),
.rst(rst),
.enable(enable),
.detected(detected));
initialbegin
7/29/2019 Byte Pattern Detector
10/11
10 of 11
// Initialize number of memory locations to read from memory.memmem_max =50;
// make sure the initial memory iterator is set to 0. this is the// beginning address.counter =0;
// instantiate the reading of the memory and store data to memory// variable.$readmemh("memory.mem", memory,0, mem_max);
// Initialize Inputsclk =0;stream =0;rst =1;enable =0;
// Wait 3 ns for global rst to finish#3;
// turn on the device by setting enable to high and reset to low.enable =1;rst =0;
// loop at each memory location. then at each address push value to stream at2 time
// units interval.for(counter =0; counter < mem_max; counter = counter +1)begin
#2 stream = memory[counter];end
$finish;end
// block of code provides clock source for the device under test.alwaysbegin
#1 clk =!clk;
end
endmodule
7/29/2019 Byte Pattern Detector
11/11
11 of 11
Source Code memory.mem
AA
56
AB
89
7F
AA
56
AB
89
7F
56
AB
89
7F
11
22
33
44
5566
77
77
88
99
01
02
03
AA
56
AB89
7F
AA
56
AB
89
7F
56
AB
89
7F
11
22
33
44
55
66
77