Friday, 5 June 2015

VHDL half adder code test in circuit and test bench xilinx spartan 3 development board

This video is part of a series which final design is a Controlled Datapath using a structural approach. A Structural approach consist in designing all components needed for the design such as gates to form subsystems and then joining them together to form a larger design like adders and Arithmetic logic units,etc.

The design in these labs was first developed in VHDL you can check the final VHDL version in the link below as well as intructions on how to set up the Waveshare development board to get started, the setup is the same for VHDL and Verilog:

Lab Sheets:
http://viahold.com/y37

Lab guide

http://cogismith.com/1OwP

This tutorial uses components to understand the basics of microcontroller design.


Intended Microcontroller design:







Datapath and controller internals:

     

Parts working on now:

Constructing the alu:

For constructing the ALU we need an adder, the adder is formed by two half adders and the half adder is formed with gates. Refer to the lab sheets:

  

VHDL code:

 library IEEE;  
 use IEEE.STD_LOGIC_1164.ALL;  
 entity halfadder is  
   Port ( a : in STD_LOGIC;  
       b : in STD_LOGIC;  
       sum : out STD_LOGIC;  
       cout : out STD_LOGIC);  
 end halfadder;  
 architecture Behavioral of halfadder is  
 begin  
 sum<= a xor b;  
 cout<=a and b;  
 end Behavioral;  
 --INPUTS         OUTPUTS  
 --A       B       SUM   CARRY  
 --0       0       0       0  
 --0       1       1       0  
 --1       0       1       0  
 --1       1       0       1  



Testbench

 LIBRARY ieee;  
 USE ieee.std_logic_1164.ALL;  
 ENTITY halfadder_test IS  
 END halfadder_test;  
 ARCHITECTURE behavior OF halfadder_test IS   
   -- Component Declaration for the Unit Under Test (UUT)  
   COMPONENT halfadder  
   PORT(  
      a : IN std_logic;  
      b : IN std_logic;  
      sum : OUT std_logic;  
      cout : OUT std_logic  
     );  
   END COMPONENT;  
   --Inputs  
   signal a : std_logic := '0';  
   signal b : std_logic := '0';  
       --Outputs  
   signal sum : std_logic;  
   signal cout : std_logic;  
   -- No clocks detected in port list. Replace <clock> below with   
   -- appropriate port name   
 BEGIN  
      -- Instantiate the Unit Under Test (UUT)  
   uut: halfadder PORT MAP (  
      a => a,  
      b => b,  
      sum => sum,  
      cout => cout  
     );  
   -- Clock process definitions  
   -- Stimulus process  
   stim_proc: process  
   begin            
    -- hold reset state for 100 ns.  
    wait for 100 ns;       
   a <= '0';   
      b <= '0';   
      wait for 100 ns;  
      a <= '1';   
      b <= '0';   
      wait for 100 ns;  
      a <= '0';  
      b <= '1';   
      wait for 100 ns;  
      a <= '1';   
      b <= '1';   
    wait;  
   end process;  
 END;  

No comments:

Post a Comment