ELEE6374 Advanced Digital System Design - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

ELEE6374 Advanced Digital System Design

Description:

Example (1): 16-1 mux using function. Examples (2): clock divider. Example (3): 4-bit shift register. Example (4): 74LS163. Verilog model of 74LS163 ... – PowerPoint PPT presentation

Number of Views:307
Avg rating:3.0/5.0
Slides: 22
Provided by: engrP
Category:

less

Transcript and Presenter's Notes

Title: ELEE6374 Advanced Digital System Design


1
ELEE6374 Advanced Digital System Design
  • Lecture 6 Behavior Descriptions II
  • 02/12/07

2
Learning objectives
  • Explain conditional statements using if and else.
  • Describe multiway branching, using case, casex
    and casez statements.
  • Understand looping statements such as for, while,
    repeat and forever.

3
Activity Flow Control ( if else )
  • if ( A lt B ) S_reg S 1
  • if ( B lt C )
  • if ( a gt b )
  • begin
  • end
  • if ( A lt B ) P d
  • else P k
  • if ( A gt B ) P d
  • else if ( A lt B ) P k
  • else if
  • else P Q
  • Three types of if statements
  • Syntax if ( expression ) statement else
    statement
  • Multiple statements for a case must be grouped
    using begin and end.
  • Value of expression
  • 0, x or z gt false
  • Non-zero number gt true

4
Conditional Operator ( ? )
  • Conditional operator can be applied in
  • either continuous assignments
  • or behavioral descriptions
  • always _at_ ( posedge clock or negedge reset)
  • if (reset 0) y_out0
  • else y_out ( sel ) ? a b a b

always _at_ ( posedge clock or negedge reset) if
(reset 0) y_out0 else if (sel) y_out a
b else y_out a b
5
The case Statement
  • module mux4 ( a, b, c, d, select, yout )
  • input a, b, c, d
  • input 10 select
  • output yout
  • reg yout
  • always _at_( a or b or c or d or select )
  • begin
  • case ( select )
  • 0 yout a
  • 1 yout b
  • 2 yout c
  • 3 yout d
  • default yout 1bx
  • endcase
  • endmodule
  • Case items are examined in order
  • Exact match between case expression and case
    item, same bit-length.
  • Case-item may be a single or a block statement.
  • default is optional.
  • caseendcase
  • casex dont care bits with x and z
  • casez dont care bits with z

6
Expression Matching in case Construct
  • always _at_ ( pulse )
  • casez ( word )
  • 8b0000????

7
Loops
  • repeat
  • for loop
  • while loop
  • forever
  • disable

8
The repeat Loop
  • word_address 0
  • repeat ( memory_size )
  • begin
  • memory word_address 0
  • word_address word_address 1
  • end

9
The for Loop
  • reg 150 regA
  • integer k
  • for ( k 4 k k k 1 )
  • begin
  • regA k10 0
  • regA k2 1
  • end

Loop variables have to be either integer or reg
10
The while Loop
  • begin cnt1s
  • reg 70 tmp
  • cnt 0
  • tmp regA
  • while ( tmp )
  • begin
  • cnt cnt tmp0
  • tmp tmp gtgt 1
  • end
  • end

Loop activities suspend external activities
  • module sth ( externalSig )
  • input externalSig
  • always
  • begin
  • while ( externalSig )
  • end
  • endmodule

Replacement for while ?
11
The disable Statement
  • begin
  • k 0
  • for ( k 0 k lt 15 k k 1 )
  • if ( word k 1 ) disable
  • end

Terminate prematurely in a block of procedural
statements
12
The forever Loop
  • parameter half_cycle 50
  • initial
  • begin clock_loop
  • clock 0
  • forever
  • begin
  • half_cycle clock 1
  • half_cycle clock 0
  • end
  • end
  • initial
  • 350 disable clock_loop

13
always and forever
14
Functions
  • Defined within a module
  • Implement only combinational behavior
  • Compute and return a value for given parameters
  • Have no timing/event control
  • May call other functions, not itself
  • Can be referenced anywhere an expression can
    exist
  • Function name serves as the output variable
  • Must have at least one input port

15
Example of Function
module word_aligner (w_in, w_out) input 70
w_in output 70 w_out assign w_out
align (w_in) function 70 align
input 70 word begin align
word if (align ! 0) while
(align7 0) align align ltlt
1 end endfunction endmodule
16
Example (1) 16-1 mux using function
17
Examples (2) clock divider
18
Example (3) 4-bit shift register
19
Example (4) 74LS163
20
Verilog model of 74LS163
21
Simulation results
Write a Comment
User Comments (0)
About PowerShow.com