Project

General

Profile

1009 markw
---------------------------------------------------------------------------
-- (c) 2020 mark watson
-- I am happy for anyone to use this for non-commercial use.
-- If my vhdl files are used commercially or otherwise sold,
-- please contact me for explicit permission at scrameta (gmail).
-- This applies for source and binary form and derived works.
---------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.numeric_std.all;

1036 markw
ENTITY PSG_noise IS
1009 markw
PORT
(
CLK : IN STD_LOGIC;
RESET_N : IN STD_LOGIC;
ENABLE : IN STD_LOGIC;
1053 markw
TICK : IN STD_LOGIC;
1009 markw
BIT_OUT : OUT STD_LOGIC
);
1036 markw
END PSG_noise;
1009 markw
1036 markw
ARCHITECTURE vhdl OF PSG_noise IS
1009 markw
signal shift_reg: std_logic_vector(16 downto 0);
signal shift_next: std_logic_vector(16 downto 0);
1053 markw
signal noise_reg : std_logic;
signal noise_next : std_logic;
1009 markw
BEGIN
-- register
process(clk, reset_n)
begin
if (reset_n = '0') then
shift_reg <= (others=>'0');
1053 markw
noise_reg <= '0';
1009 markw
elsif (clk'event and clk='1') then
shift_reg <= shift_next;
1053 markw
noise_reg <= noise_next;
1009 markw
end if;
end process;

1053 markw
-- next state lfsr
1009 markw
process(shift_reg,enable)
begin
shift_next <= shift_reg;
if (enable = '1') then
shift_next <= (shift_reg(3) xnor shift_reg(0))&shift_reg(16 downto 1);
end if;
end process;
1053 markw
-- next state output
process(shift_reg,noise_reg,tick)
begin
noise_next <= noise_reg;
if (tick = '1') then
noise_next <= shift_reg(0);
end if;
end process;
1009 markw
-- output
1053 markw
bit_out <= noise_reg;
1009 markw
END vhdl;