CS 232: Lab #4

Lab 4: Connecting components in VHDL

The purpose of this lab is to get you working with multiple VHDL files and connecting them without using a BDF file.


Tasks

  1. Start Quartus. Follow the new project wizard and create a new directory for lab 4. Call your project calc. This is the name of the project and the top level entity, but it will not be the only design file you create and use.
  2. Select File->New and create a new VHDL file. Use the following as a template for your file. The template defines the inputs and outputs, but has an empty architecture.
    -- simple template
    
    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    
    entity calc is
      port 
      (
        a      : in unsigned  (3 downto 0);
        b      : in unsigned  (3 downto 0);
        c      : in std_logic_vector (1 downto 0);
        result : out unsigned (4 downto 0)
      );
    
    end entity;
    
    architecture rtl of calc is
    begin
    
    end rtl;
    

    Save the file as calc.vhd and add it to your project.

  3. Now create another VHDL file called alu.vhd. Use exactly the same template as above, but change the entity name to alu in both the entity and architecture statements. Change the parameter names to d, e, f, and q. Save the file and add it to your project.

    Make a process statement in the architecture body that is sensitive to signals d, e, and f. Then make a case statement on f which has the cases "00", "01", "10", and others. Have case "00" assign to q the sum of d and e. Have case "01" assign to q the difference of d and e. Have case "10" assign to q the bitwise AND of d and e. Have case "11" (others) assign to q the bitwise OR of d and e. Note that you'll need to pad the 4-bit numbers to convert them to 5-bit numbers. For example:

    q <= ('0' & a) + ('0' & b));

  4. Go back to the calc.vhd file. Use the following component declaration template. Put it in the declaration section of the architecture.
    component <entity>
        <port statement>
    end component;
    

    Copy the port statement from alu.vhd into the component statement. Replace <entity> with alu.

  5. In the body of your architecture, make an instance of the alu component. To make an instance of another circuit--like adding a component to a BDF diagram--you use the port map statement. A port map statement needs a unique name, the name of the component, then port map and the argument list. The code below is how you would create one instance of the ALU.
      alu1: alu
        port map( d => a, e => b, f => c, q => result );
    

    In the argument list, the first symbol is the parameter name and the second symbol is the local variable you are connecting to it.

  6. Compile your files to check the syntax (Analyze File).
  7. Download the file calcbench.vhd, which is a test file for the calc circuit. Then open a new terminal, cd to your working directory, and execute the following commands in a terminal in order to simulate and test the circuit.

    ghdl -a calcbench.vhd calc.vhd alu.vhd
    ghdl -e calcbench
    ghdl -r calcbench --vcd=calcbench.vcd
    gtkwave calcbench.vcd

    If you insert all of the signals into the view window, it should look like the following. Note that you can make the signals somewhat easier to read by right-clicking on a signal name and then selecting Data Format::Decimal.

    GTKwave output

When you have completed the lab assignment, go ahead and get started on the current project.