The objectives of this session are:
In the Netscape window where you are reading this, you can create a second window so that you can read these instructions and explore the web pages at the same time.
A new window should appear. This can also be done using the "File" entry in the menu bar and selecting a New Web Browser.
In the new window, find you way back to the Gateway page - and take a brief look at the sort of documents and links there to get an idea of what resources are available.
Next, enter the Verilog resource area and do the same - and finally enter the Verilog manual.
During this session and the following one, you should aim to read through the manual and the examples contained within it. But for now, let's learn the editor.
The idea is to run through the on-line tutorial in the Xemacs editor. This can be called by clicking on the Gateway icon in the top right of your screen.
To start the tutorial: there is a menu item, under the Help menu bar,J called: Xemacs tutorial. Alternatively, point to the Xemacs window, hold down the "control" key and type "h", release the control key and type "t".
Now - spend as long as necessary learning to use the editor. NOTE: previous students have suggested that ten minutes is enough to learn the few basic commands and that the rest of the tutorial is full of commands which are never used and/or are quickly forgotten. So read and play for about twenty minutes and then come back to the tutorial later if you feel that your editing skills are inadequate.
There are four buttons in the Xemacs editor associated with the Verilog environment:
The first thing we want to do is to pickup some text form the Netscape window and put it into the Xemacs window
SAMPLE PROGRAM ONE
module sayHello;
initial $display("Hello");
endmodule
Notice that the Netscape and Xemacs windows use different key strokes to achieve these operations of copy and paste. However, in both windows the operations can be found in the Edit menu bar. AND in Xemacs there are menu buttons also.
IMPORTANT: files of verilog code MUST end with a ".v" so that the editor knows to do the highlighting properly.
Let us try something else - delete a ";" at the end of the first line - and click on the Verilog button. When the program has run (and the result says that there is an error) click on the Error menu button and watch the two windows jump to indicate where the error occurs. NOTE, missing out the ";" is the most common beginner's error - and NOTE that the error check only notices the problem at the beginning of the next line of text.
Now try to type this program in yourself - in the same Xemacs window watching carefully as the colours change and the returns and indentations are done for you. Make sure you do a final return after the endmodule
Delete the original program (highlight it with the mouse and press the Cut key) - and now run your version to see if there are any errors.
You now have the basic skills. In the Netscape window in which you were exploring the on-line documentation, find the "VERILOG INTRODUCTION" or "Verilog resource" page and look at a small design example: an inverting multiplexor. Copy and Paste this example into the Xemacs window and use File -> Save as to store it in a new file. Run it to see if it works.
Read through the code to see if you can understand the basic structure of the language - the brave might like to enhance it as:
It is important that you TRY this BEFORE looking at the the answers which can be found here .
The objectives of this section are:
You need to read the three documents:
in the GATEWAY to design excellence home page before attempting the following activities.
For each of the following, create the required module and perform simulations which test its function.
module origMod ( <parameter list> );
...
endmodule
module newOne (out, clk, reset, d);
...
someGate (<list of inputs and outputs>)
origMod modName (<list of inputs and outputs>)
...
<something to invert the signal to get the right polarity>
...
endmodule
Now we need to put the above modules together to form more interesting functions - remember that you must write tests to check that you are right.
reg [2:0] regMem;
reg out
...
{out, regMem} = {regMem, in};
module shift(out, clk, in);
output [3:0] out;
input clk;
input [3:0] in;
reg [3:0] shiftMem [0:3];
assign out = shiftMem[3];
always @(posedge clk) begin
shiftMem[3] = shiftMem[2];
shiftMem[2] = shiftMem[1];
shiftMem[1] = shiftMem[0];
shiftMem[0] = in;
end
endmodule // shift
module testShift;
reg [3:0] a;
reg clk;
wire [3:0] out;
integer i;
shift mod1 (out, clk, a);
initial begin
clk = 0;
forever #5 clk = ~clk;
end // initial begin
initial #2 forever #10 $display("%d %d", a, out);
initial begin
i = 0;
repeat (9) begin
#10 a = i;
i = i + 1;
end // repeat (9)
#10 $finish;
end // initial begin
endmodule // testShift
The second document recommended above has a section on digital counter design, and the second large worked-example in the on-line manual is also about counters. It might be worth reading these before writing the following code.