Altera_Forum
Honored Contributor
13 years agosimple VHDL program --> need help please
i have an external asynchronious signal (called "sig") which i have to count its rising or falling edges. i wrote a program which somehow ends very quickly --> after 2 rising edges, req_dist = 32 --> req_dist(8 downto 1)=16 .
is someone can see what is my problem ? thank you very much for help... library IEEE; use IEEE.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity encoder is port( CLK : in std_logic; sig : in std_logic ; reset : in std_logic; req_dist: in std_logic_vector(8 downto 0); --required distance arrived : out std_logic ); end entity encoder; architecture arc_encoder of encoder is signal counter : std_logic_vector(8 downto 0) := "000000000"; signal distance : std_logic_vector(8 downto 0); signal flag : bit := '1' ; begin process(CLK,reset) begin if (reset = '1') then counter <= (others => '0'); arrived <= '0'; flag <='1'; elsif(rising_edge(CLK)) then if(req_dist /= "0") then if (sig = '0' or flag = '0') then flag <='0'; if (sig ='1') then if (counter < req_dist(8 downto 1)) then counter <= counter + '1'; flag <='1'; else arrived <= '1'; counter <= (others => '0'); flag <='1'; end if; end if; end if; end if; end if; end process; end architecture;