From f04ecca4077b5f8723b2a8e0a125bfeacc44214a Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Sun, 19 Feb 2023 13:57:55 +0100 Subject: single frequency implementation --- basys3/basys3.srcs/apu_LUT_reader.vhd | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 basys3/basys3.srcs/apu_LUT_reader.vhd (limited to 'basys3/basys3.srcs/apu_LUT_reader.vhd') diff --git a/basys3/basys3.srcs/apu_LUT_reader.vhd b/basys3/basys3.srcs/apu_LUT_reader.vhd new file mode 100644 index 0000000..2dd3b06 --- /dev/null +++ b/basys3/basys3.srcs/apu_LUT_reader.vhd @@ -0,0 +1,56 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity apu_LUT_reader is + port ( + clk : in std_logic; + rst : in std_logic; + freq : in std_logic_vector(11 downto 0); + wave : in std_logic_vector(1 downto 0); + value : out std_logic_vector(7 downto 0) + ); +end entity; + +architecture Behavioral of apu_LUT_reader is + + signal idx : std_logic_vector(7 downto 0) := (others => '0'); + signal buf : unsigned := (others => '0'); + +begin + + process (clk) + begin + if rst = '1' then + idx <= x"00"; + buf <= x"00"; + elsif rising_edge(clk) then + --main code here + + if wave = "00" then --Sawtooth + value <= idx; + elsif wave = "01" then --Square + if (signed(idx) < 128) then + value <= x"00"; + else + value <= x"FF"; + end if; + elsif wave = "10" then --Triangle + value <= std_logic_vector( abs(signed(idx)-127)*2 ); + else--wave = "11" then --Noise + --implement noise function here: + value <= x"80"; --remove this + end if; + + + + if unsigned(idx) < 255 then --moves to next index value + idx <= std_logic_vector( unsigned(idx) + '1'); + else + idx <= x"00"; + end if; + + end if; + end process; + +end architecture; \ No newline at end of file -- cgit v1.2.3 From 3739edf5d5adc7a79aa9fd050d45493d697eaa92 Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Sun, 19 Feb 2023 14:02:12 +0100 Subject: apu_LUT_reader made with variable frequency --- basys3/basys3.srcs/apu_LUT_reader.vhd | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'basys3/basys3.srcs/apu_LUT_reader.vhd') diff --git a/basys3/basys3.srcs/apu_LUT_reader.vhd b/basys3/basys3.srcs/apu_LUT_reader.vhd index 2dd3b06..a37cd30 100644 --- a/basys3/basys3.srcs/apu_LUT_reader.vhd +++ b/basys3/basys3.srcs/apu_LUT_reader.vhd @@ -44,10 +44,15 @@ begin - if unsigned(idx) < 255 then --moves to next index value - idx <= std_logic_vector( unsigned(idx) + '1'); + if buf < unsigned(freq) then -- change frequency + buf <= buf + 1; else - idx <= x"00"; + buf <= x"00"; + if unsigned(idx) < 255 then --moves to next index value + idx <= std_logic_vector( unsigned(idx) + '1'); + else + idx <= x"00"; + end if; end if; end if; -- cgit v1.2.3 From f28e1ceec5b9a6ee3f156c3f032eb7a78a08f401 Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Sun, 19 Feb 2023 16:20:20 +0100 Subject: shifted triangle wave 180* --- basys3/basys3.srcs/apu_LUT_reader.vhd | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'basys3/basys3.srcs/apu_LUT_reader.vhd') diff --git a/basys3/basys3.srcs/apu_LUT_reader.vhd b/basys3/basys3.srcs/apu_LUT_reader.vhd index a37cd30..e56f855 100644 --- a/basys3/basys3.srcs/apu_LUT_reader.vhd +++ b/basys3/basys3.srcs/apu_LUT_reader.vhd @@ -14,7 +14,10 @@ end entity; architecture Behavioral of apu_LUT_reader is - signal idx : std_logic_vector(7 downto 0) := (others => '0'); + constant AMPLITUDE : natural := 0; + constant SAMPLE_SIZE : natural := 256; + + signal idx : unsigned := (others => '0'); signal buf : unsigned := (others => '0'); begin @@ -25,21 +28,25 @@ begin idx <= x"00"; buf <= x"00"; elsif rising_edge(clk) then - --main code here + -- main code here - if wave = "00" then --Sawtooth - value <= idx; - elsif wave = "01" then --Square - if (signed(idx) < 128) then + if wave = "00" then -- Sawtooth + value <= std_logic_vector( idx ); + elsif wave = "01" then -- Square + if idx < (SAMPLE_SIZE/2) then value <= x"00"; else value <= x"FF"; end if; - elsif wave = "10" then --Triangle - value <= std_logic_vector( abs(signed(idx)-127)*2 ); - else--wave = "11" then --Noise - --implement noise function here: - value <= x"80"; --remove this + elsif wave = "10" then -- Triangle + if idx < (SAMPLE_SIZE/2) then + value <= std_logic_vector( idx*2 ); + else + value <= std_logic_vector( (SAMPLE_SIZE-idx)*2 ); + end if; + else-- wave = "11" then -- Noise + -- TODO: implement noise function here: + value <= x"80"; -- remove this end if; @@ -48,8 +55,8 @@ begin buf <= buf + 1; else buf <= x"00"; - if unsigned(idx) < 255 then --moves to next index value - idx <= std_logic_vector( unsigned(idx) + '1'); + if idx < (SAMPLE_SIZE-1) then -- moves to next index value + idx <= idx + 1; else idx <= x"00"; end if; @@ -58,4 +65,4 @@ begin end if; end process; -end architecture; \ No newline at end of file +end architecture; -- cgit v1.2.3 From c3b877f0503ce995bd79ed3f4eb74d7370839582 Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Sun, 19 Feb 2023 16:30:24 +0100 Subject: small formatting fix --- basys3/basys3.srcs/apu_LUT_reader.vhd | 5 +++-- basys3/basys3.srcs/apu_tb_LUT_reader.vhd | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'basys3/basys3.srcs/apu_LUT_reader.vhd') diff --git a/basys3/basys3.srcs/apu_LUT_reader.vhd b/basys3/basys3.srcs/apu_LUT_reader.vhd index e56f855..6039798 100644 --- a/basys3/basys3.srcs/apu_LUT_reader.vhd +++ b/basys3/basys3.srcs/apu_LUT_reader.vhd @@ -4,7 +4,7 @@ use ieee.numeric_std.all; entity apu_LUT_reader is port ( - clk : in std_logic; + clk : in std_logic; rst : in std_logic; freq : in std_logic_vector(11 downto 0); wave : in std_logic_vector(1 downto 0); @@ -27,6 +27,7 @@ begin if rst = '1' then idx <= x"00"; buf <= x"00"; + value <= x"00"; elsif rising_edge(clk) then -- main code here @@ -34,7 +35,7 @@ begin value <= std_logic_vector( idx ); elsif wave = "01" then -- Square if idx < (SAMPLE_SIZE/2) then - value <= x"00"; + value <= x"00"; --std_logic_vector( SAMPLE_SIZE-AMPLITUDE ); -- TODO: make so that this work with a changable amplitude (for square wave) else value <= x"FF"; end if; diff --git a/basys3/basys3.srcs/apu_tb_LUT_reader.vhd b/basys3/basys3.srcs/apu_tb_LUT_reader.vhd index d4ed935..5a38d39 100644 --- a/basys3/basys3.srcs/apu_tb_LUT_reader.vhd +++ b/basys3/basys3.srcs/apu_tb_LUT_reader.vhd @@ -45,4 +45,4 @@ begin end loop; end process; -end architecture; \ No newline at end of file +end architecture; -- cgit v1.2.3