Docsity

Getting Started with Verilog: A Comprehensive Guide, Study notes of Photography

Toggle sidebar
bg1
copyright(c) 2003 W. B. Ligon III 1
Getting Started withVerilog
Verilog is used to describe hardware, not software
Verilog code is composed of a number of modules
Modules are like functions or methods: they
describe the interface of a component and its
implementation
Components modeled by a module can be primitive
or complex objects
Models can be implemented behaviorally or
structurally
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29

Partial preview of the text

Download Getting Started with Verilog: A Comprehensive Guide and more Study notes Photography in PDF only on Docsity!

Getting Started withVerilog

^ Verilog is used to describe

hardware

, not software

^ Verilog code is composed of a number of modules ^ Modules are like functions or methods: theydescribe the interface of a component and itsimplementation ^ Components modeled by a module can be primitiveor complex objects ^ Models can be implemented behaviorally orstructurally

A Verilog Module

XOR_GATE

A B

F

ports

module xor_gate

(A,

B, F);

input

A, B;

output F;assign F =

(A &

B) |

(~A

& ~B);

endmodule

Literals

^ General form is

[size]['radix]value

0 10 'b10'h104'b1004'bx8'b0100_10018'o

Declarations

module mymod

(inbus, outbus);

parameter

bus_width

parameter

rise_delay =

input [31:0]

inbus;

output [31:0]

outbus;

reg

[31:0] regA; wire

somesig;

endmodule

Continuous Signal Assignment  Consists entirely of boolean equations  References only wire signals  Constantly re-evaluates whenever inputschange^ assign f

= (a

& ~b)

OR

(~a &

b);

Structural Models

^ Defines a module using components ^ Defines internal signals to connectcomponents ^ All basic gates are available

wire

s1,

s2;

nor(s1,

s2, f);

and(a, b,

s1);

nor(a, b,

s2);

always

Statements

^ Behavioral models^ always @(<sensitivity-list>)begin

<procedural-statments><if-else><while,

for,

repeat>

end

Sensitivity List

^ Sensitivity list tells simulator when toevaluate the

always

block's code

^ When any signal in the list changes its value,the

always

block is executed

^ Special constructs

posedge

and

negedge

allow edge-triggered (flip-flop) models

Example using case statement ////^

an 8-bit 4-to-

mux

//wire

[1:0]control; reg

[7:0]a, [7:0]b,

[7:0]c,

[7:0]d, [7:0]e;

always @(control or

a or

b or

c or

d)

begin

case

(control)0:^ e^

a;

1: e

b;

2: e

c;

3: e

d;

endcase end

initial

Statements

^ Simulation models - testbenches^ initialbegin

procedural-statmentsif-elsecasewhile, for, repeat end

Control Flow Statements

if ()

else

case

()

:^

:^

default

:^

endcasefor (;

;

)

Combinational Logic

^ Use continuous assignments or ... ^ always block with inputs in the sensitivity list^ module

some_logic

(a,

b,

c,

d,

e);

input

a,

b,

c,

d;

output

e; reg

s1; assign

e^

=^ s

|^

d;

always

@(a or

b^

or^

c)

if^

(a^

&^ ~b) s^

=^ c; else

s^

=^ ~a;

endmodule

Non-Blocking Assignments

^ Evaluate at the time of execution ^ Complete (and update the variable) after allevents at the current time ^ Used only inside an

always

, and only to

assign a

reg

or

integer

^ Only assign a given variable once ^ Used in implementing sequential logic

Sequential Circuits - Simple FF  Use an always to control the inputs module flip-flop (clk,

d, q);

input clk, d;output q;always @(clk

or d)

if (clk)q <=

d;

endmodule