Vous êtes sur la page 1sur 30

Le but de ce TP est dcrire la synthse des exemples classique en VHDL sous lenvironnement de modelSIM pour simul le comportement du

II.

Cration dun nouveau projet : File-New-Library

La bibliothque work est la bibliothque par dfaut pour regroupe les projets

Pour crs un nouveaux fichier source vhdl en cliquant sur Create New File

Et pour ajouter le code vhdl on clique sur right-click puis Edit

Linverseur est un port logique qui inverse logiquement le signal dentre

Entre(A) Sortie (out) 0 1 1 0

Library IEEE ; USE ieee.std_logic_1164.all ; entity inv is Port ( A : in std_logic ; S : out std_logic ) ; end inv;

architecture ARCH_inv of inv is begin S<= not A ; end ARCH_inv ;

# Compile of inverseur.vhd was successful. Pour simul le comportement du inverseur on clique sur start simulation puis on le slectionner dans la bibliothque work

Le layout des fentres change au mode de simulation

On fait ajouter les signaux a et s dans le wave et on attribut a a un signal clock de 100 et de cycle duty 50 (priodique)

Pour lancer la simulation on clique sur continue run puis Break

Simulation d inverseur :

Dabord pour travailler avec un autre exemple il fait retenir au mode de no design

Un multiplexeur (abrviation: MUX) est un circuit permettant de concentrer sur une mme voie de transmission diffrents types de liaisons (informatique, tlcopie, tlphonie, tltex) en slectionnant une entre parmi N. Il possdera donc N entres, une seconde entre de 2N bits permettant de choisir quelle entre sera slectionne, et une sortie.
S0 Z 0 A 1 B

La valeur d'une des deux entres E(i), sera propage sur la sortie S suivant la valeur de aut(appel autorisation) si aut=0 alors toutes les valeurs de la sortie valent 0 si aut=1 alors on voit l'adresse (A) S=E(a),exemple si k=2 on a 2 adresses tq A0=0 et A1=1 chaque E doit avoir 2 valeurs si aut=1 alors en dcimale A1A0=2 on prend E2. Un MUX simple ralise la fonction logique : S= aut.(A0'A1'E0+A0'A1E1+A0A1'E2+A0A1E3) On trouvera donc des multiplexeurs 2 vers 1 (1 bit de slection), 4 vers 1 (2 bits de slection), 8 vers 1 (3 bits de slection), etc. Certains multiplexeurs transmettent aussi bien les signaux numriques que les signaux analogiques.
S [0] S [1] 0 0 1 0 1 0 1 1 S A B C D

Donc on peut crire :

S= (d and s(0) and s(1)) o (c and not s(0) and s(1)) or (b and s(0) and not s(1)) or (a and not s(0) and not s(1));

Ou avec une process


mux_proc: process (s, a, b, c, d) begin x <= d; -- valeur par dfaut if s = "00" then x <= a; elsif s = "01" then x <= b; elsif s = "10" then x <= c; end if; end process;

Library IEEE ;
USE ieee.std_logic_1164.all ; entity mux is Port ( A : in std_logic_vector(3 downto 0) ; add : in std_logic_vector(1 downto 0); S : out std_logic ) ; end mux; architecture ARCH_mux of mux is begin S <= (A(3) and add(0) and add(1)) or (A(2) and not add(0) and add(1)) or (A(1) and add(0) and not add(1)) or (A(0) and not add(0) and not add(1)) ; end ARCH_mux ;

Pour simul le comportement de mux4 il faut au entres des bit forc

Par exemple : 0101 Et pour le signaux dadresses il faut passer par tous les cas add[0]=0101 et add[1]=0011 Alor on dfinit add[1] comme une clock de p= 100 et d=50 ;

Et add[0] comme une horloge de p=50 et d=25

Simulation de MUX 1 parmi 4

Le but de ce TP est dcrire la synthse des exemples classique en VHDL


