------------------------------------------------------------------------------- -- Title : palet -- Project : ------------------------------------------------------------------------------- -- File : palet.vhd -- Author : Frederic Lochon -- Company : -- Last update : 2002/12/10 -- Platform : ------------------------------------------------------------------------------- -- Description : -- detection approximative de zones de couleur (a choisir au moment de la -- synthese) ------------------------------------------------------------------------------- -- Modification history : -- 2002/11/28 : created ------------------------------------------------------------------------------- LIBRARY ieee, work; USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; USE ieee.std_logic_unsigned.all; ENTITY palet IS GENERIC ( code_red : integer range 0 to 1 := 1; code_gre : integer range 0 to 1 := 0; code_blu : integer range 0 to 1 := 0; seuilpixel : integer := 10; seuilligne : integer := 3; hauteur_min : integer := 2; largeur_min : integer := 7 ); PORT ( cpt_line : IN integer range 0 to 511; cpt_row : IN integer range 0 to 1023; cpt_row_out : OUT integer range 0 to 1023; cpt_line_out: OUT integer range 0 to 511; red_out : OUT std_logic; gre_out : OUT std_logic; blu_out : OUT std_logic; red_in : IN std_logic; gre_in : IN std_logic; blu_in : IN std_logic; -- droite : OUT integer range 0 to 1023; -- gauche : OUT integer range 0 to 1023; -- haut : OUT integer range 0 to 511; -- bas : OUT integer range 0 to 511; choix : IN std_logic_vector(1 downto 0); donnee : OUT std_logic_vector(11 downto 0); en_win : IN std_logic; so_win : OUT std_logic; reset_n : IN std_logic; clock : IN std_logic ); END palet ; ARCHITECTURE deux_d OF palet IS signal s_droite, s_gauche: integer range 0 to 1023; signal s_haut, s_bas : integer range 0 to 511; signal row_start : integer range 0 to 1023; -- pixel signal line_start : integer range 0 to 511; -- hs signal last1 : std_logic; signal match : std_logic; function itol(i: integer range 0 to 1) return std_logic is variable l: std_logic := '0'; begin if i=1 then l:='1'; end if; return l; end; BEGIN colormatch : process (red_in, gre_in, blu_in) begin if red_in=itol(code_red) and gre_in=itol(code_gre) and blu_in=itol(code_blu) then match <= '1'; else match <= '0'; end if; end process; ------------------------------------------------------------------------------- choix_donnee : process (choix, s_gauche, s_droite, s_haut, s_bas) begin case choix is when "00" => donnee <= std_logic_vector(to_unsigned(s_gauche,12)); when "01" => donnee <= std_logic_vector(to_unsigned(s_droite,12)); when "10" => donnee <= std_logic_vector(to_unsigned(s_haut,12)); when others => donnee <= std_logic_vector(to_unsigned(s_bas,12)); -- when others => NULL; end case; end process; ------------------------------------------------------------------------------- findball : process (clock, reset_n) begin if (reset_n='0') then s_droite <= 0; s_gauche <= 0; red_out <= '0'; blu_out <= '0'; gre_out <= '0'; last1 <= '0'; s_bas <= 0; s_haut <= 0; line_start <= 0; row_start <= 0; so_win <= '0'; cpt_row_out <= 0; cpt_line_out <= 0; elsif (rising_edge(clock)) then -- fenetrage if en_win = '1' and row_start=0 and match = '1' then s_gauche <= cpt_row; s_droite <= cpt_row; red_out <= '0'; -- pixel bleu: demarrage du palet gre_out <= '0'; blu_out <= '1'; last1 <= '1'; s_bas <= cpt_line; s_haut <= cpt_line; line_start <= cpt_line; row_start <= cpt_row; elsif en_win = '1' and row_start=0 then s_gauche <= s_gauche; s_droite <= s_droite; red_out <= red_in; -- rien de special gre_out <= gre_in; blu_out <= blu_in; last1 <= last1; s_bas <= s_bas; s_haut <= s_haut; line_start <= line_start; row_start <= row_start; elsif en_win = '1' and match = '1' and last1 = '1' and line_start = cpt_line then if cpt_row > s_droite then s_droite <= cpt_row; else s_droite <= s_droite; end if; s_gauche <= s_gauche; red_out <= itol(code_red); -- pixel bleu-ciel / violet : suite de pixel dans gre_out <= itol(code_gre); -- une meme ligne blu_out <= '1'; last1 <= last1; s_bas <= s_bas; s_haut <= s_haut; line_start <= line_start; row_start <= row_start; elsif en_win = '1' and match = '1' and abs(cpt_row-row_start) s_droite then s_droite <= cpt_row; else s_droite <= s_droite; end if; red_out <= '1'; -- pixel jaune: nouvelle ligne pas gre_out <= '1'; -- loin (meme palet) blu_out <= '0'; last1 <= '1'; s_haut <= s_haut; s_bas <= cpt_line; line_start <= cpt_line; row_start <= cpt_row; elsif en_win = '1' then s_gauche <= s_gauche; s_droite <= s_droite; red_out <= red_in; -- c'est meme pas la bonne couleur gre_out <= gre_in; blu_out <= blu_in; last1 <= '0'; s_bas <= s_bas; s_haut <= s_haut; line_start <= line_start; row_start <= row_start; elsif en_win = '1' and ( cpt_line - line_start > seuilligne) and ( ((s_bas-s_haut) < hauteur_min) ) then s_gauche <= 0; s_droite <= 0; s_haut <= 0; s_bas <= 0; line_start <= 0; row_start <= 0; last1 <= '0'; red_out <= red_in; gre_out <= gre_in; blu_out <= blu_in; -- hors fenetrage else s_gauche <= s_gauche; s_droite <= s_droite; red_out <= '0'; -- hors fenetre, on fait du noir gre_out <= '0'; blu_out <= '0'; last1 <= '0'; -- hum... faudra verifier ca... s_bas <= s_bas; s_haut <= s_haut; line_start <= line_start; row_start <= row_start; end if; cpt_row_out <= cpt_row; -- on fait suivre les valeurs au palet cpt_line_out <= cpt_line; -- suivant so_win <= en_win; end if; end process; end deux_d;