ducna
Newbie level 6
scrambler vhdl
I am writing a program about seft synchronous scrambler (meaning that not need synchronization - data stream (A)-> scrambler -> descramber -> restore the same origin (A)) with generator polynomial : x^7 + x^4 +1 but when simulation , i see dataout not the same data in, can anyone help me, my code
scrambler.vhd
--Data randomizer (scrambler)
--Generator polynomial R(x) = x^7 + x^4 + 1
Library ieee;
Use ieee.std_logic_1164.all;
entity scrambler is
port(
reset : in std_logic;
datain : in std_logic; -- input bit
clock : in std_logic; -- data shift clock
-- scrambled output
dataout : out std_logic
);
end scrambler;
architecture behaviour of scrambler is
signal shift_reg: std_logic_vector(6 downto 0); -- shift register
signal dout : std_logic;
begin
process(clock,reset, datain)
begin
if reset = '1' then
shift_reg <= (others=>'1');
dout <= datain;
elsif (clock'event and clock='1') then
dout <= datain xor shift_reg(6) xor shift_reg(3);
shift_reg(0) <= dout;
shift_reg(1) <= shift_reg(0);
shift_reg(2) <= shift_reg(1);
shift_reg(3) <= shift_reg(2);
shift_reg(4) <= shift_reg(3);
shift_reg(5) <= shift_reg(4);
shift_reg(6) <= shift_reg(5);
end if;
end process;
dataout <= dout;
end behaviour;
descrambler
Library ieee;
Use ieee.std_logic_1164.all;
entity descram is
port(
reset : in std_logic;
datain : in std_logic; -- input bit
clock : in std_logic; -- data shift clock
-- descrambled output bit
dataout : out std_logic
);
end descram;
architecture behaviour of descram is
signal shift_reg: std_logic_vector(6 downto 0); -- shift register
begin
process(reset, clock, datain)
begin
if reset = '1' then
shift_reg <= (others=>'1');
dataout <= datain;
elsif (clock'event and clock='1') then
shift_reg(0) <= datain;
shift_reg(1) <= shift_reg(0);
shift_reg(2) <= shift_reg(1);
shift_reg(3) <= shift_reg(2);
shift_reg(4) <= shift_reg(3);
shift_reg(5) <= shift_reg(4);
shift_reg(6) <= shift_reg(5);
dataout <= datain xor shift_reg(6) xor shift_reg(3);
end if;
end process;
end behaviour;
and testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY tb_scram_vhd IS
END tb_scram_vhd;
ARCHITECTURE behavior OF tb_scram_vhd IS
COMPONENT scrambler
PORT(
reset : IN std_logic;
datain : IN std_logic;
clock : IN std_logic;
dataout : OUT std_logic
);
END COMPONENT;
COMPONENT descram
PORT(
reset : IN std_logic;
datain : IN std_logic;
clock : IN std_logic;
dataout : OUT std_logic
);
END COMPONENT;
SIGNAL sdin : std_logic:= '0';
SIGNAL sdout : std_logic:= '0';
SIGNAL dsdin : std_logic:= '0';
SIGNAL dsdout : std_logic:= '0';
--Generate data to test
signal data : std_logic_vector(63 downto 0);
signal clk : std_logic:= '0';
SIGNAL reset : std_logic:= '1';
SIGNAL notclk : std_logic;
BEGIN
reset <= '0' after 180 ns;
clk <= not clk after 50 ns; -- about 8448K (E2)
notclk <= not clk;
PROCESS (clk)
begin
if reset = '1' then
data <= "1111111011011100101110101001100001110110010101000011001000010000";
elsif clk'event and clk = '1' then
data <= data(62 downto 0) & data(63) ;
end if ;
end process ;
sdin <= data(63);
uscram: scrambler PORT MAP(
reset => reset,
datain => sdin,
clock => notclk,
dataout => sdout
);
dsdin <= sdout;
udscram: descram PORT MAP(
reset => reset,
datain => dsdin,
clock => clk,
dataout => dsdout
);
END;
I am writing a program about seft synchronous scrambler (meaning that not need synchronization - data stream (A)-> scrambler -> descramber -> restore the same origin (A)) with generator polynomial : x^7 + x^4 +1 but when simulation , i see dataout not the same data in, can anyone help me, my code
scrambler.vhd
--Data randomizer (scrambler)
--Generator polynomial R(x) = x^7 + x^4 + 1
Library ieee;
Use ieee.std_logic_1164.all;
entity scrambler is
port(
reset : in std_logic;
datain : in std_logic; -- input bit
clock : in std_logic; -- data shift clock
-- scrambled output
dataout : out std_logic
);
end scrambler;
architecture behaviour of scrambler is
signal shift_reg: std_logic_vector(6 downto 0); -- shift register
signal dout : std_logic;
begin
process(clock,reset, datain)
begin
if reset = '1' then
shift_reg <= (others=>'1');
dout <= datain;
elsif (clock'event and clock='1') then
dout <= datain xor shift_reg(6) xor shift_reg(3);
shift_reg(0) <= dout;
shift_reg(1) <= shift_reg(0);
shift_reg(2) <= shift_reg(1);
shift_reg(3) <= shift_reg(2);
shift_reg(4) <= shift_reg(3);
shift_reg(5) <= shift_reg(4);
shift_reg(6) <= shift_reg(5);
end if;
end process;
dataout <= dout;
end behaviour;
descrambler
Library ieee;
Use ieee.std_logic_1164.all;
entity descram is
port(
reset : in std_logic;
datain : in std_logic; -- input bit
clock : in std_logic; -- data shift clock
-- descrambled output bit
dataout : out std_logic
);
end descram;
architecture behaviour of descram is
signal shift_reg: std_logic_vector(6 downto 0); -- shift register
begin
process(reset, clock, datain)
begin
if reset = '1' then
shift_reg <= (others=>'1');
dataout <= datain;
elsif (clock'event and clock='1') then
shift_reg(0) <= datain;
shift_reg(1) <= shift_reg(0);
shift_reg(2) <= shift_reg(1);
shift_reg(3) <= shift_reg(2);
shift_reg(4) <= shift_reg(3);
shift_reg(5) <= shift_reg(4);
shift_reg(6) <= shift_reg(5);
dataout <= datain xor shift_reg(6) xor shift_reg(3);
end if;
end process;
end behaviour;
and testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY tb_scram_vhd IS
END tb_scram_vhd;
ARCHITECTURE behavior OF tb_scram_vhd IS
COMPONENT scrambler
PORT(
reset : IN std_logic;
datain : IN std_logic;
clock : IN std_logic;
dataout : OUT std_logic
);
END COMPONENT;
COMPONENT descram
PORT(
reset : IN std_logic;
datain : IN std_logic;
clock : IN std_logic;
dataout : OUT std_logic
);
END COMPONENT;
SIGNAL sdin : std_logic:= '0';
SIGNAL sdout : std_logic:= '0';
SIGNAL dsdin : std_logic:= '0';
SIGNAL dsdout : std_logic:= '0';
--Generate data to test
signal data : std_logic_vector(63 downto 0);
signal clk : std_logic:= '0';
SIGNAL reset : std_logic:= '1';
SIGNAL notclk : std_logic;
BEGIN
reset <= '0' after 180 ns;
clk <= not clk after 50 ns; -- about 8448K (E2)
notclk <= not clk;
PROCESS (clk)
begin
if reset = '1' then
data <= "1111111011011100101110101001100001110110010101000011001000010000";
elsif clk'event and clk = '1' then
data <= data(62 downto 0) & data(63) ;
end if ;
end process ;
sdin <= data(63);
uscram: scrambler PORT MAP(
reset => reset,
datain => sdin,
clock => notclk,
dataout => sdout
);
dsdin <= sdout;
udscram: descram PORT MAP(
reset => reset,
datain => dsdin,
clock => clk,
dataout => dsdout
);
END;