Monish PPT VERILOG HDL
Monish PPT VERILOG HDL
UNIT- I Design
Using
Verilog
Adopted from
T. R. Padmanabhan and B. Bala Tripura
Sundari,
Design through Verilog HDL –Wiley, 2009.
Prepared BY
D. Khalandar Basha
Assoc Prof., IARE
Un i t - I
Unit - I
INTRODUCTION TO VERILOG:
o Verilogas HDL
o Levels of design Description
o Concurrency
o Simulation and Synthesis
o Functional Verification
o System Tasks
o Programming Language Interface (PLI)
o Module
o Simulation and Synthesis Tools
o Test Benches.
Compiler Directives.
o
B y
Prepared
Y D .
VERILOG AS AN HDL
Gate Level
I ARE ,
B ash a ,
Data Flow
Khal andar
Behavioral
Level
Circuit
D .
Level or
B y
switch level
Prepared
Y D .
Circuit Level or switch level
y = (ab+cd)
Behavioral Level
o Concurrency
o Simulation and Synthesis
o Functional Verification
o System Tasks
o Programming Language Interface (PLI)
Concurrency
of operation.
o All the activities scheduled at one time step are completed and
D .
“synthesis.”
o The circuits realized from them are essentially direct
translations of functions into circuit elements.
D .
B y
Prepared
Y D .
Functional Verification
o
I ARE ,
Verilog code.
Khal andar
o PLI is primarily used for doing the things which would not
have been possible otherwise using Verilog syntax.
D .
B y
Prepared
Y D .
MODULE
“module.”
I ARE ,
> input ports through which one gets entry into the module
> output ports through which one exits the module.
B ash a ,
> inout ports: These represent ports through which one gets entry into the
module or exits the module
Khal andar
Functional Description
Khal andar
endmodule
D .
B y
Prepared
Y D .
SIMULATION AND SYNTHESIS TOOLS
o module tb_module_name ;
B ash a ,
endmodule
Prepared
Y D .
LANGUAGE CONSTRUCTS AND
CONVENTIONS IN VERILOG
o CASE SENSITIVITY
H
I ARE ,
o IDENTIFIERS
H
I ARE ,
identifiers
o
as the first character. Subsequent characters can be of
sign
B y
Prepared
Y D .
WHITE SPACE CHARACTERS , COMMENTS
o
I ARE ,
o Blanks (\b), tabs (\t), newlines (\n), and form feed form the
B ash a ,
o COMMENTS
Khal andar
o NUMBERS
H
4.3, 4.3e2
o
Prepared
Y D .
LOGIC VALUES
Capacitor
B y
o The two types differ in the way they are used as well as with
regard to theirrespective hardware structures.
Khal andar
D .
B y
Prepared
Y D .
Net data type
o
I ARE ,
o If the driving end of a net is left floating, the net goes to the
high impedance state.
Khal andar
o
I ARE ,
WIR 0 1 X Z WAN 0 1 X Z
H
E D
I ARE ,
/TRI /
TRIAN
0 0 X X 0 D 0
1 X 1 X 1 0 0 0 0 1
B ash a ,
X X X X X 1
X 00 1X X X
X
Z 0 1 X Z Z 0 1 X Z
Khal andar
WOR 0 1 X Z TRI1( 0 1 X Z
/TRIO 0
R )
0 0 X X 0
0 0 1 X 0
D .
1
1 1 1 1 1 1 X 1 X
B y
X X X X
X X 1 X X X
Prepared
Z 0 1 X 1(0)
Z 0 1 X Z
Y D .
Variable Data Type
o reg
o time
o integer
B ash a ,
o real
o Realtime
Khal andar
o MEMORY
o Reg [15:0] memory[511:0];
o an array called “memory”; it has 512 locations.
D .
B y
o
I ARE ,
reg[2:0] b;
reg[4:2] c;
Khal andar
wire[-2:2] d ;
o
Prepared
Y D .
Parameters,
Operators.
PARAMETERS
H
in a Verilog module
o parameter word_size = 16;
B ash a ,
OPERATORS
o Unary: - for example, ~a.
o Binary: - for example, a&b.
D .
Prepared BY
D. Khalandar Basha
Assoc Prof., IARE
Un i t - II
Unit - II
module
o
aoi_gate(o,a1,a2,b1,b2);
input a1,a2,b1,b2; output o;
wire o1,o2;
and g1(o1,a1,a2);
and g2(o2,b1,b2);
nor g3(o,o1,o2);
endmodule
o module aoi_st;
reg a1,a2,b1,b2;
wire o;
initial
begin b1 = 0; b2 = 0;
a1 = 0; a2 = 0;
#3 a1 = 1; a2 = 1; b1 = 1; b2 = 0;
end
initial #100 $stop;
initial $monitor($time , " o = %b , a1 = %b , a2 = %b , b1 = %b ,b2 = %b
",o,a1,a2,b1,b2);
aoi_gate gg(o,a1,a2,b1,b2);
endmodule
Un i t - II
TRI-STATE GATES
primitives
Un i t - II
o Simple Latch
module sbrbff(sb,rb,q,qb);
input sb,rb;
output q,qb;
nand(q,sb,qb);
nand(qb,rb,q);
endmodule
Un i t - II
RS Flip-Flop module
o module srff(s,r,q,qb);
input s,r;
output q,qb;
wire ss,rr;
not(ss,s),(rr,r);
nand(q,ss,qb);
nand(qb,rr,q);
endmodule
Un i t - II
A Clocked RS Flip-Flop
module
o module srffcplev(cp,s,r,q,qb);
input cp,s,r;
output q,qb;
wire ss,rr;
nand (ss,s,cp),
(rr,r,cp),
(q,ss,qb),
(qb,rr,q);
endmodule
Un i t - II
D-Latch module
o module dlatch(en,d,q,qb);
input d,en;
output q,qb;
wire dd;
wire s,r;
not n1(dd,d);
nand (sb,d,en);
nand g2(rb,dd,en);
sbrbffff(sb,rb,q,qb);
endmodule
Un i t - II
DELAYS
o Net Delay
wire #2 nn;
// nn is declared as a net with a propagation delay of 2
time steps
wire # (2, 1) nm;
//the positive (0 to 1) transition has a delay of 2 time steps
//The negative (1 to 0) transition has a delay of 1 time step
o Gate Delay
and #3 g( a,b, c);
and #(2, 1) g(a,b, c);
Un i t - II
o wire #(1:2:3) a;
Un i t - II
Net Charges
o net can have a capacitor associated with it, which can store the
signal level even after the
signal source dries up (i.e., tri-stated).
o wire #2 c;
o assign c = a & b;
CONCATENATION OF VECTORS
{a, b, c}
{a(7:4), b(2:0)}
{2{p}} = {p, p}
{2{p}, q} = {p,p, q}
{a, 3 {2{b , c}, d}} = {a,b, c,b, c, d,b, c,b, c, d,b, c,b, c, d }
Un i t - II
OPERATORS
Un i t - II
Unary Operators
Un i t - II
Binary Operators
Cont..
cont…
Ternary operator
oA ?B:C
o assign y = w ? x : z;
Operator Priority
Adopted from
Wiley,
T. R. Padmanabhan and B. Bala
Tripura Sundari, Design through
Verilog HDL – 2009.
Prepared by
D. Khalandar Basha
Assoc Prof., IARE
UNIT -
III
o BEHAVIORAL MODELING:
• Introduction
• Operations and Assignments
• Functional Bifurcation
• Initial Construct, Always Construct
• Assignments with Delays Wait Construct
• Multiple Always Blocks
• Designs at Behavioral Level
• Blocking and Non-Blocking Assignments
• The case statement
• Simulation Flow
• if and if-else constructs
• assign-deassign construct, repeat construct,for loop, the disable construct,
while loop,forever loop, parallel blocks,force-release construct, Event.
BEHAVIORAL MODELING
BEHAVIORAL MODELING
o Behavioral level modeling constitutes design
description at an abstract level.
o One can visualize the circuit in terms of its key
modular functions and their behavior; it can be
described at a functional level itself instead of
getting bogged down with implementation details.
OPERATIONS AND ASSIGNMENTS
o The design description at the behavioral level is done
through a sequence of assignments.
o endmodule
ALWAYS CONSTRUCT
o The always process signifies activities to be executed on
an “always basis.”
o Its essential characteristics are:
• Any behavioral level design description is done using an
always block.
• The process has to be flagged off by an event or a
change in a net or areg. Otherwise it ends in a stalemate.
• The process can have one assignment statement or
multiple assignment statements.
• Normally the statements are executed sequentially in the
order they appear.
EVENT CONTROL
oThe always block is executed repeatedly and endlessly. It
is necessary to specify a condition or a set of conditions,
which will steer the system to the execution of the block.
Alternately such a flagging-off can be done by
specifying an event preceded by the symbol “@”.
o @(negedge clk) :executes the following block at the negative edge of clk.
o @(posedgeclk) : executes the following block at the positive edge of the
clk.
o @clk : executes the following block at both the edges of clk.
o @(prtor clr) :
o @(posedgeclk1 ornegedge clk2) :
o @ (a or b or c) can also write as @ (a or b or c) @ (a,b, c) @ (a, b or
c)
EXAMPLE
COUNTER
o module counterup(a,clk,N);
input clk;
input[3:0]N;
output[3:0]a;
reg[3:0]a;
initial a=4'b0000;
always@(negedge clk) a=(a==N)?4'b0000:a+1'b1;
o endmodule
ASSIGNMENTS WITH DELAYS
o always #3 b = a;
o Values of a at the 3rd, 6th, 9th, etc., ns are sampled and assigned to
b.
o Initial
o begin
o a = 1’b1;
o b = 1’b0;
o #1 a = 1’b0;
o #3 a = 1’b1;
o #1 a = 1’b0;
o #2 a = 1’b1;
o #3 a = 1’b0;
o end
INTRA-ASSIGNMENT DELAYS
o The “intra-assignment” delay carries out the assignment
in two parts.
o An assignment with an intra-assignment has the form
o A = # dl expression;
o Here the expression is scheduled to be evaluated as soon
as it is encountered.
o However, the result of the evaluation is assigned to the
right-hand side quantity a after a delay specified by dl.
o dl can be an integer or a constant expression
o always #2 a = a + 1;
o always #b a = a + 1;
o always #(b + c) a = a + 1;
ZERO DELAY
o Adelay of 0 ns does not really cause any delay.
o However, it ensures that the assignment following is
executed last in the concerned time slot.
o always
o begin a = 1;
o #0 a = 0;
o end
WAIT CONSTRUCT
o The wait construct makes the simulator wait for the
specified expression to be true before proceeding with
the following assignment or group of assignments.
o Its syntax has the form
o wait (alpha) assignment1;
o alpha can be a variable, the value on a net, or an
expression involving them.
o @clk a = b; assigns the value of b to a when clk changes;
o wait (clk) #2 a = b; the simulator waits for the clock to
be high and then assigns b to a
BLOCKING AND NONBLOCKING ASSIGNMENTS
o And
o A = B;
oB=A; // A, B will have same value
NONBLOCKING ASSIGNMENTS AND DELAYS
o The principle of Delays of the intra-assignment type operation is
similar to that with blocking assignments.
o always @ ( a orb)
o #3 c1 = a&b;
o which has a delay of 3 ns for the blocking assignment to c1. If a orb
changes, the always block is activated. Three ns later, (a&b) is
evaluated and assigned to c1. The event “(a or b)” will be
checked for change or trigger again. If a or b changes, all the
activities are frozen for 3 ns. If a or b changes in the interim
period, the block is not activated. Hence the module does not depict
the desired output.
o always @ ( a orb)
o c2 = #3 a&b;
o The always block is activated if a or b changes. (a & b) is evaluated
immediately but assigned to c2 only after 3 ns. Only after
the delayed assignment to c2, the event (a orb) checked for change.
If a orb changes in the interim period, the block is not activated.
o always @(a orb)
o #3 c3 <= a&b;
o The block is entered if the value of a orb changes but the
evaluation of a&b and the assignment to c3 take place with a
time delay of 3ns. If a orb changes in the interim period, the
block is not activated.
o end
o …
o The quantity a can be a number or an expression evaluated to a
number.
o The following block is executed “a” times. If “a” evaluates to 0 or x
orz, the block is not executed.
FOR
LOOP
o The for loop in Verilog is quite similar to the for loop in C
o It has four parts; the sequence of execution is as follows:
o 1. Execute assignment1.
o 2. Evaluate expression.
o 3. If the expression evaluates to the true state (1), carry out
statement. Go to step 5.
o 4. If expression evaluates to the false state (0), exit the loop.
o 5. Execute assignment2. Go to step 2
o ....
o for(assignment1; expression; assignment 2)
o statement;
o . . .
THE DISABLE CONSTRUCT
o To break out of a block or loop. The disable statement
terminates a named block or task. Control is transferred
to the statement immediately following the block
o The disable construct is functionally similar to the breakin
C
o always@(posedge en)
o begin: OR_ gate
o b=1'b0;
o for(i=0;i<=3;i=i+1)
o if(a[i]==1'b1)
o begin b=1'b1;
o disable OR_gate;
o end
o end
WHILE LOOP
o The Boolean expression is evaluated. If it is true, the
statement s are executed and expression evaluated and
checked. If the expression evaluates to false, the loop is
terminated and the following statement is taken
for execution
o while(|a)
o begin
o b=1'b1;
o @(posedge clk)
o a=a- 1'b1;
o end
o b=1'b0;
FOREVER LOOP
o Repeated execution of a block in an endless manner is
best done with the forever loop (compare with repeat
where the repetition is for a fixed number of times).
o . . .
o .always@change
DIGITAL DESIGN
USING VERILOG
Prepared BY
D. Khalandar
Basha
Assoc Prof.,
IARE
UNIT - IV
SWITCH LEVEL MODELING
o Basic Transistor Switches, CMOS Switch, Bi –
directional Gates, Time Delays with Switch
Primitives, Instantiations with Strengths and
Delays, Strength Contention with Trireg Nets
SYSTEM TASKS, FUNCTIONS, AND
COMPILER DIRECTIVES:
o Parameters, Path Delays, Module Parameters,
System Tasks and Functions, File – Based Tasks
and Functions, Compiler Directives, Hierarchical
Access, User-defined Primitives (UDP).
INTRODUCTION
o Display Tasks
The $display task, whenever encountered, displays the arguments in the
desired format; and the display advances to a newline. $write task carries
out the desired display but does not advance to the new line
$strobe Task
o When a variable or a set of variables is sampled and its value displayed,
the $strobe task can be used; it senses the value of the specified
variables and displays them.
$monitor Task
o $monitor task is activated and displays the arguments specified
whenever any of the arguments changes
$random Function
o One can start with a seed number (optional) and generate a
random number repeatedly. Such random number sequences can
be fruitfully used for testing.
FILE-BASED TASKS AND FUNCTIONS
o To carry out any file-based task, the file has to be opened, reading,
writing, etc., completed and the file closed. The keywords for all file-
based tasks start with the letter f to distinguish them from the other
tasks
o All the system tasks to output information can be used to output to a file.
$display, $strobe, $monitor, etc., are of this category. The respective
keywords to output to the file are $fdisplay, $fstrobe, $fmonitor.
o The first field of the task statement is an argument - the file descriptor.
The subsequent fields are identical to the corresponding nonfile tasks.
COMPILER DIRECTIVES
Time-Related Tasks
o The `timescale compiler directive allows the time scale to be specified
for the design. The `timescale directive has two components
o `timescale 1 ms/100 μs
HIERARCHICAL ACCESS
126
Sequential Models
127
Sequential Models 128
Sequential
Models
Feedback
Model Capacitive Implicit
Model Model
Feedback Model 129
Sequential
Models
Feedback
Model Capacitive Implicit
Model Model
Feedback Model
. Basic Feedback
state (one
A - -bit)
Memory element
two
Feedback Line
130
Capacitive Model 131
Sequential
Models
Feedback
Model Capacitive Implicit
Model Model
Capacitive Model
When c 1 the value of D
saved in the input gate
becomes is of the
inverter
and when c 0 this value
becomes
be saved until the next time thatwill
becomes 1 again. c
The complement
of the stored data
Capacitive Storage
.
132
133
Implicit Model
Sequential
Models
Capacitive
Feedback Implicit
Model
Model Model
Implicit Verilog offers language constructs that
Model
Feedback and capacitive models
are technology dependent and are technology independent and allow
have the problem of being too much more efficient simulation of
detailed and too slow to circuits with a large number of
simulate. storage elements.
1S Q
1R
C1
. An SR-Latch Notation
134
Basic Memory Components
Basic Memory
Components
Basic Memory
Components
User Defined
Gate Level Primitives
Sequential Primitives
g1
g2
137
. Cross-Coupled NOR Latch
Gate Level Primitives
Base of most static
memory components
、 timescale 1ns/100ps
Simultaneous assertion
of both inputs results in 138
loss of memory.
Gate Level
Control Gates
Clock Primitives
latch p
Input
. Master-Slave D Flip-Flop
142
Gate Level
Primitives
`timescale 1ns/100ps
module master_slave (input d, c, output q,
q_b );
wire qm, qm_b;
defparam master.tplh=4,
slave.tpl =4, master.tphl=4, Hierarchical Naming
h slave.tphl=4;
latch_
p master ( d, ~d, c, qm,
qm_b ),
slave ( qm, qm_b, ~c, q,
q_b ); endmodule
145
User Defined Sequential
Primitives
primitive latch( q, s, r,
c ); output q;
reg q;
input s, r, c;
initial q=1'b0;
table
// s r c q q+ ;
// ------:---:----;
? ?0 :? :- ;
00 1 : ? :- ; Table defining the latch
0 1 1 : ? :0 ; output
1 0 1 : ? : 1 ;
endtable
endprimitive
146
. Sequential UDP Defining a Latch
User Defined Sequential
Primitives
primitive latch( q, s, r, c );
.............
............. Column for specifying
table present state
// s r c q
q+ ;
// Signifies no
“ ”
------:---:----; change
? ?0:?:- ;
0 0 1 : ? :-
; 0 1 1 : ? :
0 ; 10 1 : ?
: 1 ;
endtable Signifies any
“ ”
value
endprimitive
Memory Vectors
Flip-flop Timing
and Arrays
148
Memory Elements Using
When a block s ’
clock input is 0 ,
s
and when its clock is
1 it puts its data input
into its output.
149
. Master-Slave Using Two Feedback Blocks
Memory Elements
Using
Assignments
`timescale 1ns/100ps
Basic Memory
Components
User Defined
Gate Level Sequential Primitives
Primitives
Behavioral
Memory Elements Memory Elements
Using Assignments
Memory Vectors
Flip-flop Timing and Arrays
151
Behavioral Memory
Elements
. Behavioral Coding:
. A more abstract and easier way of writing Verilog code for a latch or
flip-flop.
. The storage of data and its sensitivity to its clock and other control inputs will be
implied in the way model is written.
152
Behavioral Memory Elements153
Behavioral
Memory
Elements
Latch
Flip -flop
Modeling
Modeling
Flip-flop
with Set-Reset Other
Storage Element
Control Modeling Styles
Latch Modeling 154
Behavioral
Memory
Elements
Latch
Flip-flop
Modeling
Modeling
Flip-flop
with Set-Reset Other
Storage Element
Control Modeling Styles
While c is 1
changes on d directly q
affect
Latch Modeling
and q_b outputs.
A Storage
unit
Level Sensitive c:
`timescale1ns 10 p A
to Latch
/ 0 s
module latchinpu d, outpu reg q,
alway @( (ot d c, t q_b );
s
if ( c c r )
)
begin
#4 q = input is read and
d;
#3 q_b = After 4nstod
assigned
end ~d; q output.
endmodule
If d changes between the
time q and q_b
it is read
for
erroneous results
Type Latch Verilog Code happen.
.
A D- After another wait of 3ns, d is
read again 155
~d is
and
to q_b output. assigned
Latch Modeling Corrects the
timing of
problem
`timescale 1ns/100ps blocking
assignments.
controls
Latch Modeling
Storing a 1 time
at time 30
Flip-flop Modeling 158
Behavioral
Memory
Elements
- Reset
Set Control
Behavioral
Memory
Elements
Latch
Modeling Flip-flop
Modeling
-flop
Flip Other
with Set-Reset
Storage Element
Control Modeling Styles
Flip-flop With Set-Reset
Control
`timescale 1ns/100ps
pand 4 一 and
Control
Syncb
same.
4 一 are
flip
A5yncb the t output.
Styles
Behavioral
Memory
Elements
Latch
Flip -flop
Modeling
Modeling
Flip-flop
Other
with Set-Reset
Storage Element
Control Modeling Styles
Other Storage Element
Modeling Styles
A latch using a wai
`timescale statement instead
t of an
1ns/100ps event control
module latch (input d, c, output reg q, q_b ); statement
If the
Latch Using wait, a Potentially Dangerous delay control statements are
Model
omitted, then the looping of
the
.
simulation.
Flip-flop Timing
Basic Memory
Components
Flip-flop
Timing
Width
Setup Hold And
Time Time Period
173
Setup Time
Flip-flop
Timing
Width
Setup Hold
And
Time Time
Period
Setup Time
. Setup Time
. The Minimum necessary time that a data input requires to setup before it is
clocked into a flip-flop.
. Verilog construct for checking the setup time: $setup task
. The $setup task:
. Takes flip-flop data input, active clock edge and the setup time as its parameters.
. Is used within a specify block.
174
Continuously checks
timing distance between
$setup task within a specify changes on d
Setup Time
block and the positive edge of clk.
If this adistance is message
violation less thanwill
5ns,be
`timescale issued.
1ns/100ps
module d_ff ( input d, clk, s, r, output reg q,
q_b );
specify
$setup ( d, posedge clk, 5 );
endspecify
always @( posedgeclk or posedge s or posedge
rbegin
)
end
endmodul
e Positive edge trigger flip-flop and
Asynchronous set and
reset
controls
. Flip-Flop with Setup Time
175
Setup Time
always @( posedge clk orposedge s or posedge r )
begin
if( s ) begin
q <= #4 1'b1;
q_b <= #3 1'b0;
end else if( r ) begin
q <= #4 1'b0;
q_b <= #3 1'b1;
end else begin
q <= #4 d;
q_b <= #3 ~d;
end
end
endmodule
176
.
Flip-Flop with Setup Time
(Continued)
The d input changes at 57ns and
Setup Time
the data is clocked into the flip-
flop at 60ns,
only 3ns after d.
.
Setup Time Violation
The simulation run reports
the violation.
177
178
Hold Time
Flip-flop
Timing
Hold Width
Setup
And
Time Time
Period
Hold Time
. Hold Time
. The Minimum necessary time a flip-flop data input must stay stable (holds its
value) after it is clocked.
. Verilog construct for checking the setup time: $hold task
. The $setup task:
. Takes flip-flop data input, active clock edge and the required hold time as its
parameters.
. Is used within a specify block.
179
Hold Time
`timescale 1ns/100ps
module d_ff ( input d, clk, s,r, output regFliqp fqlo_pbw);ithhold time of 3ns.
specify
$hold ( posedge clk, d, 3 );
endspecify
always @( posedge clk or posedge s or posedge
r ) begin
end
endmodule
181
Hold Time
. The Verilog $setuphold task combines setup and hold timing checks.
. Example:
. $setuphold (posedgeclk, d, 5, 3)
182
Width And Period 183
Flip-flop
Timing
Width
Setup
Time Hold
And
Time Period
Width And Period
. Verilog $width and $period check for minimum pulse width and period.
. Pulse Width: Checks the time from a specified edge of a reference signal to its
opposite edge.
. Period: Checks the time from a specified edge of a reference signal to the same edge.
184
Width And
Period
specify
$setuphold ( posedge clk, d, 5, 3 );
$width (posedge r, 4);
$width (posedge s, 4);
$period (negedge clk, 43);
endspecify
185
Component
Description
Data
Components Controllers
186
Controllers
Decisions
Based on :Inputs ,
Outputs ,State
187
Controllers
. Controller:
188
Controllers
Controllers
Sequence
Detector
Synchronizer
189
Synchronizer
Controllers
Sequence
Synchronizer Detector
190
Synchronizer
Clk
adata
synched
. Synchronizing adata
191
Synchronizer
`timescale 1ns/100ps
module Synchronizer (input clk, adata,
output reg synched);
always @(posedge clk)
if (adata == 0) synched <= 0;
else synched <= 1;
endmodule If a 1 is Detected on
adata on the rising
edge of clock,
A Simple Synchronization Circuit
.
synched becomes 1
and
remains 1
for atleast one
clock period
192
Sequence Detector
Controllers
Synthesizer Sequence
Detector
193
Sequence Detector
When the sequence
is detected, the w
Searches on Output becomes 1
it’sa input stays 1 and
for a complete
for the clock cycle
110
Sequence If 110 is detected
on a, then w gets
a w
1, else w gets 0 .
clk
. State Machine Description
194
Sequence Detector
A Moore Machine
Sequence Detector
States are named: The State in which the
s0 , s1 , s2 , s3 110 sequence is
0 1 detected.
reset
1 1 0
S0 S1 S2 S3
0 0 0 0 1
1
Initia
l 0
State
It Takes atleast
3 clock periods to
. Sequence Detector State Machine get
to the s3 state
195
Sequence Detector
module Detector110 (input a, clk, reset, output w);
parameter [1:0] s0=2'b00, s1=2'b01, s2=2'b10, s3=2'b11;
reg [1:0] current;
endmodule
State Machine
Coding
A More Modular
Huffman
Style
Coding
Style
A ROM Based
Controller
197
Moore Machines
State Machine
Coding
A More Modular
Huffman
Style
Coding
Style
A ROM Based
Controller
198
Moore Machines
. Moore Machine :
.
A state machine in which all outputs are carefully synchronized with the
circuit
clock.
.
In the state diagram form, each state of the machine specifies its
outputs
independent of circuit .
. inputs
In Verilog code of a state machine, only circuit state variables participate in
the
output expression of the
circuit.
199
Mealy Machines
State Machine
Coding
A More Modular
Huffman
Style
Coding
Style
A ROM Based
Controller
200
Mealy Machines
. Mealy Machine :
. Is different from a Moore machine in that its output depends on its current state
and inputs while in that state.
. State transitions and clocking and resetting the machine are no different from
those of a Moore machine. The same coding techniques are used.
201