Verilog Synthesis Examplesx2
Verilog Synthesis Examplesx2
CS/EE 3710
Fall 2010
Behavioral Modeling
Using continuous assignments
ISE can build you a nice adder
Easier than specifying your own
1
Bitwise Operators
Bitwise operations act on vectors (buses)
2
Reduction Operators
Apply operator to a single vector
Reduce to a single bit answer
Conditional Operator
Classic mux
Can be confusing if you get crazy
3
Using internal signals
Internal wires and regs can be used inside a
module
4
Operator Precedence
Constants
Specified in binary, octal, decimal, or hex
Note use of underscore in long binary numbers
5
Hierarchy
Instantiate other modules in your module
Tristates
Assign the value z
Just say NO!
No on-board tri-states on Spartan3e FPGAs
Use MUXs instead!
6
Bit Swizzling
Sometimes useful to work on part of a bus, or
combine different signals together
Use bus (vector) notation
Bit Swizzling
Sometimes useful to work on part of a bus, or
combine different signals together
Use concatenation {} operator
7
Registers
Edge-triggered flip flops
Always use reset of some sort!
Registers
Can also add an enable signal
Only capture new data on clock and en
8
Counters
Behavioral
Counters
Structural
9
Comb Logic with Always blocks
Always blocks are often sequential
But, if you have all RHS variables in the
sensitivity list it can be combinational
Remember that you still must assign to a reg
type
10
Decoder example (combinational)
11
Seven Segment Decoder
Memories
Generally translates to block RAMs on the
Spartan3e FPGA
12
Shift Register?
13
Blocking vs. Non-Blocking
Shift Register?
14
Example
Three states, no inputs, one output, two state
bits
Example
15
Mealy vs. Moore
Mealy example
Output is true if
input is the same as
it was on the last
two cycles
16
Mealy Example
Parameterized Modules
17
Verilog Style Guide
Use only non-blocking assignments in
always blocks
Define combinational logic using assign
statements whenever practical
Unless if or case makes things more readable
When modeling combinational logic with
always blocks, if a signal is assigned in one
branch of an if or case, it needs to be assigned
in all branches
18
Verilog Style Guide
Be very careful if you use both edges of the
clock
It’s much safer to stick with one
I.e. @(posedge clock) only
Be certain not to imply latches
Watch for synthesis warnings about implied
latches
Provide a reset on all registers
19