Library ieee; Use ieee.std_logic_1164.all; Use ieee.numeric_std.all; Use ieee.std_logic_unsigned.all; entity BASCULEDSRS is port ( D,CLK,SET,RESET : in std_logic; S : out std_logic); end BASCULEDSRS; architecture DESCRIPTION of BASCULEDSRS is begin PRO_BASCULEDSRS : process (CLK) Begin if (CLK'event and CLK ='1') then if (RESET ='1') then S <= '0'; elsif (SET ='1')then S <= '1'; else S <= D; end if; end if; end process PRO_BASCULEDSRS; end DESCRIPTION;

Pour le signal clk on lui attribu un click de 100 comme periode et 50% de duty cycle

Pour le signal Don lui attribu un click de 200 comme priode et 50% de duty cycle pour mieux observer le fonctionnement du bascule D

Ils sont trs utiliss dans les descriptions VHDL. Lcriture dun compteur peut tre trs simple comme trs complique. Ils font appels aux process.
Library ieee; Use ieee.std_logic_1164.all; Use ieee.numeric_std.all; Use ieee.std_logic_unsigned.all; entity CMP4BITS is PORT ( CLOCK : in std_logic; Q : inout std_logic_vector(3 downto 0)); end CMP4BITS; architecture DESCRIPTION of CMP4BITS is begin process (CLOCK) begin if (CLOCK ='1' and CLOCK'event) then Q <= Q + 1; end if; end process; end DESCRIPTION;

La description ci-dessus est trs simple. Le dclenchement du process se fera sur un changement dtat du signal CLOCK, lincrmentation de la sortie Q se fera sur le front montant de lhorloge CLOCK. v. .
Library ieee; Use ieee.std_logic_1164.all; Use ieee.numeric_std.all; Use ieee.std_logic_unsigned.all; entity CMP3BITS is PORT ( CLOCK : in std_logic; RESET : in std_logic; Q : out std_logic_vector(2 downto 0)); end CMP3BITS; architecture DESCRIPTION of CMP3BITS is signal CMP: std_logic_vector (2 downto 0); begin

process (RESET,CLOCK) begin if RESET ='1' then CMP <= "000"; elsif (CLOCK ='1' and CLOCK'event) then CMP <= CMP + 1; end if; end process; Q <= CMP; end DESCRIPTION;

vi. Library ieee; Use ieee.std_logic_1164.all; Use ieee.numeric_std.all; Use ieee.std_logic_unsigned.all; entity CMP3BITS is PORT ( CLOCK : in std_logic; RESET : in std_logic; Q : out std_logic_vector (2 downto 0)); end CMP3BITS; architecture DESCRIPTION of CMP3BITS is signal CMP: std_logic_vector (2 downto 0); begin process (CLOCK) begin if (CLOCK ='1' and CLOCK'event) then if RESET ='1' then CMP <= "000"; else CMP <= CMP + 1; end if; end if;

end process; Q <= CMP; end DESCRIPTION;

Dans ce paragraphe, nous allons dtailler la description dune unit arithmtique et logique ainsi que les phases de compilation et de simulation. Le but de ce TP est dcrire la synthse des exemples classique en VHDL
Library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.STD_LOGIC_SIGNED.ALL; entity simple_alu is port( Clk : in std_logic; A,B : in signed(15 downto 0); Op : in unsigned(1 downto 0); R : out signed(15 downto 0) ); end simple_alu; architecture Behavioral of simple_alu is signal Reg1,Reg2,Reg3 : signed(15 downto 0) := (others => '0'); begin Reg1 <= A; Reg2 <= B; R <= Reg3; process(Clk) begin if(rising_edge(Clk)) then case Op is when "00" =>

Reg3 <= Reg1 + Reg2; when "01" => Reg3 <= Reg1 - Reg2; when "11" => Reg3 <= Reg1 and Reg2; when others => Reg3 <= Reg1 or Reg2; end case; end if; end process; end Behavioral;

ENTREES

SORTIES

library ieee; use ieee.std_logic_1164.all; entity parity is port ( A :in std_logic_vector (15 downto 0); p :out std_logic ); end entity; architecture description of parity is begin process (A) variable k :std_logic; begin k := '0'; for i in 0 to 15 loop k := k xor A(i); end loop; p <= k; end process ; end ;

library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use ieee.STD_LOGIC_ARITH.all; entity divnn is port (hor, en : in bit;

div1, div2 : out bit); end divnn; architecture combien of divnn is signal sig1 : integer range 0 to 3; signal sig2 : bit; begin div1 <= '1' when sig1 = 2 else '0'; div2 <= sig2; d1 : process begin wait until hor = '1'; if en = '0' then sig1 <= 0; else case sig1 is when 0 => if sig2 = '1' then sig1 <= 1; end if; when 1 => sig1 <= 2 ; when 2 => sig1 <= 0 ; when others => sig1 <= 0 ; end case; end if; end process; d2 : process begin wait until hor = '1'; if en = '0' then sig2 <= '0'; else case sig2 is when '0' => if sig1= 0 then sig2 <= '1'; end if; when others => sig2 <= '0'; end case; end if; end process; end combien;

On dsire afficher, sur un afficheur 7 segments, les chiffres de 0 9 ainsi que les lettres de A F. Nous allons donc raliser pour cela un dcodeur recevant en entre un code binaire sur 4 bits (compris entre 0000(2) et 1111(2)), et fournissant en sortie 7 signaux qui permettrons dalimenter les segments de lafficheur. Les entres sappellent E1 E4, E1 tant le bit de poids faible. Les sorties sappelle Sa, Sb, Sc, Sd, Se, Sf, et Sg, et alimentent respectivement les segments a g de lafficheur.

Rappel du reprage des segments dun afficheur 7 segments :

Affichage des symboles sur lafficheur 7 segments :

E3 0 0 0 0 0 0 0 0 1

E2 0 0 0 0 1 1 1 1 0

E1 0 0 1 1 0 0 1 1 0

E0 0 1 0 1 0 1 0 1 0

a 0 1 0 0 1 0 0 0 0

b 0 0 0 0 0 1 1 0 0

c 0 0 1 0 0 0 0 0 0

d 0 1 0 0 1 0 0 1 0

e 0 1 0 1 1 1 0 1 0

f 0 1 1 1 0 0 0 1 0

g 1 1 0 0 0 0 0 1 0

nombre 0 1 2 3 4 5 6 7 8

1 1 1 1 1 1 1

0 0 0 1 1 1 1

0 1 1 0 0 1 1

1 0 1 0 1 0 1

0 0 1 0 1 0 0

0 0 1 1 0 1 1

0 0 0 1 0 1 1

0 1 0 0 0 0 1

1 0 0 0 0 0 0

0 0 0 0 1 0 0

0 0 0 1 0 0 0

9 A B C D E F

library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity seg7 is port ( clk : in std_logic; bcd : in std_logic_vector(3 downto 0); --BCD segment7 : out std_logic_vector(6 downto 0) end seg7; architecture arch_seg7 of seg7 is begin process (clk,bcd) BEGIN if (clk'event and clk='1') then case bcd is when "0000"=> segment7 <="0000001"; when "0001"=> segment7 <="1001111"; when "0010"=> segment7 <="0010010"; when "0011"=> segment7 <="0000110"; when "0100"=> segment7 <="1001100"; when "0101"=> segment7 <="0100100"; when "0110"=> segment7 <="0100000"; when "0111"=> segment7 <="0001111"; when "1000"=> segment7 <="0000000"; when "1001"=> segment7 <="0000100"; when "1010"=> segment7 <="0001000"; when "1011"=> segment7 <="1100000"; when "1100"=> segment7 <="0110001"; when "1101"=> segment7 <="1000010"; when "1110"=> segment7 <="0110000"; when "1111"=> segment7 <="0111000"; when others=> segment7 <="1111111"; end case; end if;

);

-----------------

'0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'A' 'B' 'C' 'D' 'E' 'F'

end process; end arch_seg7;

0 4 2

Dans un premier temps, pour illustrer la mthode, on simplifie le problme lextrme : Au croisement de 2 routes, on place des feux tricolores :

F2

F1

R1 feu rouge de laxe 1 O1 feu orange ----------

F1

F2

V1 feu vert

-----------

R2 , O2, V2 idem pou laxe 2

Le diagramme (machines tats) de ce carrefour est prsent sous la forme suivante :

-- FEUX_1.vhd------------

-- Pillet jl 25/8/97

B. de C.-------------

-- Essai gestion carrefour simplifie -------------------------------------------------library ieee; use IEEE.std_logic_1164.all; library synth ; use synth.VHDLSYNTH.all ;

----- Dfinition de l'entit----------------ENTITY feux_1 IS PORT (RAZ, horl :in std_logic; -- Ne pas oublier remise 0 et horloge !

V1, V2, R1, R2, O1, O2 :out std_logic); END feux_1;

------ Dfinir L'architecture de description d'tat ----------------ARCHITECTURE diagramme OF feux_1 IS TYPE etat_17 IS (INIT, V11, V12, V13, V14, V15, V16, V17, V18, OR1, SEC, V21, V22, V23, V24, V25, OR2); SIGNAL etat, nextetat :etat_17 ; --2 signaux :etats courant et suivant

Attribute ENCODING_STYLE of sorties: label is ONE_HOT;

BEGIN definir_etat: PROCESS( raz, horl) -- "definir_etat" :label optionnel BEGIN If raz = '1' THEN etat <= INIT; ELSIF rising_edge(horl) THEN etat <= nextetat; END IF; END PROCESS definir_etat;

------------ Dfinir les tats des sorties------------------sorties : process (etat) BEGIN CASE etat IS WHEN INIT => R1<='1';R2<='1';V1 <='0';V2<='0';O1<='0'; O2<='0'; nextetat <= V11; WHEN V11 => R1<='0';V1<='1'; nextetat <= V12; nextetat <= V13; nextetat <= V14; nextetat <= V15; nextetat <= V16; nextetat <= V17; nextetat <= V18; nextetat <= OR1; nextetat <= SEC;

WHEN V12 =>R1<='0';V1<='1'; WHEN V13 => R1<='0';V1<='1'; WHEN V14 => R1<='0';V1<='1'; WHEN V15 =>R1<='0';V1<='1'; WHEN V16 => R1<='0';V1<='1'; WHEN V17 => R1<='0';V1<='1'; WHEN V18 => R1<='0';V1<='1'; WHEN OR1 => V1<='0';O1<= '1';

WHEN SEC => R1<='1'; O1 <='0';nextetat <= V21; WHEN V21 => R2<='0'; V2<='1';nextetat <= V22 WHEN V22 => R2<='0'; V2<='1'; WHEN V23 => R2<='0'; V2<='1'; WHEN V24 => R2<='0'; V2<='1'; WHEN V25 => R2<='0'; V2<='1'; WHEN OR2 => V2<='0' ;O2<='1'; END CASE; END process sorties ; END diagramme; nextetat <= V23; nextetat <= V24; nextetat <= V25; nextetat <= OR2; nextetat <= INIT;

LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.std_logic_unsigned.all; USE ieee.numeric_std.ALL; ENTITY h IS END h; ARCHITECTURE behavior OF h IS COMPONENT carrefour PORT( CLK_SYS : IN std_logic; RST : IN std_logic; R1 : OUT std_logic; R2 : OUT std_logic; O1 : OUT std_logic; O2 : OUT std_logic; V1 : OUT std_logic; V2 : OUT std_logic ); END COMPONENT;

-- les entres signal CLK_SYS : std_logic := '0'; signal RST : std_logic := '0'; --les sorties signal R1 : std_logic; signal R2 : std_logic; signal O1 : std_logic; signal O2 : std_logic; signal V1 : std_logic; signal V2 : std_logic; BEGIN -- initializer des vectors uut: carrefour PORT MAP ( CLK_SYS => CLK_SYS, RST => RST, R1 => R1, R2 => R2, O1 => O1,

O2 => O2, V1 => V1, V2 => V2 );

clock:process begin CLK_SYS <= '0'; wait for 1000ms; CLK_SYS <= '1'; wait for 1000ms; end process;

-- process de test reset: process begin -- rest ON dans 100ms. RST <= '1'; wait for 1000ms; RST <= '0'; wait; end process; END;

Vous aimerez peut-être aussi