DATA FLOW MODELLING, COUNTERS
Points to Remember
1
When instantiating a module, the order of the ports used in instantiation must be the same as
their order in the module definition.
DATAFLOW MODELLING (CONTD)
Example: Ripple Counter
In this lab we will design a 4-bit ripple counter by using negative edge-triggered flip flop. We design
it using Verilog dataflow statements and test it with a stimulus module. The diagrams for the 4-bit
ripple carry counter modules are shown below. Fallowing figure shows the counter being built with
four T-flipflops.
2
As the T- FF is built with D- FF:
Dataflow code:
Verilog Code for T-flipflop
Finally, we define the lowest level module D_FF (edge_dff ), using dataflow statement.
3
Verilog Code for Edge-Triggered D-flipflop
4
The design block is now ready. Now we must instantiate the design block inside the stimulus block
to test the design. The clock has a time period of 20 with a 50% duty cycle.
NOTE: $finish statement is used whenever forever loop or always block is used, otherwise the
loop will keep on running indefinitely; it serves the useful purpose of suspending all initial
blocks. Also note that forever loop is normally used in conjunction with initial statement block,
whereas always can be used as a standalone block. All initial statements are executed
concurrently at time t =0 and the delays of one initial block do not affect the other initial block.
On the other hand the delays in one initial block containing begin and end are added.
5
The output of the simulation is shown below. Note that the clear signal resets the count to zero.
The waveforms are also shown below:
6
7