I'm creating an n bit shift register. When the enable signal is high, I want the shift register to shift n times, irrespective of whether enable continues to be high or low. I've put a for loop to shift n times inside a process. My code is given below.
I don't think the for loop is working, as the shifting is not restricted to n times. Where am I going wrong?
library ieee;
use ieee.std_logic_1164.all;
entity SReg is
generic (
n : integer := 4
);
port(
clk: in std_logic;
reset: in std_logic;
enable: in std_logic; --enables shifting
parallel_in: in std_logic_vector(n-1 downto 0);
s_in: in std_logic; --serial input
s_out: out std_logic --serial output
);
end SReg;
architecture behavioral of SReg is
signal temp_reg: std_logic_vector(n-1 downto 0) := (Others => '0');
begin
process (clk,reset)
begin
if (reset = '1') then
temp_reg <= parallel_in;
elsif (clk'event and clk='1') then
if (enable ='1') then
--shifting n number of bits
for i in 0 to n-1 loop
s_out <= temp_reg(0);
temp_reg <= s_in & temp_reg(n-1 downto 1);
end loop;
end if;
end if;
end process;
end behavioral;
No comments:
Post a Comment