Refactor volume_saturator VHDL code for improved readability and structure; update project files for consistent path references and disable unused components in lab3 design.

This commit is contained in:
2025-05-19 16:24:36 +02:00
parent 5f30651763
commit 1b6bae5183
16 changed files with 965 additions and 618 deletions

View File

@@ -1,36 +1,7 @@
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 22.05.2021 15:42:35
-- Design Name:
-- Module Name: led_level_controller - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity led_level_controller is
generic(
NUM_LEDS : positive := 16;
@@ -54,7 +25,83 @@ entity led_level_controller is
end led_level_controller;
architecture Behavioral of led_level_controller is
constant REFRESH_CYCLES : natural := (refresh_time_ms * 1_000_000) / clock_period_ns;
signal volume_value : signed(CHANNEL_LENGHT-1 downto 0) := (others => '0');
signal abs_audio : unsigned(CHANNEL_LENGHT-2 downto 0) := (others => '0');
signal leds_int : std_logic_vector(NUM_LEDS-1 downto 0) := (others => '0');
signal led_update : std_logic := '0';
signal refresh_counter : natural range 0 to REFRESH_CYCLES-1 := 0;
begin
led <= leds_int;
s_axis_tready <= '1';
-- Register the audio absolute value
process(aclk)
begin
if rising_edge(aclk) then
if aresetn = '0' then
volume_value <= (others => '0');
elsif s_axis_tvalid = '1' then
volume_value <= signed(s_axis_tdata);
if volume_value(volume_value'high) = '1' then
abs_audio <= unsigned(-volume_value(CHANNEL_LENGHT-2 downto 0));
else
abs_audio <= unsigned(volume_value(CHANNEL_LENGHT-2 downto 0));
end if;
end if;
end if;
end process;
-- Refresh counter
process(aclk)
begin
if rising_edge(aclk) then
if aresetn = '0' then
refresh_counter <= 0;
led_update <= '0';
else
if refresh_counter = REFRESH_CYCLES-1 then
refresh_counter <= 0;
led_update <= '1';
else
refresh_counter <= refresh_counter + 1;
led_update <= '0';
end if;
end if;
end if;
end process;
-- Linear scaling of the audio signal to LED levels
process(aclk)
variable leds_on : natural range 0 to NUM_LEDS;
variable temp_led_level : integer range 0 to NUM_LEDS;
begin
if rising_edge(aclk) then
if aresetn = '0' then
leds_int <= (others => '0');
elsif led_update = '1' then
-- Automatic linear scaling calculation:
if to_integer(abs_audio) = 0 then
temp_led_level := 0;
else -- -1 bit for sign, -4 to get 15+1 levels
temp_led_level := to_integer(shift_right(abs_audio,CHANNEL_LENGHT-4-1))+1;
end if;
-- Limit to maximum number of LEDs
if temp_led_level > NUM_LEDS then
leds_on := NUM_LEDS;
else
leds_on := temp_led_level;
end if;
leds_int <= (others => '0');
if leds_on > 0 then
leds_int(leds_on-1 downto 0) <= (others => '1');
end if;
end if;
end if;
end process;
end Behavioral;