Verilog OverviewCreated: Mar 2004, Updated: Apr 2006 This overview 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. The sections inside are:
enjoy... yow, bill 1. IntroductionSome Verilog basics:
2. ModulesModules are the basic building blocks of Verilog. Every design or design part is a module. Modules are like functions or methods in that they have parameters. These are the inputs to the module. Instead of a return value, modules have output parameters that are defined is a fashion similar to input 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):
Module parameters may be multiple bits wide. Here's an example:
3. Structural DescriptionsVerilog can be used to represent logic diagrams 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 AND8: an 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.
4. Boolean EquationsThe format for Boolean equations in Verilog is a little 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 my_function with 3 inputs and 2 outputs, defined using Boolean operators:
5. 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 in different ways: as gates, as equations, as a combination, etc. 6. 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 a lot of nuance to sequential descriptions that goes beyond the scope of our class. To wet your beak though, 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. 7. 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 (on CLK)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. 8. More ReadingI don't really have a good book to which I can refer you. Sorry. there is a lot of online material to help, however. I'll start at Wikipedia (of course): en.wikipedia.org/wiki/Verilog This page has a few nice starter examples. The best thing about the page is probably the links at the bottom. Yow! A comment on a couple of those tasty links:
Just FYI, some of the other really important areas of Verilog we won't cover:
thanks... yow, bill |