Verilog OverviewThis over is intentionally not comprehensive... far from it. I am just covering a couple of the basic forms of Verilog that are used in hardware design. I will also compare Verilog to software languages like C++ and Java with which you should be familiar. IntroductionSome Verilog basics:
ModulesModules are the basic building blocks of Verilog. Every design or design part is a module. Modules are like functions in that they have parameters. Modules can use other modules. This is like creating your own functions and calling them in C++. In hardware design, this is called "design hierarchy." A module looks like this:
Hopefully, <module_name> and <parameter_name> tokens are self-evident. The <parameter_list> is a comma-separated list of all the parameters to a module. Order is important. Here's an example of a module name "foo" with two input parameters ("a" and "b") and two output parameters ("x" and "y"):
So far, all parameters have been one bit wide. Multi-bit parameters can be specified as well. A couple examples:
Structural DescriptionsVerilog can be used to represent logic diagram or gate-level hardware descriptions. The wire keyword is used to represent connections between gates. Verilog also provides keywords for the basic logic gates: and, or, not, nand, nor, xor, xnor. Here's a very simple example of a 8-bit and gate built using 2-bit and primitives:
There are also a couple of nice examples in our text: Figure 4-32 on page 185 and Figure 4-33 on page 187. Boolean EquationsThe format for Boolean equations in Verilog is not very different to what we're accustomed to. The Boolean operators defined in the language are:
The keyword assign is used to set the value of outputs or wires. Parentheses can be used to correctly order Boolean operators to fashion the function you are trying to express. Here's an example with 3 inputs and 2 outputs, defined using Boolean operators:
Hierarchical DesignsDesign hierarchy is created when one module uses (or calls) another. This is done in the same fashion as using the primitive gates (and, or, etc) that Verilog provides as described above in the "Structural Descriptions" section. Here's a nice example from page 233 of our text. It's a four bit adder build out of a full adder that is in turn built out of a half adder. So, there are 3 levels of hierarchy here.
Also, note that different design modules may be described at any level you deem appropriate: gates, equations, etc. Sequential ElementsSequential elements like flipflops and latches can be modeled using Verilog. As we know, moving from combinational design to sequential design entails additional complexity. The same is true with your sequential models in Verilog. We'll need to learn some new keywords:
There is much to discuss here, and I won't do it. It's beyond the scope of our class. To wet your beak, here's an example of a D flipflop that is positive edge-triggered with a reset. This example is from page 294 of our text, though you'll notice that it doesn't match exactly. Figure 6-34 is wrong because it declares Q as both an output and a reg. This is fixed up below:
Finally, I snuck in a new symbol, <=, in this example. There are two flavors of assignment statements within a process: blocking and non-blocking. Blocking assignments, identified with just an equals sign (=), are handled sequentially. Non-blocking assignments, the <= flavor we have above, are evaluate the right-hand side of all non-blocking assignments before changing any values. It's a subtle point that (again) is mostly beyond our scope. Finite State MachinesJust as with software languages, there are a zillion ways to do finite state machines in Verilog. I'll show you one way here. It's the method presented in out text on pages 295-297. In these pages, Verilog code for the "sequence recognizer" (as shown in the state diagram of Figure 6-24(d) on page 271) of Chapter 6 is presented. Within the module for this design, there are three processes. Let's call then "current state", "next state" and "output". Each process deals separately with the issues of "current state", "next state" and setting the output signals. Here's the setup of the module:
The current state is positive edge-triggered and also dependent on the RESET input. This process is similar to the one in the D flipflop above.
The "next state" process uses the keywords case and endcase which are similar to a switch in C++. Notice that this process is activated on any change in input X or the current state.
The final "output signal" process sets the value of the output signal based on the current state and the input signal X.
This is one clean, easy approach (separate processes for state, next state, and outputs) that can generally be applied to many FSM problems. Read on...Some of the other really important areas of Verilog we won't cover:
Done... yow, bill Mar 2004 |