library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use ieee.numeric_std.all; use ieee.numeric_bit.all; entity generator is port( clk10: in std_logic; --12MHZ-clock da: inout std_logic_vector(5 downto 0); --D/A-pins for D/A-converter dip_prescaler: in std_logic_vector(7 downto 0); --prescaler for setting signal-frequency button_value: in std_logic_vector(3 downto 0); --value of button-decoder strobe: in std_logic; --button-decoder(button was pressed) segment_display: out std_logic_vector(6 downto 0)); end generator; architecture Behavioral of generator is shared variable choose_function: std_logic_vector(1 downto 0); function sinus(counter: integer) return integer is --sinus-function for signal begin case counter is when 0 => return 63; when 1 => return 63; when 2 => return 63; when 3 => return 63; when 4 => return 62; when 5 => return 62; when 6 => return 62; when 7 => return 61; when 8 => return 61; when 9 => return 60; when 10 => return 59; when 11 => return 58; when 12 => return 58; when 13 => return 57; when 14 => return 56; when 15 => return 55; when 16 => return 53; when 17 => return 52; when 18 => return 51; when 19 => return 50; when 20 => return 49; when 21 => return 47; when 23 => return 44; when 24 => return 43; when 25 => return 42; when 26 => return 40; when 27 => return 39; when 28 => return 37; when 29 => return 35; when 30 => return 34; when 31 => return 32; when 32 => return 31; when 33 => return 29; when 34 => return 28; when 35 => return 26; when 36 => return 24; when 37 => return 23; when 38 => return 21; when 39 => return 20; when 40 => return 19; when 41 => return 17; when 42 => return 16; when 43 => return 14; when 44 => return 13; when 45 => return 12; when 46 => return 11; when 47 => return 10; when 48 => return 8; when 49 => return 7; when 50 => return 6; when 51 => return 5; when 52 => return 5; when 53 => return 4; when 54 => return 3; when 55 => return 2; when 56 => return 2; when 57 => return 1; when 58 => return 1; when 59 => return 1; when 60 => return 0; when 61 => return 0; when 62 => return 0; when 63 => return 0; when others => return 0; end case; end function sinus; begin function_generator: process(clk10) variable prescaler: std_logic_vector(7 downto 0); variable counter: integer range 0 to 63:=0; variable switch_triangle, switch_sinus: std_logic; --setting the ascent of the signal begin if(clk10'event and clk10='1') then prescaler:=prescaler+1; end if; if(prescaler>=dip_prescaler) then prescaler:="00000000"; case choose_function is when "01" => da <= da+1; --sawtooth when "10" => --triangle if(switch_triangle='0') then da <= da+1; --set into the if-else-junction if(da=63) then switch_triangle:='1'; end if; else da <= da-1; --set into the if-else-junction if(da=0) then switch_triangle:='0'; end if; end if; when "11" => da <= conv_std_logic_vector(unsigned(sinus(counter)),da'LENGTH); --sinus if(switch_sinus='0') then counter:=counter+1; if(counter=63) then switch_sinus:='1'; end if; else counter:=counter-1; if(counter=0) then switch_sinus:='0'; end if; end if; when others => da <= "------"; --no signal end case; end if; end process function_generator; display_function: process(strobe) begin if(strobe'event and strobe='1') then case button_value is when "0000" => choose_function:="01"; --sawtooth when "0001" => choose_function:="10"; --triangle when "0010" => choose_function:="11"; --sinus when others => choose_function:="00"; --empty end case; end if; end process display_function; end Behavioral;