library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity sound is Port ( CLK : in std_logic; btn_2FT : in std_logic; sw : in std_logic_vector(1 downto 1); RS : out std_logic; MI : out std_logic ); end sound; architecture Behavioral of sound is -- benutzbare Noten und Pause (z) constant D: std_logic_vector(3 downto 0) := x"0"; constant E: std_logic_vector(3 downto 0) := x"1"; constant F: std_logic_vector(3 downto 0) := x"2"; constant Fis: std_logic_vector(3 downto 0) := x"3"; constant G: std_logic_vector(3 downto 0) := x"4"; constant A: std_logic_vector(3 downto 0) := x"5"; constant B: std_logic_vector(3 downto 0) := x"6"; constant H: std_logic_vector(3 downto 0) := x"7"; constant cc: std_logic_vector(3 downto 0) := x"8"; constant dd: std_logic_vector(3 downto 0) := x"9"; constant ee: std_logic_vector(3 downto 0) := x"A"; constant z: std_logic_vector(3 downto 0) := x"B"; -- Frequenzteiler type freq_type is array (0 to 11) of std_logic_vector (19 downto 0); constant freq: freq_type := ( x"0A738", -- x"29CE1", -- für 292 Hz -> D x"094DD", -- x"25377", -- für 328 Hz -> E x"08C4F", -- x"2313E", -- für 348 Hz -> F x"084AF", -- x"212BE", -- für 368 Hz -> Fis x"07C8f", -- x"1F23F", -- für 392 Hz -> G x"06EF9", -- x"1BBE4", -- für 440 Hz -> A (Kammerton :-) x"06855", -- x"1A156", -- für 468 Hz -> B x"0633E", -- x"18CFA", -- für 492 Hz -> H x"05DE6", -- x"1779A", -- für 520 Hz -> c x"0539C", -- x"14E70", -- für 584 Hz -> d x"04A6F", -- x"129BC", -- für 656 Hz -> e x"001F4"); -- für 0 Hz -> Pause -> keine Änderung -- Der Song type song_type is array (0 to 153) of std_logic_vector (6 downto 0); constant song: song_type := ( "010" & z, "011" & z, "011" & D, "010" & D, "111" & D, "011" & D, --------- "001" & G, "001" & G, "001" & A, "001" & A, --------- "001" & dd, "110" & dd, "110" & H, "010" & G, "011" & z, "011" & G, "010" & H, "111" & H, "011" & G, --------- "001" & E, "000" & cc, "010" & A, "111" & A, "011" & Fis, --------- "000" & G, "001" & z, "010" & G, "111" & G, "011" & A, --------- "001" & H, "001" & H, "001" & H, "010" & cc, "111" & cc, "011" & H, --------- "001" & H, "001" & A, "001" & z, "010" & A, "111" & A, "011" & H, -------- "001" & cc, "001" & cc, "001" & cc, "010" & dd, "111" & dd, "011" & cc, ---------- "000" & H, "001" & z, "010" & dd, "111" & dd, "011" & dd, ---------- "001" & dd, "110" & H, "111" & H, "011" & G, "001" & dd, "010" & H, "111" & H, "011" & G, --------- "000" & D, "010" & z, "011" & z, "011" & D, "010" & D, "111" & D, "011" & Fis, ----------- "000" & A, "001" & cc, "010" & A, "111" & A, "011" & Fis, ----------- "001" & A, "001" & G, "000" & F, --------- "001" & E, "010" & G, "111" & G, "011" & G, "001" & G, "010" & Fis, "111" & Fis, "011" & G, --------- "000" & A, "101" & A, "010" & z, "010" & A, --------- "001" & B, "110" & B, "010" & B, "010" & B, "010" & B, "010" & cc, "010" & dd, ---------- "000" & A, "101" & A, "010" & B, "010" & A, --------- "001" & G, "110" & G, "010" & G, "010" & G, "110" & B, "010" & A, "010" & G, --------- "001" & G, "010" & Fis, "000" & z, "011" & z, "011" & dd, ---------- "000" & dd, "110" & dd, "111" & dd, "011" & dd, "010" & H, "111" & H, "011" & G, --------- "000" & A, "101" & A, "010" & z, "011" & z, "011" & dd, ---------- "000" & dd, "110" & dd, "111" & dd, "011" & dd, "010" & H, "111" & H, "011" & G, --------- "000" & A, "110" & A, "010" & z, "001" & D, --------- "000" & G, "001" & z, "001" & A, --------- "000" & H, "000" & z, --------- "000" & cc, "001" & dd, "001" & ee, ---------- "000" & A, "110" & A, "010" & z, "001" & ee, ---------- "000" & dd, "110" & dd, "111" & dd, "011" & H, "010" & cc, "111" & cc, "011" & A, --------- "000" & G, --------- --------- "000" & z ); -- dummy-Pause für den Abschluß, sonst nicht so einfach zu proggen... begin --========================================================================== -- 50 MHz Takt ---------------------------------------------------------------------------- process(CLK) variable MI_buffer : std_logic; variable taste : std_logic_vector( 1 downto 0) := "00"; constant metrum : std_logic_vector(23 downto 0) := x"5F5E10"; -- => 1/4 Sek. für 1/16tel variable metrum_counter : std_logic_vector(23 downto 0) := CONV_STD_LOGIC_VECTOR(0,24); variable ton : std_logic_vector( 7 downto 0) := x"99"; -- 153 kein Ton variable helper : std_logic_vector( 6 downto 0); constant bogen_zahl : std_logic_vector( 3 downto 0) := x"A"; variable bogen_counter : std_logic_vector( 3 downto 0); variable dauer : std_logic_vector( 1 downto 0); variable f_wert : std_logic_vector(19 downto 0); variable f_counter : std_logic_vector(19 downto 0) := CONV_STD_LOGIC_VECTOR(0,20); begin if(CLK = '1' and CLK'EVENT) then -- Tastendruck löst Start aus taste := taste(0) & (btn_2FT OR sw(1)); if (taste = "11") AND (ton >= 153) then metrum_counter := CONV_STD_LOGIC_VECTOR(0,24); f_counter := CONV_STD_LOGIC_VECTOR(0,20); ton := x"00"; helper := song(CONV_INTEGER(ton)); if (helper(6) = '1') then bogen_counter := x"0"; else bogen_counter := bogen_zahl; end if; dauer := helper(5 downto 4); f_wert := freq(CONV_INTEGER(helper(3 downto 0))); end if; if (ton < 153) then -- sonst ist das Lied zu Ende -- Ton weiter halten oder neuen Ton laden if (metrum_counter >= metrum) then metrum_counter := CONV_STD_LOGIC_VECTOR(0,24); if (dauer = "11") then ton := ton + 1; helper := song(CONV_INTEGER(ton)); if (helper(6) = '1') then bogen_counter := x"0"; else bogen_counter := bogen_zahl; end if; dauer := helper(5 downto 4); f_wert := freq(CONV_INTEGER(helper(3 downto 0))); else dauer := dauer + 1; end if; else metrum_counter := metrum_counter + 1; end if; if (f_wert > 0) then -- sonst Pause => nix ändern if (f_counter >= f_wert) then f_counter := CONV_STD_LOGIC_VECTOR(0,20); if (bogen_counter = x"0") then MI_buffer := not MI_buffer; else bogen_counter := bogen_counter - 1; end if; else f_counter := f_counter + 1; end if; end if; MI <= MI_buffer; RS <= '1'; else RS <= '0'; end if; end if; end process; --------------------------------------------------------------- end Behavioral;