In lieu of an s-r debounce latch on your switch, you could try
something like this (not even syntax checked):
entity sevsegment is
port (
clk_i : in std_logic;
sevseg : out std_logic_vector(6 downto 0);
reset_n : in std_logic;--active low reset
switch : in std_logic
);
end sevsegment;
architecture rtl of sevsegment is
signal switch_filter : std_logic_vector(15 downto 0); -- actual
length depends on clk speed and bounce characteristics
signal switch_changed : std_logic;
signal bcd_counter : std_logic_vector(4 downto 0);
begin
process(reset_n,clk_i)
variable bcd_counter: integer range 0 to 9;
begin
if(reset_n ='0') then
bcd_counter <= X"0";-- enable 1993 syntax
switch_filter <= (others => '0');
switch_changed <= '0';
elsif clk_i'event and clk_i='1' then
if(switch_changed='1') then
if bcd_counter< X"9" then
bcd_counter <= bcd_counter + 1;
else
bcd_counter <= X"0";
end if;
end if;
switch_filter <= switch_filter(switch_filter'length - 2 downto 0)
& switch;--shift register
switch_changed <= (not switch_filter(switch_filter'length -1)) and
switch_filter(switch_filter'length -2) and
switch_filter(switch_filter'length -3) and
switch_filter(switch_filter'length -4);
end if;
end process;
decode_bcd_counter_combinatorial: process(bcd_counter)
begin
case bcd_counter is
when 0 =>
sevseg <= "1111110";
when 1 =>
sevseg <= "0110000";
when 2 =>
sevseg <= "1101101";
when 3 =>
sevseg <= "1111001";
when 4 =>
sevseg <= "0110011";
when 5 =>
sevseg<= "1011011";
when 6 =>
sevseg <= "1011111";
when 7 =>
sevseg <= "1110000";
when 8 =>
sevseg <= "1111111";
when 9 =>
sevseg <= "1111011";
when others =>
sevseg <= "1111110";
end case;
end process decode_bcd_counter_combinatorial;
end rtl;
"Simone Winkler" <> wrote in message news:<>...
> Hello!
>
> I'm trying to build the following thing: a 7-segment-led that increases its
> value every time a switch is pressed.
>
> library IEEE;
> use IEEE.STD_LOGIC_1164.ALL;
> use IEEE.STD_LOGIC_ARITH.ALL;
> use IEEE.STD_LOGIC_UNSIGNED.ALL;
>
> entity sevsegment is
> Port (
> clk_i: in std_logic;
> sevseg : out std_logic_vector(6 downto 0);
> reset : in std_logic;
> switch: in std_logic);
> end sevsegment;
>
> architecture Behavioral of sevsegment is
> signal sevseg_s: std_logic_vector(6 downto 0);
> begin
>
> process(reset,switch,clk_i)
> variable counter: integer range 0 to 9;
> begin
> if clk_i'event and clk_i='1' then
> if reset='0' then
> counter:=0;
> sevseg_s <= "1111110";
> elsif switch'event and switch='0' then
> if counter<9 then
> counter:=counter+1;
> else
> counter:=0;
> end if;
> case counter is
> when 0 => sevseg_s <= "1111110";
> when 1 => sevseg_s <= "0110000";
> when 2 => sevseg_s <= "1101101";
> when 3 => sevseg_s <= "1111001";
> when 4 => sevseg_s <= "0110011";
> when 5 => sevseg_s <= "1011011";
> when 6 => sevseg_s <= "1011111";
> when 7 => sevseg_s <= "1110000";
> when 8 => sevseg_s <= "1111111";
> when 9 => sevseg_s <= "1111011";
> end case;
> end if;
> end process;
>
> sevseg <= sevseg_s;
>
> end Behavioral;
>
>
> Why doesn't it work?
1. The switch is not debounced (possibly).
2. The synthesizer doesn't recognized one process with two clocks.
> I know that "multiple clocks" are not allowed, but i
> can't find any solution to solve my problem....
((((((((
There are many solutions. I think the one I gave above may work.
> In the end, everything should be implemented to a spartanII-FPGA...
>
> Thank you very much,
> Simone
Good luck.