Introduction to VHDL and MAX+plus II

VHDL, or VHSIC (Very High Speed Integrated Circuits) Hardware Description Language, was developed by the Department of Defense in 1983 for describing hardware design from a software level.

The basic building blocks of VHDL design are the ENTITY declaration and the ARCHITECTURE body. Note that comments in VHDL code can be inserted by adding    -- comment here    anywhere in the code. The comment will continue until the end of the line. There is no way to terminate a comment except an end-of-line.

In the following code examples, we use the convention that UPPER CASE words are reserved words in VHDL, while lower case words are identifiers chosen by the programmer.

ENTITY

The ENTITY declaration describes only the input and output ports of the design. The highest level of any VHDL design is a single ENTITY declaration. For MAX+plus II to compile your project, the VHDL file name must be the same as the entity name. For instance, the following ENTITY declaration must be stored in the file counter_4.vhd.

The internal relationship between the inputs and the outputs is not specified. At this stage, the entire design is treated as a "black box", with no knowledge of its internal workings. Signals that enter and leave this box must be declared in the PORT declaration.

ENTITY counter_4 IS PORT(
    clk, reset, load_counter:   IN BIT;
    data:                       IN BIT_VECTOR( 3 DOWNTO 0 );
    count_zero:           	OUT BIT;
    count:                      BUFFER BIT_VECTOR( 3 DOWNTO 0 ) 
    );
END counter_4;

(Note that the last entry in the PORT declaration is not followed by a semicolon.)

Each signal has a signal mode (IN, OUT, BUFFER) and a signal type (BIT, BIT_VECTOR).

The signal mode determines how the entity will read and write to each signal. There are four different signal modes:

The signal type must also be declared in the PORT declaration. Signal type describes the possible values the signal can take, and can describe a vector of similar signal types.

