Project

General

Profile

1081 markw
---------------------------------------------------------------------------
1132 markw
-- (c) 2020 mark watson
1081 markw
-- 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 sigmadelta_2ndorder IS
PORT
(
CLK : IN STD_LOGIC;
RESET_N : IN STD_LOGIC;
1087 markw
ENABLE : IN STD_LOGIC := '1';
1081 markw
AUDIN : IN UNSIGNED(15 downto 0);
AUDOUT : OUT std_logic
);
END sigmadelta_2ndorder;

ARCHITECTURE vhdl OF sigmadelta_2ndorder IS
1087 markw
signal ttl1_next : signed(21 downto 1);
signal ttl1_reg : signed(21 downto 1);
1134 markw
signal ttl2_next : signed(23 downto 1);
signal ttl2_reg : signed(23 downto 1);
1081 markw
signal out_next : std_logic;
signal out_reg : std_logic;
BEGIN

process(clk,reset_n)
begin
if (reset_n='0') then
ttl1_reg <= (others=>'0');
ttl2_reg <= (others=>'0');
out_reg <= '0';
elsif (clk'event and clk='1') then
ttl1_reg <= ttl1_next;
ttl2_reg <= ttl2_next;
out_reg <= out_next;
end if;
end process;


--a1= -2.00000;
--a2= -10.00000;
--b1= 2.00000;
--c1= 2.00000;
--c2= 1.00000;
1132 markw

1089 markw
process(audin,out_reg,ttl1_reg,ttl2_reg,enable)
1132 markw
variable audinadj : unsigned(16 downto 0);
1087 markw
variable fb : signed(21 downto 0);
1090 markw
variable ttl1_tmp : signed(21 downto 1);
1081 markw
begin
1087 markw
out_next <= out_reg;
ttl1_next <= ttl1_reg;
ttl2_next <= ttl2_reg;

if (enable='1') then
1132 markw
audinadj := resize(audin,17) + to_unsigned(4096,17) - resize(audin(15 downto 3) ,17);

1087 markw
fb:=(others=>'0');
1134 markw
if (ttl2_reg(23 downto 16)>0) then
1087 markw
fb(16) := '1';
else
fb(16) := '0';
end if;

1132 markw
ttl1_tmp := ttl1_reg + resize(signed("0"&audinadj),22-1) - (fb(21-1 downto 0));
1090 markw
ttl1_next <= ttl1_tmp;
1087 markw
1134 markw
ttl2_next <= ttl2_reg + resize(((ttl1_tmp(21-1 downto 1)&"0") - ((fb(21-1 downto 0))+(fb(21-3 downto 0)&"00"))),23);
1087 markw
out_next <= fb(16);
1081 markw
end if;
end process;

audout <= out_reg;

end vhdl;