I am trying to make a four bit up/down modulo10 counter. Button1 - counts up, Button2 - counts down. I'm trying to do it using rising_edge command but for two signals I can’t define with button was pressed. So in next version of program I want detect button using if statement.
library IEEE;
use IEEE.std_logic_1164.all, IEEE.numeric_std.all;
ENTITY counter is
generic (n:natural :=4);
port(
button1: in std_logic;
button2: in std_logic;
clear: in std_logic;
C : out std_logic;
OUT1 : out std_logic_vector(n-1 downto 0)
);
END counter;
ARCHITECTURE beh of counter is
begin
p0:process (button1, clear) is
variable count: unsigned (n-1 downto 0);
begin
if clear = '1' then
count:= (others=>'0');
elsif button1='1' then
count:=count+1;
elsif count=10 then
count:=(others=>'0');
C<='1';
else C<='0';
end if;
if button2='1' then
count:=count-1;
if count=0 then
count:=(others=>'1');
C<='1';
else C<='0';
end if;
end if;
OUT1<=std_logic_vector(count);
end process p0;
end architecture beh;
In Quartus program is compiled without errors, but in simulation does not work. I would be very greatfull for help. :)