Comparateur 12 bits en VHDL
Répondre à la discussion
Affichage des résultats 1 à 15 sur 15

Comparateur 12 bits en VHDL



  1. #1
    ioro

    Comparateur 12 bits en VHDL


    ------

    Bonjour à tous,

    Nous avons pour projet de conception VHDL de réaliser un remix du mastermind.
    Je bloque sur le comparateur entre la combinaison saisie par le user et la combinaison à trouver.

    Pour chaque valeur de couleur, on l'exprime sur 3 bits.
    La combinaison à trouver est sur 12 bits.

    Pour comparer, je veux comparer la première couleur avec le reste de la combinaison, du style :

    if user_combi(2 downto 0) = combi_select(2 downto 0) then
    blablabla....

    Mais voilà, j'ai un problème, je pense "C" et pas "VHDL" donc si quelqu'un pouvait me donner 1 ou 2 conseils, ça serait le top!

    D'avance, merci.

    Ioro

    -----

  2. #2
    jiherve

    Re : Comparateur 12 bits en VHDL

    Bonjour,
    En l’occurrence le raisonnement est juste.
    JR
    l'électronique c'est pas du vaudou!

  3. #3
    ioro

    Re : Comparateur 12 bits en VHDL

    Ok mais mon prof m'a dit de revoir le code ^^

  4. #4
    jiherve

    Re : Comparateur 12 bits en VHDL

    Re
    il faudrait voir tout le code, utiliser la balise code accessible en mode avancé .
    JR
    l'électronique c'est pas du vaudou!

  5. A voir en vidéo sur Futura
  6. #5
    ioro

    Re : Comparateur 12 bits en VHDL

    Code:
    ----------------------------------------------------------------------------------
    -- Company: 
    -- Engineer: 
    -- 
    -- Create Date:    15:11:06 04/20/2015 
    -- Design Name: 
    -- Module Name:    comparaison - Behavioral 
    -- Project Name: 
    -- Target Devices: 
    -- Tool versions: 
    -- Description: 
    --
    -- Dependencies: 
    --
    -- Revision: 
    -- Revision 0.01 - File Created
    -- Additional Comments: 
    --
    ----------------------------------------------------------------------------------
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    
    -- Uncomment the following library declaration if using
    -- arithmetic functions with Signed or Unsigned values
    use IEEE.NUMERIC_STD.ALL;
    
    -- Uncomment the following library declaration if instantiating
    -- any Xilinx primitives in this code.
    --library UNISIM;
    --use UNISIM.VComponents.all;
    
    entity comparaison is
        Port ( 
    			  rst : in  STD_LOGIC;
               combi_select : in  STD_LOGIC_VECTOR (11 downto 0);
               cmp_en : in  STD_LOGIC;
               user_combi : in  STD_LOGIC_VECTOR (11 downto 0);
               result : out  STD_LOGIC;
               leds : out  STD_LOGIC_VECTOR (7 downto 0));
    end comparaison;
    
    architecture Behavioral of comparaison is
    signal cpt : unsigned (3 downto 0);
    signal cpt_color : unsigned (1 downto 0);		-- indique si bonne couleur
    signal cpt_place : unsigned (1 downto 0);		-- indique si bonne couleur et bien placé
    
    begin
    
    	comparaison : process(rst, cmp_en, user_combi, combi_select)
    	begin
    		if rst = '1' then
    			--leds <= "11111111";
    			result <= '0';
    			cpt_color <= "00";
    			cpt_place <= "00";
    			cpt <= "0000";
    		
    		elsif cmp_en='1' then
    		
    			if user_combi = combi_select then
    				--leds <= "11110000";
    				result <= '1';
    			
    			else
    			
    			cpt_color <= "00";
    			cpt_place <= "00";
    			
    			-- Pour les bonnes couleurs bien placées
    				if cpt = "0000" then
    					if user_combi(2 downto 0) = combi_select(2 downto 0) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0001";
    				end if;
    				
    				if cpt = "0001" then				
    					if user_combi(5 downto 3) = combi_select(5 downto 3) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0010";
    				end if;
    				
    				if cpt = "0010" then					
    					if user_combi(8 downto 6) = combi_select(8 downto 6) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0011";
    				end if;
    					
    				if cpt = "0011" then
    					if user_combi(11 downto 9) = combi_select(11 downto 9) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0100";
    				end if;
    					
    					-- Pour les bonnes couleurs mal placées
    				if cpt = "0100" then
    					if user_combi(2 downto 0) = combi_select(5 downto 3) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "0101";
    				end if;
    					
    				if cpt = "0101" then
    					if user_combi(2 downto 0) = combi_select(8 downto 6) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "0110";
    				end if;
    				
    				if cpt = "0110" then					
    					if user_combi(2 downto 0) = combi_select(11 downto 9) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "0111";
    				end if;
    					
    				if cpt = "0111" then
    					if user_combi(5 downto 3) = combi_select(2 downto 0) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1000";
    				end if;
    					
    				if cpt = "1000" then
    					if user_combi(5 downto 3) = combi_select(8 downto 6) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1001";
    				end if;
    					
    				if cpt = "1001" then	
    					if user_combi(5 downto 3) = combi_select(11 downto 9) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1010";
    				end if;
    				
    				if cpt <= "1010" then									
    					if user_combi(8 downto 6) = combi_select(2 downto 0) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1011";
    				end if;
    				
    				if cpt <= "1011" then					
    					if user_combi(8 downto 6) = combi_select(5 downto 3) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1100";
    				end if;
    				
    				if cpt <= "1100" then					
    					if user_combi(8 downto 6) = combi_select(11 downto 9) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1101";
    				end if;
    									
    				if cpt <= "1101" then
    					if user_combi(11 downto 9) = combi_select(2 downto 0) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1110";
    				end if;
    					
    				if cpt = "1110" then
    					if user_combi(11 downto 9) = combi_select(5 downto 3) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1111";
    				end if;
    					
    				if cpt = "1111" then
    					if user_combi(11 downto 9) = combi_select(8 downto 6) then
    						cpt_color <= cpt_color +1;
    					end if;
    				end if;
    				
    			end if;
    			
    		end if;	
    	end process;
    	
    	place_ok : process(cpt_place)
    	begin
    		case cpt_place is
    			when "00" =>
    				leds(3 downto 0) <= "1111";
    			when "01" =>
    				leds(3 downto 0) <= "1110";
    			when "10" =>
    				leds(3 downto 0) <= "1100";
    			when "11" =>
    				leds(3 downto 0) <= "1000";
    			when others =>
    				leds(3 downto 0) <= "1111";
    		end case;
    	end process;
    	
    	color_ok : process(cpt_color)
    	begin
    		case cpt_color is
    			when "00" =>
    				leds(7 downto 4) <= "1111";
    			when "01" =>
    				leds(7 downto 4) <= "1110";
    			when "10" =>
    				leds(7 downto 4) <= "1100";
    			when "11" =>
    				leds(7 downto 4) <= "1000";
    			when others =>
    				leds(7 downto 4) <= "1111";
    		end case;
    	end process;
    
    
    	
    end Behavioral;
    Voilà mais ça ne marche pas !

  7. #6
    jiherve

    Re : Comparateur 12 bits en VHDL

    Bonsoir,
    le problème est que tu utilises une structure qui s'apparente à un process synchrone mais qu'il n'y a pas d'horloge, donc ce qui sera instancié ce sont des latch, c'est un péché mortel.
    Ensuite comme ta liste de sensibilité ne comporte que des signaux non répétitif le process ne sera exécuté que de façon erratique et jamais pour une modification de cpt qui est ta machine à états car absent de la liste.
    Réécrit avec un process synchrone, bien sur il faudra plusieurs coups d'horloge pour obtenir le résultat et donc il faudra peut être un petit signal supplémentaire pour indiquer la fin de la réflexion.
    Autrement c'est possible aussi en combinatoire mais alors il faudrait passer par des variables.
    N'oublies jamais qu'un signal n'est affecté qu'une fois à la sortie du process par la dernière valeur "gagnante",alors que les variables peuvent évoluer durant le cours du process.
    Si à terme cela doit être synthétisable, ce qui est le but du VHDL alors la solution synchrone sera la meilleure.
    bien sur je pourrais te pondre un code fonctionnel mais tu n'apprendrais rien
    JR
    l'électronique c'est pas du vaudou!

  8. #7
    ioro

    Re : Comparateur 12 bits en VHDL

    Non non je ne veux pas le code ^^

    Je veux bien un coup de pouce cependant.
    Le comparateur ne fonctionnera pas avec une clk mais une machine à états qui autorisera ou non la comparaison.

    Sachant que je débute, quelles pistes dois-je emprunter?

    Merci

  9. #8
    jiherve

    Re : Comparateur 12 bits en VHDL

    Re
    il peut très bien y avoir un signal de validation mais une machine à états classique demande une horloge, c'est un processus séquentiel, et un processus séquentiel ne s’implémente de façon fiable qu'avec des bascules fonctionnant sur un front d'horloge et pas avec des latch dont le fonctionnement est aléatoire.
    Donc réécrire avec un process synchrone.
    JR
    l'électronique c'est pas du vaudou!

  10. #9
    jiherve

    Re : Comparateur 12 bits en VHDL

    Ajout,
    autrement on peut décrire un énorme truc combinatoire mais là pas besoin de machine à états.Il sera synthétisable mais cela sera une brouette.
    JR
    l'électronique c'est pas du vaudou!

  11. #10
    ioro

    Re : Comparateur 12 bits en VHDL

    Alors, j'ai mis une clk dans mon process mais lors de la simu, c'est du grand nawak!

    Code:
    ----------------------------------------------------------------------------------
    -- Company: 
    -- Engineer: 
    -- 
    -- Create Date:    15:11:06 04/20/2015 
    -- Design Name: 
    -- Module Name:    comparaison - Behavioral 
    -- Project Name: 
    -- Target Devices: 
    -- Tool versions: 
    -- Description: 
    --
    -- Dependencies: 
    --
    -- Revision: 
    -- Revision 0.01 - File Created
    -- Additional Comments: 
    --
    ----------------------------------------------------------------------------------
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    
    -- Uncomment the following library declaration if using
    -- arithmetic functions with Signed or Unsigned values
    use IEEE.NUMERIC_STD.ALL;
    
    -- Uncomment the following library declaration if instantiating
    -- any Xilinx primitives in this code.
    --library UNISIM;
    --use UNISIM.VComponents.all;
    
    entity comparaison is
        Port ( clk : in STD_LOGIC;
    			  rst : in  STD_LOGIC;
               combi_select : in  STD_LOGIC_VECTOR (11 downto 0);
               cmp_en : in  STD_LOGIC;
               user_combi : in  STD_LOGIC_VECTOR (11 downto 0);
               result : out  STD_LOGIC;
               leds : out  STD_LOGIC_VECTOR (7 downto 0));
    end comparaison;
    
    architecture Behavioral of comparaison is
    signal cpt : unsigned (3 downto 0) := "0000";
    signal cpt_color : unsigned (1 downto 0) := "00";		-- indique si bonne couleur
    signal cpt_place : unsigned (1 downto 0) := "00";		-- indique si bonne couleur et bien placé
    
    begin
    
    	comparaison : process(rst, clk, cmp_en)
    	begin
    		if rst = '1' then
    			--leds <= "11111111";
    			result <= '0';
    			cpt_color <= "00";
    			cpt_place <= "00";
    			cpt <= "0000";
    		
    		elsif(clk'event and clk = '1') then
    			if cmp_en = '1' then
    		
    				if user_combi = combi_select then
    					--leds <= "11110000";
    					result <= '1';
    			
    				else
    			
    				cpt_color <= "00";
    				cpt_place <= "00";
    				
    				end if;
    				
    			
    			-- Pour les bonnes couleurs bien placées
    				if cpt = "0000" then
    					if user_combi(2 downto 0) = combi_select(2 downto 0) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0001";
    				end if;
    				
    				if cpt = "0001" then				
    					if user_combi(5 downto 3) = combi_select(5 downto 3) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0010";
    				end if;
    				
    				if cpt = "0010" then					
    					if user_combi(8 downto 6) = combi_select(8 downto 6) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0011";
    				end if;
    					
    				if cpt = "0011" then
    					if user_combi(11 downto 9) = combi_select(11 downto 9) then
    						cpt_place <= cpt_place +1;
    					end if;
    					cpt <= "0100";
    				end if;
    					
    					-- Pour les bonnes couleurs mal placées
    				if cpt = "0100" then
    					if user_combi(2 downto 0) = combi_select(5 downto 3) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "0101";
    				end if;
    					
    				if cpt = "0101" then
    					if user_combi(2 downto 0) = combi_select(8 downto 6) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "0110";
    				end if;
    				
    				if cpt = "0110" then					
    					if user_combi(2 downto 0) = combi_select(11 downto 9) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "0111";
    				end if;
    					
    				if cpt = "0111" then
    					if user_combi(5 downto 3) = combi_select(2 downto 0) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1000";
    				end if;
    					
    				if cpt = "1000" then
    					if user_combi(5 downto 3) = combi_select(8 downto 6) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1001";
    				end if;
    					
    				if cpt = "1001" then	
    					if user_combi(5 downto 3) = combi_select(11 downto 9) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1010";
    				end if;
    				
    				if cpt <= "1010" then									
    					if user_combi(8 downto 6) = combi_select(2 downto 0) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1011";
    				end if;
    				
    				if cpt <= "1011" then					
    					if user_combi(8 downto 6) = combi_select(5 downto 3) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1100";
    				end if;
    				
    				if cpt <= "1100" then					
    					if user_combi(8 downto 6) = combi_select(11 downto 9) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1101";
    				end if;
    									
    				if cpt <= "1101" then
    					if user_combi(11 downto 9) = combi_select(2 downto 0) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1110";
    				end if;
    					
    				if cpt = "1110" then
    					if user_combi(11 downto 9) = combi_select(5 downto 3) then
    						cpt_color <= cpt_color +1;
    					end if;
    					cpt <= "1111";
    				end if;
    					
    				if cpt = "1111" then
    					if user_combi(11 downto 9) = combi_select(8 downto 6) then
    						cpt_color <= cpt_color +1;
    					end if;
    				end if;
    				
    			end if;
    			
    		end if;	
    	end process;
    	
    	place_ok : process(cpt_place)
    	begin
    		case cpt_place is
    			when "00" =>
    				leds(3 downto 0) <= "1111";
    			when "01" =>
    				leds(3 downto 0) <= "1110";
    			when "10" =>
    				leds(3 downto 0) <= "1100";
    			when "11" =>
    				leds(3 downto 0) <= "1000";
    			when others =>
    				leds(3 downto 0) <= "1111";
    		end case;
    	end process;
    	
    	color_ok : process(cpt_color)
    	begin
    		case cpt_color is
    			when "00" =>
    				leds(7 downto 4) <= "1111";
    			when "01" =>
    				leds(7 downto 4) <= "1110";
    			when "10" =>
    				leds(7 downto 4) <= "1100";
    			when "11" =>
    				leds(7 downto 4) <= "1000";
    			when others =>
    				leds(7 downto 4) <= "1111";
    		end case;
    	end process;
    end Behavioral;

  12. #11
    jiherve

    Re : Comparateur 12 bits en VHDL

    Re
    Ok,
    maintenant tu devrais pouvoir alléger l’écriture en introduisant un case sur cpt et en ne faisant qu'une incrementation.
    Il faudra aussi une validation pour l'affichage lorsque cpt atteint 0xF et aussi prévoir un truc pour remettre cpt à 0 lorsque la combinaison jouée change, mais c'est peut être déjà le rôle de ton signal cpt_en.
    En tous cas tu écris de façon propre, les indentations sont bien respectées bien qu'un peu grandes(2 espaces c'est suffisant), c'est important pour la lisibilité et donc la compréhension.
    JR
    l'électronique c'est pas du vaudou!

  13. #12
    ioro

    Re : Comparateur 12 bits en VHDL

    Le case sur cpt? J'ai pas tout suivi ^^
    Ok pour la remise à zéro,

  14. #13
    jiherve

    Re : Comparateur 12 bits en VHDL

    Re
    au lieu d'enchainer des if il serait plus simple d’écrire
    Code:
    CASE cpt is
      when "0000" =>
        if
         ....
        end if;
      when "0001" =>
       ....
    end case;
    cpt <= cpt+1;
    JR
    l'électronique c'est pas du vaudou!

  15. #14
    ioro

    Re : Comparateur 12 bits en VHDL

    Ok mais je ne vois pas comment incrémenter le cpt du coup...

  16. #15
    ioro

    Re : Comparateur 12 bits en VHDL

    Bon il doit y avoir une merde dans le code.
    Dans la simu, cpt passe de 0 à 14 à chaque fois... Je vois pas d'où vient le prob...

Discussions similaires

  1. [VHDL] - Compteur N bits et modulo - generic
    Par Baboush93 dans le forum Électronique
    Réponses: 1
    Dernier message: 24/11/2011, 22h40
  2. VHDL : Conversion 16 bits vers 32 bits
    Par gregdrck5 dans le forum Électronique
    Réponses: 1
    Dernier message: 09/10/2011, 21h34
  3. vhdl comparaison deux nombres de bits différents
    Par invite938b5933 dans le forum Électronique
    Réponses: 4
    Dernier message: 09/11/2010, 21h38
  4. tp additionneur 3 bits et comparateur 3 bits
    Par mountaineer dans le forum Électronique
    Réponses: 9
    Dernier message: 17/12/2008, 12h50
  5. comparateur a 4 bits
    Par invite4f1fdd24 dans le forum Électronique
    Réponses: 4
    Dernier message: 29/05/2007, 22h38
Découvrez nos comparatifs produits sur l'informatique et les technologies.