-1
\$\begingroup\$

I have this simple code which doesn't behave as it should and can't figure out why.

entity test is
port (D0        : in  std_logic;
        output      : out unsigned(6 downto 0));
end test;

architecture Behavioral of test is
    signal clk_Cent_i : unsigned(6 downto 0);
begin

    gen_clk : process (D0)
    begin
    if  D0 = '1' then
    clk_Cent_i<=clk_Cent_i + "1";
    end if;
    end process gen_clk;
output<= clk_Cent_i; 
end Behavioral;

I want by pressing a button to increment a counter and show the counters' number to 7 leds.

\$\endgroup\$
3
\$\begingroup\$

If you want to count individual presses, you need to react on signal edges. So, instead of

if  D0 = '1' then

you need to write

if(rising_edge(D0)) then

Warning: this will only work if D0 is correctly debounced, i.e. a single rising edge is produced on each press.

\$\endgroup\$
  • 2
    \$\begingroup\$ This will make D0 a clock signal. The switch will likely fail the timings. Better to set up an FSM to monitor the state of the switch on each clock edge. \$\endgroup\$ – user110971 May 30 '16 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.