Sequence Detector
Sequence Detector
Verilog HDL
22ECE42
Expt 6:
Sequence Detector
3
Digital Design Using Verilog HDL- 22ECE42
Sequence Detector
● A sequence detector is a sequential state machine that takes an
input string of bits and generates an output 1 whenever the target
sequence has been detected.
● Sequence detector is of two types:
Overlapping
Non-Overlapping din
rst
4
Digital Design Using Verilog HDL- 22ECE42
Sequence Detector
din - 1 0 1 0 1 0 1 0 1 1 0 0
Non-Overlapping
din - 101010101100
dout - 000100010000
Overlapping
din - 101010101100
dout - 000101010000
5
Digital Design Using Verilog HDL- 22ECE42
Sequence Detector
without overlap
S1 1
S2 10
S3 101
7
Digital Design Using Verilog HDL- 22ECE42
STATE TRANSITION DIAGRAM
Received
State
Bit
S0 -
S1 1
S2 10
S3 101
8
Digital Design Using Verilog HDL- 22ECE42
STATE TABLE
S0 S0 S1 0 0
S1 S2 S1 0 0
S2 S0 S3 0 0
S3 S0 S1 1 0
9
Digital Design Using Verilog HDL- 22ECE42
Verilog Code in Behaviour model
● always and initial block
● All other behavioral statements can appear only inside these structured
procedure statements
● Behavioural statements
○ If
○ Switch
○ For
○ While
○ repeat
○ Task
○ Function
● No need to know full circuit diagram or boolean expression
Digital Design Using Verilog HDL- 22ECE42
Conditional Statement
if (<expression>)
true_statement ;
else
false_statement;
11
Digital Design Using Verilog HDL- 22ECE42
Multiway Branching: case Statement
● The keywords case, endcase, and default are used in the case statement.
● Syntax:
case (expression)
case_item1: statement1;
case_item2: statement2;
case_item3: statement 3;
…
…
default: default_statement;
endcase
Digital Design Using Verilog HDL- 22ECE42
Verilog Code
module sequence_detector_wo(output dout, input clk,rst, din);
parameter [1:0] s0 = 2'b00, s1 = 2'b01,s2 = 2'b10, s3 =2'b11;
reg [1:0] current_state, next_state;
S1 1
S2 10
S3 101
19
Digital Design Using Verilog HDL- 22ECE42
STATE TRANSITION DIAGRAM
Received
State
Bit
S0 -
S1 1
S2 10
S3 101
20
Digital Design Using Verilog HDL- 22ECE42
STATE TABLE
S0 S0 S1 0 0
S1 S2 S1 0 0
S2 S0 S3 0 0
S3 S2 S1 1 0
21
Digital Design Using Verilog HDL- 22ECE42
Verilog Code
module sequence_detector_o(output dout, input clk,rst, din);
parameter [1:0] s0 = 2'b00, s1 = 2'b01,s2 = 2'b10, s3 =2'b11;
reg [1:0] current_state, next_state;
Draw the output waveform for the sum (S) and carry-out (Cout) signals.
Assume that all gate delays are negligible.
27
Digital Design Using Verilog HDL- 22ECE42
THANK YOU
28
Digital Design Using Verilog HDL- 22ECE42