Saturday, 27 June 2015

VHDL nbit register with load hold control - 4 bit register structural design code test in circuit and test bench ISE Xilinx

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

The complete video tutorial at:

https://youtu.be/_lZcWH0gjIw?list=PLZqHwo1YWqVMSdkQOYC_W0o59LWnZvFn4

The design in this lab covers the basics of microcontrolller structural design

Intended Controlled datapath design design:







Datapath and controller internals:




This is another components which will be used to construct the datapath. Refer to the lab sheets(lab 3):


VHDL code:

 library IEEE;  
 use IEEE.STD_LOGIC_1164.ALL;  
 entity nbitregloadhold is  
 generic(n:positive:=4);  
   Port ( Dinputs : in STD_LOGIC_VECTOR (n-1 downto 0);  
       loadhold : in STD_LOGIC;  
       CLK : in STD_LOGIC;  
       reset : in STD_LOGIC;  
       preset : in STD_LOGIC;  
       qoutputs : inout STD_LOGIC_VECTOR (n-1 downto 0));  
 end nbitregloadhold;  
 architecture Behavioral of nbitregloadhold is  
 component nbitregister   
 generic(n:positive:=4);  
   Port ( Dinputs : in STD_LOGIC_VECTOR (n-1 downto 0);  
       clk : in STD_LOGIC;  
       reset : in STD_LOGIC;  
       preset : in STD_LOGIC;  
       q : out STD_LOGIC_VECTOR (n-1 downto 0);  
       qnot : out STD_LOGIC_VECTOR (n-1 downto 0));  
 end component;  
 component nbittwoinputmux   
 generic(n:positive:=4);  
   Port ( InA : in STD_LOGIC_VECTOR (n-1 downto 0);  
       InB : in STD_LOGIC_VECTOR (n-1 downto 0);  
       Control : in STD_LOGIC;  
       Output : out STD_LOGIC_VECTOR (n-1 downto 0));  
 end component;  
 signal toreg,dummyq:std_logic_vector(n-1 downto 0);  
 begin  
 A: nbittwoinputmux port map(qoutputs,Dinputs,loadhold,toreg);  
 B: nbitregister port map(toreg, CLK, reset,preset,qoutputs, dummyq);  
 end Behavioral;  


Test bench code:

 LIBRARY ieee;  
 USE ieee.std_logic_1164.ALL;  
 ENTITY nbitregloadholdtestbench IS  
 END nbitregloadholdtestbench;  
 ARCHITECTURE behavior OF nbitregloadholdtestbench IS   
   -- Component Declaration for the Unit Under Test (UUT)  
   COMPONENT nbitregloadhold  
   PORT(  
      Dinputs : IN std_logic_vector(3 downto 0);  
      loadhold : IN std_logic;  
      CLK : IN std_logic;  
      reset : IN std_logic;  
      preset : IN std_logic;  
      qoutputs : INOUT std_logic_vector(3 downto 0)  
     );  
   END COMPONENT;  
   --Inputs  
   signal Dinputs : std_logic_vector(3 downto 0) := (others => '0');  
   signal loadhold : std_logic := '0';  
   signal CLK : std_logic := '0';  
   signal reset : std_logic := '0';  
   signal preset : std_logic := '0';  
      --BiDirs  
   signal qoutputs : std_logic_vector(3 downto 0);  
   -- Clock period definitions  
   constant CLK_period : time := 10 ns;  
 BEGIN  
      -- Instantiate the Unit Under Test (UUT)  
   uut: nbitregloadhold PORT MAP (  
      Dinputs => Dinputs,  
      loadhold => loadhold,  
      CLK => CLK,  
      reset => reset,  
      preset => preset,  
      qoutputs => qoutputs  
     );  
  clk_process :process  
   begin  
           CLK <= '0';  
           wait for clk_period/2;  
           CLK <= '1';  
           wait for clk_period/2;  
   end process;  
   -- Stimulus process  
   stim_proc: process  
   begin            
    -- hold reset state for 100 ns.  
    wait for 100 ns;       
            wait for 100 ns;       
    Dinputs <= "1001" ;  
              wait for 100 ns;       
                loadhold <= '1';  
                             wait for 100 ns;       
              wait for 100 ns;        
                loadhold <= '0';  
              wait for 100 ns;       
                     reset <= '1';  
                     wait for 100 ns;        
                          reset <= '0';  
                     preset <= '1';  
              wait for 100 ns;       
                     preset <= '0';  
    wait for clk_period*10;  
    -- insert stimulus here   
    wait;  
   end process;  
 END;  


Component ( 4 bit - nbit two input multiplexer ) code in the video description



Component ( nbit - 4 bit - register ) code in the video description


No comments:

Post a Comment