Sequential Verilog
Al Wood
Registers
A simple memory to hold state, normally implemented as D-type flip-flop.
Inputs and outputs can be declared as registers:
By convention usually only outputs are registers and inputs are wires.
Example: Decoder with register
Sequential always blocks
At the next positive edge of the clock, register
a
will acquire the value held in b
(which could be a register or wire).
SystemVerilog provides:
Delayed (non-blocking) assignments
<=
causes the value to be transferred on the next clock edge. It should only be used in sequential always blocks.
Conversely
=
(aka blocking assignment) happens immediately and should only be used in combinatorial always blocks.
This means you can do surprising things with registers:
Common problems
You now know Verilog :-) Here are the common “gotchas”.
- Variable assigned in multiple always blocks
- Incomplete branch or output assignment
According to Verilog definition
gt
and eq
keep their previous values when not assigned which implies internal state, unintended latches are inferred.Fixing incomplete output assignment (1)
These sort of issues cause endless hair pulling avoid such things. Here is how we could correct this:
Fixing incomplete output assignment (2)
Or we can use default values.
Incomplete output with case statements (1)
Similar problems can occur with
case
statements:Incomplete output with case statements (2)
A default clause is a good catchall.
Exercise 4
Which is actually lots of exercises, all in
basic_verilog
blink
: Make the LED flash. Extend to make LED’s flash in a pattern.fibonacci
: Count through the LEDs in a fibonacci sequence.button
: Make the LED’s count when you press the button. Why won’t it count nice and smoothly?button_edge_detect
: This solves the problem of detecting a button press.lock
: Unlock the device with a password. This leads into the next talk.
沒有留言:
張貼留言