0% found this document useful (0 votes)
6 views

Unit-II - Design of Digital Systems Updated

Uploaded by

Sanyam Gill
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Unit-II - Design of Digital Systems Updated

Uploaded by

Sanyam Gill
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Design Using System Verilog

Design of Combinational and Sequential Circuits:

Dr. Sujit K. Patel


Assistant Professor, DECE|TIET

1
Unit-2
• HDL modelling of combinational and sequential circuits: multiplexer, decoder, adder,
flip flops and registers, simple design examples, testbench for combinational and
sequential circuits. Mealy and Moore FSMs, Design Examples.

2
System Verilog Modeling Styles
• Modeling styles are
1. Data flow level

2. Gate level

3. Behavioral level

4. Mixed modeling

3
Modeling Styles: Examples
• Dataflow level modelling of mux:
module mux_2to1 (i0,i1,sel,y);

input logic i0,i1,sel;

output logic y;

assign y = (sel) ? i1 : i0;

// assign y= ((~sel)&i0) | (sel & i1);

endmodule
4
Modeling Styles: Examples
• Gate level modeling: module mux_2to1_Gate_Level (i0,i1,sel,y);
input logic i0,i1,sel;
output logic y;
logic y1,y2;
not n1(sel_n, sel);
and and_1(y1, i0,sel_n);
and and_2(y2,i1,sel);
or or_1(y,y1,y2);
endmodule

5
Modeling Styles: Examples
• Behavioral modelling: module mux_2to1_Beh (i0,i1,sel,y);
input logic i0,i1,sel;
output logic y;
always@(*) begin
if (sel==0)
y<=i0;
else
y<=i1;
end
endmodule
6
Testbench for 2-to-1 MUX

7
• Non-synthesizable code for 2-input NAND gate

8
Switch level modelling of 2-input NAND gate

9
Testbench for 2-Input NAND gate

10
Power of System Verilog

11
Dangers of Verilog: Incomplete Specification

12
Incomplete Specification Infers Latches

13
Avoiding Incomplete Specification

14
The Sequential always Block

15
Importance of the Sensitivity List

16
Importance of the Sensitivity List

17
Simulation

18
Blocking vs. Nonblocking Assignments

19
Blocking vs. Nonblocking Assignments

20
x

21
Assignment Styles for Sequential Logic

22
Use Nonblocking for Sequential Logic

23
Simulation

24
Use Blocking for Combinational Logic

25
Use Blocking for Combinational Logic

26
Dangers of Verilog : Priority Logic

27
Resulting Priority Logic

28
Avoiding (Unintended) Priority Logic

29
Useful Boolean Operators

30
31
D-FF with synchronous enable and asynchronous reset
Reset
Input D Q Output
Clk

enable

32
Testbench for D-FF with synchronous enable

33
Simulation

34
Synchronous System Design

• Synchronous Design Methodology


• All storage components are synchronized with global clock
• Input data sampled at positive or negative edge of the clock signal

• Synchronous system consists of three parts


1. State register
2. Next state logic
3. Output logic

35
Two-segment coding style for a DFF with enable input

0
MUX D Q q
d 1

enable
Clk Asyn_reset

36
Simulation

37
Binary up/down counter

clk
Up/Down 4-bit
sync_rst q
Counter
up_down

Present State Output


Next State Outputs
Up_dwon Next State register Present State
Logic
Logic
reset
clk

38
Binary up/down counter

39
Testbench for up/down counter

40
Simulation

41
Universal shift register
clk
si_l
4-bit
si_r USR q
pi_d
Sel

Present State Output


register Logic Outputs
si_l Next State Present State
si_r Next State
Logic
pi_d clk
sel

42
Universal Shift Register

43
Testbench for Universal Shift Register

44
Simulation

45
Finite State Machine

46
Some Basic Concepts: FSM

• Any circuit with memory is a finite state machine


• Even computers can be viewed as huge FSMs

• Design of FSMs Involves


• Defining states
• Defining transitions between states

• There are two types of FSMs


• Mealy
• Moore
Mealy FSM

• Output is a function of a present state and inputs

Inputs Next State


Logic
Next State Present State
clock Present State
reset register

Output Outputs
Logic
Moore FSM

• Output is a function of a present state only

Inputs Next State


Loigc
Next State Present State
clock Present State
reset register

Output Outputs
Logic
FSM Code Development
• The procedure of developing code for an FSM is similar to that of a regular
sequential circuit.

• We first separate the state register and then derive the code for the
combinational next-state logic and output logic.

• The main difference is the next-state logic.


• For an FSM, the code for the next-state logic follows the flow of a state diagram.

• We will discuss one example based on the binary sequence detector.


Example: Sequence Detector
Develop the SV model for Mealy sequence detector which has one-bit input
and one-bit output. This generates logic ‘1’ output whenever it
recognizes sequence “101”.
Mealy State Diagram for Sequence Detector
Desired binary sequence to be recognized by detector is “101”.
Code for Mealy Sequence Detector
//state register

//module input and outputs


Code for Mealy Sequence Detector
// Next state logic
Code for Mealy Sequence Detector
// Output logic
Testbench Code
Output Waveforms

0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 0
Moore FSM

• Output is a function of a present state only

Inputs Next State


Logic
Next State Present State
clock Present State
reset register

Output Outputs
Logic
Example: Sequence Detector
Develop the Verilog HDL model for Moore sequence detector which has one-
bit input and one-bit output. This generates logic ‘1’ output whenever it
recognizes sequence “101”.
Moore State Diagram for Sequence Detector
Desired binary sequence to be recognized by detector is “101”.
Code for Moore Sequence Detector
// State register

// input output ports


Code for Moore Sequence Detector // next state logic
Code for Moore Sequence Detector
Testbench Code Cont’d…
Output Waveforms

0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 0 0
End of Lecture

You might also like