Project

General

Profile

740 markw
---------------------------------------------------------------------------
-- (c) 2018 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;
use IEEE.STD_LOGIC_MISC.all;

ENTITY stereo_detect IS
PORT
(
CLK : IN STD_LOGIC;
RESET_N : IN STD_LOGIC;

990 markw
A : IN STD_LOGIC; -- raw
1015 markw
DETECT : OUT STD_LOGIC
740 markw
);
END stereo_detect;

ARCHITECTURE vhdl OF stereo_detect IS
990 markw
signal addr_bit_sync : std_logic;
signal addr_bit_sync_reg : std_logic;
signal addr_bit_toggle_count_next : std_logic_vector(1 downto 0);
signal addr_bit_toggle_count_reg : std_logic_vector(1 downto 0);
740 markw
BEGIN

synchronizer_4 : entity work.synchronizer
990 markw
port map (clk=>clk, raw=>a, sync=>addr_bit_sync);
740 markw
process(clk,reset_n)
begin
if (reset_n='0') then
990 markw
addr_bit_sync_reg <= '1';
addr_bit_toggle_count_reg <= (others=>'0');
740 markw
elsif (clk'event and clk='1') then
990 markw
addr_bit_sync_reg <= addr_bit_sync;
addr_bit_toggle_count_reg <= addr_bit_toggle_count_next;
740 markw
end if;
end process;


1015 markw
process(addr_bit_toggle_count_reg,addr_bit_sync,addr_bit_sync_reg)
740 markw
begin
1015 markw
DETECT <= '0';
990 markw
addr_bit_toggle_count_next <= addr_bit_toggle_count_reg;
740 markw
990 markw
if (addr_bit_toggle_count_reg="11") then
1015 markw
DETECT <= '1';
740 markw
else
990 markw
if (not(addr_bit_sync = addr_bit_sync_reg)) then
addr_bit_toggle_count_next <= std_logic_vector(unsigned(addr_bit_toggle_count_reg)+1);
740 markw
end if;
end if;
end process;

end vhdl;