Cours:TP printempsM4209 TP 2 Corr : Différence entre versions
m |
m |
||
| Ligne 1 : | Ligne 1 : | ||
<accesscontrol>Acces:Prof</accesscontrol> | <accesscontrol>Acces:Prof</accesscontrol> | ||
| + | |||
| + | =Exercice 1= | ||
<source lang=VHDL> | <source lang=VHDL> | ||
-- description du composant compteur/decompteur cascadable | -- description du composant compteur/decompteur cascadable | ||
| Ligne 49 : | Ligne 51 : | ||
end behavior; | end behavior; | ||
</source> | </source> | ||
| + | =Exercice 2= | ||
Version du 9 février 2016 à 09:37
Il s’agit d’une page protégée.
Exercice 1
-- description du composant compteur/decompteur cascadable
library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity compteurbcd is port (
clk :in std_logic;
en : in std_logic;
init : in std_logic;
--ud=1 up, ud=0 down
ud : in std_logic;
enout : out std_logic;
s: out std_logic_vector(3 downto 0)
);
end entity;
architecture behavior of compteurbcd is
signal n : std_logic_vector(3 downto 0);
begin
increment : process(clk) begin
if clk'event and clk='1' then
if init ='1' then
n <= (others => '0');
elsif en='1' then
if ud = '1' then --up
if n<9 then
n <= n + 1 ;
else
n <= (others => '0');
end if;
else -- down
if n>0 then
n <= n - 1;
else
n <= "1001";
end if;
end if;
end if;
end if;
end process;
-- gestion enout
enout <= '1' when en='1' and ud='1' and n=9 else
'1' when en='1' and ud='0' and n=0 else
'0';
s <= n;
end behavior;