Altera_Forum
Honored Contributor
13 years agovriable length counter
hello,
im trying to do a simple morsecode : library ieee; use ieee.std_logic_1164.all; entity morse is port ( sw : in std_logic_vector(2 downto 0); e : in std_logic; clock : in std_logic; led : out std_logic_vector(6 downto 0)); end morse; architecture behavioral of morse is signal clk :std_logic:='0'; signal sr : std_logic_vector(15 downto 0):="0000000000000000"; signal n : integer:=0; begin halfsecclk : process(clock) variable count : integer :=0; begin if clock'event and clock='1' then count:=count + 1; if count = 2 then count :=0; clk <= not clk; end if; end if; end process; muxes : process(e) begin if e'event and e='0' then case sw is when "000" => sr <= "0000000000011101"; n <=6 ; when "001" => sr <= "0000000101010111"; n <=10 ; when "010" => sr <= "0000010111010111"; n <= 12; when "011" => sr <= "0000000001010111"; n <= 8; when "100" => sr <= "0000000000000001"; n <= 2; when "101" => sr <= "0000000101110101"; n <= 10; when "110" => sr <= "0000000101110111"; n <= 10; when "111" => sr <= "0000000001010101"; n <= 8; when others => null; end case; end if; end process; counter : process(clk) variable cnt : integer:=0; begin if rising_edge(clk) then if sr(0)='0' then led <= "1111111"; elsif sr(0)='1' then led <= "0111111"; end if; sr<="0" & sr(15 downto 1); end if; end process; end behavioral; what i faild to do is to make the counter process shift the (sr) shift register by (n) times then stop and waits for the next value of sw is entered, i have tried many ideas but it didnt worked as i want it to. any suggestions please ? thanks in advance