Top Banner
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function
23

OUTLINE

Dec 31, 2015

Download

Documents

gersemi-hannes

OUTLINE. Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function. Behavioral modeling. Procedural blocks: initial block : executes only once always block :executes in a loop - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: OUTLINE

OUTLINE

Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function

Page 2: OUTLINE

Behavioral modeling Procedural blocks:

initial block: executes only once always block:executes in a loop

Block execution is triggered based on user-specified conditions always @ (posedge clk) ………

All procedural blocks are automatically activated at time 0

Page 3: OUTLINE

Behavioral modeling

All procedural blocks are executed concurrently

reg is the main data type that is manipulated within a sequential block It holds its value until assigned a new value

Page 4: OUTLINE

Initial Statement Executes only once at the beginning of simulation initial statements Multiple initial block execute concurrently at time 0 Used for initialization and waveform generation reg [7:0] RAM[0:1023]; reg RIB_REG; initial begin integer INX; RIB_REG =0; for (INX = 0; INX < 1024; INX = INX + 1) RAM[INX] = 0; end

group

multiple

statements

Page 5: OUTLINE

always Statement(1)

Executes continuously; must be used with some form of timing control

always (timing_control) always statements CLK = ~CLK // Will loop indefinitely Four forms of event expressions are often used

An OR of several identifiers (comb/seq logic) The rising edge of a identifier (for clock signal of a register) The falling edge of a identifier (for clock signal of a register) Delay control (for waveform generator)

Page 6: OUTLINE

always Statement(2)

Any number of initial and always statements may appear within a module

Initial and always statements are all executed in parallel

Page 7: OUTLINE

Examplemodule example (D, CURRENT_STATE, Q, NEXT_STATE);input D, CURRENT_STATE;output Q, NEXT_STATE;reg CLK, Q, NEXT_STATE;always #5 CLK = ~CLK;

always @(posedge CLK)begin Q =D;endalways @(negedge CLK)begin NEXT_STATE = CURRENT_STATE;endendmodule

delay-controlled always block

clock period = 10

activated when CLK has

a 0 -> 1 transition

activated when CLK has

a 1 -> 0 transition

Page 8: OUTLINE

Procedural Assignments The assignment statements that can be used inside an always or initia

l block The target must be a register or integer type always @(A or B) // infer wire begin

B = A; C = B; end // C=A

always @(posedge CLK) // infer flip-flop begin

B <= A;C <= B; D <= C;

end // Clock skew!!

Page 9: OUTLINE

Conditional Statements if and else if statements if (expression) statements { else if (expression) statements } [ else statements ] if (total < 60) begin grade = C; total_C = total_C + 1; end else if (sum < 75) begin grade = B; total_B = total_B + 1; end else grade = A;

Page 10: OUTLINE

Conditional Statements case statement case (case_expression) case_item_expression {, case_item_expression }: statements case_item_expression {, case_item_expression }: statements …… [ default: statements ] endcase

case (OP_CODE) 2`b10: Z = A + B; 2`b11: Z = A – B; 2`b01: Z = A * B; 2`b00: Z = A / B; default: Z = 2`bx; endcase

Page 11: OUTLINE

Loop Statements

Four loop statements are supported The for loop The while loop The repeat loop The forever loop

The syntax of loop statements is very similar to that in C language

Most of the loop statements are not synthesizable in current commercial synthesizers

Page 12: OUTLINE

for loop for (initial condition; terminating condition; increment)

begin

…..

end for (i=0;i<32;i=i+1) state[i]=0; for (i=0;i<32;i=i+2)

begin

state[i]=1;

state[i+32]=0;

end

Page 13: OUTLINE

repeat loop

repeat(constant number) connot be used to loop on a general logical expr

ession (while loop is used for this purpose) repeat(128)

begin

$display(“count=%d”,count);

count=count+1;

end

Page 14: OUTLINE

forever loop

execute forever until the $finish task is encountered.

clock=1’b0;

forever #10 clock=~clock;

Page 15: OUTLINE

while loop

while (logical expression)begin

……. end

while ((i<128) && continue)begin

$display(“count=%d”, count);i=i+1;

end

while ((i<128) && continue) i=i+1;

Page 16: OUTLINE

Exercise

Page 17: OUTLINE

Homework-- ASM designed by HDL

This example is referred from “Digital Design “, M. Morris Mano

Page 18: OUTLINE

Homework-- ASM designed by HDL

Page 19: OUTLINE

Homework-- ASM designed by HDL

Page 20: OUTLINE
Page 21: OUTLINE

Homework-- ASM designed by HDL

Page 22: OUTLINE

Homework-- ASM designed by HDL

Page 23: OUTLINE

Homework:

Simulate and discuss the results