Gradual
Introduction to Verilog Syntax: Basic Sequential
Circuits
E.R.Doering
Key to typestyle: Italics => Verilog keyword; Bold => new concept introduced
Visualize
the Hardware: |
Describe the
Hardware: |
Comments: |
D flip-flop, positive-edge triggered |
module
D_FF (D,Clock,Q); |
|
T flip-flop, negative-edge triggered |
module
T_FF (T,Clock,Q); |
T (�toggle�) flip-flop behavior is such that applying a 1
to the T input causes the output to change state on the clock edge, and
applying a 0 maintains the state. |
T flip-flop, negative-edge triggered, with inverted and noninverted outputs |
module
T_FF (T,Clock,Q,_Q); |
In this example the �assign� technique is put to good use. |
D flip-flop, negative-edge triggered, with inverted and noninverted outputs, and asynchronous reset (active high) |
module
D_FF (D,Clock,Q,_Q,Reset); |
�Asynchronous reset� means that asserting the reset will
instantly set the Q output to zero, regardless of the activity of D or Clock.
Q will remain zero as long as Reset is asserted. This behavior matches
standard flip-flop circuits. |
D flip-flop, positive-edge triggered, and asynchronous
preset (active low) |
module
D_FF (D,Clock,Q,_Preset); |
�Asynchronous preset� behaves similarly to �reset�, except
that the Q output is set to 1 instead of zero. |
D flip-flop, positive-edge triggered, with synchronous reset (active high) |
module
D_FF (D,Clock,Q,Reset); |
�Synchronous reset� means that the reset action does not
occur until the next clock edge. |
|
|
NOTE: Avoid the temptation to design arbitrary flip-flop
behavior, e.g., ability to trigger on both edges of the clock, ability to
trigger on multiple clock signals, etc. The hardware synthesis tool does not
�magically� create new hardware from thin air! You have to write circuit
descriptions that are realizable, that is, can be mapped onto existing
(known) hardware elements such as standard D flip-flops. Bottom line: Use the constructs listed above exactly as
shown... don�t invent your own!! |
16-bit data register |
module
Reg16 (D,Clock,Q,Reset); |
A register is
typically composed of an array of D flip-flops. |
N-bit data
register |
module RegN (D,Clock,Q,Reset); |
The �parameter� keyword is used to declare a global
constant for register width. This is a simple example of parameterized description. Changing only a single number can
update the entire design. |
8-bit up counter with asynchronous reset |
module CountUp (Clock,Reset,Q); |
Free-running up counter |
8-bit up counter with count enable, and asynchronous reset |
module CountUp (Clock,Reset,Enable,Q); |
Counter only increments when ENABLE signal is asserted. |
8-bit down counter with count enable and initialize
control inputs, asynchronous reset |
module CountDown (Clock,Reset,Enable,Init,Q); |
Counter is similar to previous example, except it counts
down. An additional control input initializes the counter to 8�hFF. |
8-bit loadable shift register |
module
Shifter (Clock,Reset,Load,D,Q); |
Right-shifts the data, filling the MSB with zero. |
Clock divider (produces a pulse every N clock cycles) |
reg SlowClock; always @ (posedge Clock or posedge Reset) �� if (Reset) begin ����� ClockDiv <= 0; ����� SlowClock <= 0; �� end �� else if
(ClockDiv == MaxCount) ����� begin �������� SlowClock <= 1; �������� ClockDiv <= 0; ����� end ����� else begin ����� �� SlowClock <=
0; ����� �� ClockDiv <=
ClockDiv+1; ����� end |
�ClockDiv� needs to be sized to accommodate
the value you set for �MaxCount�. In the example at
left, a maximum count of 12 means the counter register needs four bits. If
your maximum count was 1000, you would need a 10-bit counter.
where the � � � � operator
(�ceiling operator�) means go to the next higher integer. |