The simplest signal types are the BIT and BIT_VECTOR types. The only allowed values for the BIT type are '0' and '1'. (Note that single bit values are assigned values by using single quotes:
     bit_signal <= '0';
The BIT and BIT_VECTOR types are intrinsic to the VHDL language, and so they require no library declarations (see the description for std_logic below).

The BIT_VECTOR type must be declared with a value for the vector range. For this type, it is declared as
     bit_vector_signal : BIT_VECTOR( maximum_index DOWNTO 0 );
and makes a vector with maximum_index+1 elements. These elements can be individually referenced in the architecture body as      signal_vector_name( index_value )
where index_value must be between 0 and maximum_index. For instance:
     bit_vector_signal(0) <= bit_signal;
assigns the value of  bit_signal  to the first element (index 0) of the bit vector  bit_vector_signal .

An entire bit vector can be assigned a value by using double quotes:
     bit_vector_signal <= "0001";
This statement assigns  '1'  to  bit_vector_signal(0) , and  '0'  to the other three bit values in this vector.

The std_logic and std_logic_vector types are part of the ieee library, and can have the values '0', '1', '-' (don't care), 'Z' (high impedance), or 'X' (indeterminate). The additional values allow more detailed simulations to be performed, and allow the layout editor to optimize logic in the case of assignments to the "don't care" value. To use these types, you must add LIBRARY and USE statements before your entity declaration:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY counter_4 IS PORT(
    clock, reset, load_counter: IN std_logic;
    data:                       IN std_logic_vector( 3 DOWNTO 0 );
    reset_alert:                OUT std_logic;
    count:                      BUFFER std_logic_vector( 3 DOWNTO 0 ) 
    );
END counter_4;

It is important not to mix BIT and std_logic types in your code. The two types must be converted using resolution functions ("To_bit", "To_bitvector", "To_StdULogic", "To_StdULogicvector") before assigning std_logic signals to bits and vice versa. These functions will considerably complicate your code. In your design, use exclusively BIT and BIT_VECTOR types, or exclusively std_logic and std_logic_vector types. The remainder of this discussion will use only BIT and BIT_VECTOR types.

ARCHITECTURE

The functional relationships between the IN signals and the OUT signals (and the BUFFER signals) are specified in the ARCHITECTURE body. While you can write several different architectures for one entity, only one may appear in your finished VHDL code.

ENTITY full_adder IS PORT (
    a, b, carry_in :   IN BIT;
    sum, carry_out:    OUT  BIT 
    );
END full_adder;

ARCHITECTURE architecture_name OF full_adder IS
--  List of internal signals here
--  List of components here
BEGIN
--
--  Architecture statements here
--
END architecture_name;

There are three styles of ARCHITECTURE statements. You can mix several styles in your design, but you should be aware of the different statement types in each style, since some cannot be interchanged between two styles.

Other Data Objects

To simplify your coding, you can define data objects other than signals.

 

Altera VHDL compiler (MAX+plus II)

The compiler used to compile and execute (simulate) your VHDL programs is called MAX+plus II and is designed by Altera.

Using MAX+plus II Examples on an NT Workstation

 

  1. Create a directory called max2work in your home directory.
  2. Download the self-extracting executable VHDL_examples.exe into the max2work directory.
  3. Extract these files by double-clicking on the file's icon; it should be set to extract to the destination directory "Z:\max2work". (If you prefer a zip file, the same files are in VHDL_examples.zip.)
  4. Double-click on the desktop icon Xtelnet ugrad.ses.
  5. Log in to the XTERM server (same user ID and password as for NT), and click on the "Click here when done" bar at the "Message of the Day" prompt.
  6. Run the compiler by typing maxplus2 at the UNIX command line prompt.
  7. Choose File -> Open and select "max2work\full_adder.vhd".
  8. Select File -> Project -> Set Project to Current File. This makes a project out of the VHDL file.
  9. Select File -> Project -> Save, Compile and Simulate.
  10. If it compiles, choose Open SCF to enter the waveform editor.
  11. If it does not compile, go to the compiler window (choose MAX+plus II -> Compiler) then select: Interfaces -> VHDL Netlist Reader Settings. From this window, select VHDL 1993, then hit OK. Then select File -> Project -> Save, Compile and Simulate again.

Complete VHDL Example in MAX+plus II

The problem: To construct a full adder that adds 2 bits and a carry_in bit, producing a single bit sum and carry out. Then, build a 4-bit ripple carry adder using this single bit full adder.

The high level structure of the full adder is:

The full adder is implemented as a VHDL program in full_adder.vhd. If you have downloaded the Examples file, it is in the folder "full_adder_dataflow" along with an SCF file showing the 8 possible inputs.

The high level structure of the ripple carry adder is:

The implementation is in ripple_adder.vhd. This file uses the previously specified full adder as a COMPONENT. The complete example is in the folder "ripple_adder" along with an SCF file showing some of the possible inputs.

 

Printing from the UNIX machines

It might not be possible to directly print from the Print menu in MAX+plus II. In this case follow these steps:

  1. Go to File -> Print Setup. Click Options
  2. Choose Encapsulated Postscript file and give a name. Click OK.
  3. Now when you print from MAX+plus II, a postscript file is created in your current directory. This can be printed from a UNIX prompt using lpr filename. In case of problems, consult the lab assistant in the room. Also read the printing directions that are put up in the lab.

Using the Graphic Editor in MAX+plus II

If you have extra time on your projects, you may want to also build your design using gates and flip-flops. The graphic editor in VHDL is quite good, and if you name your inputs and outputs the same as in your VHDL file, you can use the same waveform editor file! One of the examples in the VHDL_examples file is a graphic design, in the directory counter_4_graphic. It uses D-flip flops to store the four bits of the counter, with similar combinational logic to the VHDL counter example (in counter_4_vhdl).

HELP!

There is online help for MAX+plus II, but it can be very confusing. A better place to start is the introduction to VHDL in sections 2.6, 3.11, and 4.5 of the textbook. You can also try some resources on the web:

The best way to learn VHDL and MAX+plus II is by working with the software, and creating working projects that use an increasing set of VHDL syntax. Start with a simple example, and once you have it working, expand on it piece by piece. If you still have questions, you can email the teaching assistant.

This introduction was written by John Pipan, Bob McIlhenny, and Anand Panangadan.