Correction TP
Correction TP
END rtl;
Exercice 3 monte charge (programme Programme test
principale)
LIBRARY IEEE; Library ieee;
USE IEEE.STD_LOGIC_1164.ALL; Use ieee.std_logic_1164.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL; entity test_montecharge is
ENTITY montecharge IS End test_montecharge;
PORT ( Architecture test_Arc_montecharge OF
B, p0, p1 : IN STD_LOGIC; test_montecharge is
M, D : OUT STD_LOGIC component montecharge
); PORT (B, p0, p1 : IN STD_LOGIC;
END montecharge; M, D : OUT STD_LOGIC
);
ARCHITECTURE rtl_montecharge OF end component;
montecharge IS signal B, p0,p1, M, D: std_logic:='0';
TYPE etats IS (ar, mon, desc); begin
SIGNAL etat_present : etats; u1: montecharge port map (B, p0,p1, M, D);
B<='0', '1' after 10 ns, '0' after 20 ns, '1' after
BEGIN 30 ns, '0' after 40 ns ;
p0<= '0', '1' after 10 ns, '0' after 20 ns, '1'
PROCESS (etat_present, p0,p1, B) BEGIN after 40 ns ;
CASE etat_present IS p1<= '0' , '1' after 20 ns, '1' after 30 ns, '0'
WHEN ar => M<='0'; after 40 ns;
D<='0'; end test_Arc_montecharge;
if (B='1' and p1='1') then
etat_present<= desc;
elsif (B='1' and p0='1') then
etat_present<= mon;
else
etat_present<= ar;
end if;
WHEN desc => M<='0';
D<='1';
if (B='0' and p0='1') then
etat_present<= ar;
else
etat_present<= desc;
end if;
WHEN mon => M<='1';
D<='0';
if (B='0' and p0='0') then
etat_present<= ar;
else
etat_present<= mon;
end if;
END CASE;
END PROCESS;
end;
Exercice 4 compteur(programme principale) Programme test
LIBRARY IEEE; Library ieee;
USE IEEE.STD_LOGIC_1164.ALL; Use ieee.std_logic_1164.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL; entity test_compteur is
ENTITY compteur IS End test_compteur;
PORT ( Architecture test_Arc_compteur OF
clk : IN STD_LOGIC; test_compteur is
qrt : OUT STD_LOGIC component compteur
); PORT (
END compteur; clk : IN STD_LOGIC;
qrt : OUT STD_LOGIC
ARCHITECTURE rtl_compteur OF );
compteur IS end component;
TYPE etats IS (zero, un , deux, trois, quatre, signal clk,qrt: std_logic:='0';
cinq, six, sept, huit, neuf); begin
SIGNAL etat_present : etats; u1: compteur port map (clk,qrt);
process
BEGIN begin
clk<='0'; wait for 10 ns;
PROCESS (etat_present, clk) clk<='1'; wait for 10 ns;
BEGIN end process;
if clk'event and clk='1' then end test_Arc_compteur;
CASE etat_present IS
WHEN zero => etat_present<=un;
qrt<='0';
WHEN un => etat_present<=deux;
qrt<='0';
WHEN deux => etat_present<=trois;
qrt<='0';
WHEN trois => etat_present<=quatre;
qrt<='0';
WHEN quatre => etat_present<=cinq;
qrt<='0';
WHEN cinq => etat_present<=six;
qrt<='0';
WHEN six => etat_present<=sept;
qrt<='0';
WHEN sept => etat_present<=huit;
qrt<='0';
WHEN huit => etat_present<=neuf;
qrt<='1';
WHEN neuf=> etat_present<=zero;
qrt<='0';
END CASE;
end if;
END PROCESS;
end;