This project implements a 4-bit shift register in VHDL with the following operations based on a 2-bit select input:
A Shift Register is a sequential logic circuit used to store and manipulate binary data. It consists of flip-flops connected in a chain, where data is shifted in or out based on the clock signal.
This project implements a 4-bit universal shift register that can:
srsi (Shift Right Serial Input).slsi (Shift Left Serial Input).ba (Bus Input) directly into the register.0000 regardless of the select input.library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ShiftReg is port (
rst, clk:in std_logic;
s:in std_logic_vector(1 downto 0);
ba:in std_logic_vector(3 downto 0);
srsi,slsi:in std_logic;
rc:inout std_logic_vector ( 3 downto 0 )
);
end ShiftReg;
architecture Behavioral of ShiftReg is
begin
process (clk)
begin
if rising_edge(clk) then
if rst ='1' then rc <= "0000";
else
case s is
when "00" => rc <= rc;
when "01" => rc(3) <= srsi; rc(2) <= rc(3); rc(1) <= rc(2); rc(0) <= rc(1);
when "10" => rc(3) <= rc(2); rc(2) <= rc(1); rc(1) <= rc(0); rc(0) <= slsi;
when "11" => rc <= ba;
when others => null;
end case;
end if;
end if;
end process;
end Behavioral;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.ALL;
ENTITY tb_ShiftReg IS
END tb_ShiftReg;
ARCHITECTURE behavior OF tb_ShiftReg IS
-- Component Declaration
COMPONENT ShiftReg
PORT(
rst : IN std_logic;
clk : IN std_logic;
s : IN std_logic_vector(1 downto 0);
ba : IN std_logic_vector(3 downto 0);
srsi : IN std_logic;
slsi : IN std_logic;
rc : INOUT std_logic_vector(3 downto 0)
);
END COMPONENT;
-- Testbench signals
signal rst : std_logic := '0';
signal clk : std_logic := '0';
signal s : std_logic_vector(1 downto 0) := "00";
signal ba : std_logic_vector(3 downto 0) := "0000";
signal srsi : std_logic := '0';
signal slsi : std_logic := '0';
signal rc : std_logic_vector(3 downto 0);
-- Clock period
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: ShiftReg PORT MAP (
rst => rst,
clk => clk,
s => s,
ba => ba,
srsi => srsi,
slsi => slsi,
rc => rc
);
-- Clock process
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
-- Reset the shift register
rst <= '1';
wait for clk_period;
rst <= '0';
wait for clk_period;
-- Test Parallel Load
ba <= "1010";
s <= "11"; -- Load value into rc
wait for clk_period;
-- Hold value (No operation)
s <= "00";
wait for clk_period;
-- Shift Right
srsi <= '1'; -- New bit from right side
s <= "01";
wait for clk_period;
srsi <= '0';
wait for clk_period;
-- Shift Left
slsi <= '1'; -- New bit from left side
s <= "10";
wait for clk_period;
slsi <= '0';
wait for clk_period;
-- Another Parallel Load
ba <= "1100";
s <= "11";
wait for clk_period;
-- Hold
s <= "00";
wait for clk_period;
wait;
end process;
END;
| Time | s |
Operation | Notes |
|---|---|---|---|
| 0ns | Reset | Clear to 0000 | ย |
| 20ns | โ11โ | Parallel Load | rc = 1010 |
| 30ns | โ00โ | Hold | rc = 1010 |
| 40ns | โ01โ | Right Shift | rc = 1101 (srsi=โ1โ) |
| 60ns | โ10โ | Left Shift | rc = 1010 (slsi=โ1โ) |
| 80ns | โ11โ | Parallel Load | rc = 1100 |
| 90ns | โ00โ | Hold | rc = 1100 |
Simulation โ
Synthesized โ
Hardware Tested โ