Hi,
try this :
--------------
library IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
Entity gray_cnt is
generic (
cnt_size : integer range 0 to 15 := 8
);
port(
rst : in std_logic ;
clk : in std_logic ;
cnt : out std_logic_vector (7 downto 0)
);
end gray_cnt;
architecture rtl of gray_cnt is
signal counter : std_logic_vector (cnt_size-1 downto 0);
signal tog : std_logic;
constant zero : std_logic_vector (cnt_size-1 downto 0) := (others => '0');
begin
gray
rocess(clk,rst)
variable i : integer ;
begin
if (rst = '0') then
counter <= (others => '0');
tog <= '1';
elsif clk='1' and clk'event then
tog <= not tog;
if tog = '1' then
counter(0) <= not counter(0);
else
if counter(0) = '1' then
counter(1) <= not counter(1);
end if;
for i in 2 to (cnt_size-1) loop
if counter(i-1) = '1' and counter(i-2 downto 0) = zero(i-2 downto 0) then
counter(i) <= not counter(i);
end if;
end loop;
end if;
end if;
end process gray;
cnt <= counter;
end;
sucesfully synthesized with ise
:wink: