Académique Documents
Professionnel Documents
Culture Documents
entity alu is
Port ( a : in std_logic_vector(3 downto 0);
b : in std_logic_vector(3 downto 0);
s : in std_logic_vector(2 downto 0);
y : out std_logic_vector(7 downto 0));
end alu;
architecture Behavioral of alu is
signal s1,s2 : std_logic_vector(7 downto 0);
begin
s1<="0000"&a;
s2<="0000"&b;
process(a,b,s1,s2,s)
begin
case s is
when "000"=> y<=s1+s2;
when "001"=> y<=s1-s2;
when "010"=> y<=a*b;
when "011"=> y<=not s1;
when "100"=> y<=s1 and s2;
when "101"=> y<=s1 or s2;
when "110"=> y<=s1 xor s2;
when "111"=> y<=s1 nand s2;
when others => null;
end case ;
end process;
end Behavioral;
______________________________________________________________________
__
BCD up/down counter
entity bcd_counter is
Port ( dir : in std_logic;
res : in std_logic;
clk : in std_logic;
count : out std_logic_vector(3 downto 0));
end bcd_counter;
architecture Behavioral of bcd_counter is
signal sclk : std_logic;
signal clk1 : std_logic_vector(15 downto 0):= "0000000000000000";
begin
process (clk)
begin
if (rising_edge(clk)) then
clk1 <= clk1 + '1';
sclk <= clk1(15);
end if ;
end process;
process (sclk, dir,res)
variable t: std_logic_vector(3 downto 0):="0000";
begin
if (res='1')then t:="0000";
elsif (rising_edge(sclk) ) then
if (dir='1')then
t:=t+'1';
if (t>"1001")then t:="0000";
end if;
else t:=t-'1';
if (t>"1001")then t:="1001";
end if;
end if ;
end if ;
count <=t;
end process ;
end Behavioral;
____________________________________________________________________
4 bit counter with async reset
entity counterasync_reset is
Port ( clk : in std_logic;
rst : in std_logic;
dir : in std_logic;
count : out std_logic_vector(3 downto 0));
end counterasync_reset;
architecture Behavioral of counterasync_reset is
signal sclk : std_logic;
signal clk1 : std_logic_vector(15 downto 0):= "0000000000000000";
begin
process (clk)
begin
if (rising_edge(clk)) then
clk1 <= clk1 + '1';
sclk <= clk1(15);
end if ;
end process;
process (clk1, dir,rst)
variable t: std_logic_vector(3 downto 0):="0000";
begin
if (rst='1')then t:="0000";
entity dc_motor is
Port ( clkin,reset,dir : in std_logic;
SC : in std_logic_vector(1 downto 0);
IN1,IN2 : out std_logic);
end dc_motor;
architecture dc_motor of dc_motor is
signal sig1,sig2,sig_in:std_logic;
signal clk1,clk2,clk3,clk4:std_logic;
signal clk_div:std_logic_vector(15 downto 0);
begin
process(clkin,reset)
begin
if(reset='1')then
clk_div<=(others=>'0');
elsif(clkin'event and clkin='1')then
clk_div<=clk_div+1;
end if;
end process;
clk1<=clk_div(3);
clk2<=clk_div(4);
clk3<=clk_div(5);
clk4<=clk_div(6);
sig1<=clk3;
sig2<=clk4;
sig_in<='1' when SC="00" else
sig2 when SC="01" else
sig1 when SC="10" else
clk2 when SC="11";
IN1<=sig_in when dir='0' else
'0';
IN2<=sig_in when dir='1' else
'0';
end dc_motor;
______________________________________________________________________
_
1:8 DEMUX
entity demux1 is
Port ( a : in std_logic;
e : in std_logic;
s : in std_logic_vector(2 downto 0);
y : out std_logic_vector(7 downto 0));
end demux1;
architecture Behavioral of demux1 is
begin
process(a,s,e)
begin
y<="00000000";
if(e='0')then
if(s="000")then
y(0)<=a;
elsif(s="001")then
y(1)<=a;
elsif(s="010")then
y(2)<=a;
elsif(s="011")then
y(3)<=a;
elsif(s="100")then
y(4)<=a;
elsif(s="101")then
y(5)<=a;
elsif(s="110")then
y(6)<=a;
elsif(s="111")then y(7)<=a;
else y<="ZZZZZZZZ";
end if;
end if;
end process;
end Behavioral;
______________________________________________________________________
_
D F/F
entity dff is
Port ( d : in std_logic;
clk : in std_logic;
clr : in std_logic;
pr : in std_logic;
q : out std_logic;
qb : out std_logic);
end dff;
architecture Behavioral of dff is
begin
process (clk,clr,pr,d)
variable t : std_logic;
begin
then
then
then
then
then
then
then
then
end if ;
end process
end Behavioral;
______________________________________________________________________
__
FULLADDER _ STRUCTURAL
entity fa_st is
Port ( x : in std_logic;
y : in std_logic;
cin : in std_logic;
cout : out std_logic;
sum : out std_logic);
end f
a_st;
architecture Behavioral of fa_st is
component ha
port ( x,y :in std_logic ;
sum,carry : out std_logic);
end component ;
signal tmp1,tmp2,tmp3 : std_logic;
begin
L1: ha port map (x,y,tmp1,tmp2);
L2: ha port map (tmp1,cin,sum,tmp3);
cout <= tmp3 or tmp2;
end Behavioral;
//(in sub file)
entity ha is
Port ( x : in std_logic;
y : in std_logic;
sum : out std_logic;
carry : out std_logic);
end ha;
architecture Behavioral of ha is
begin
end process;
end Behavioral;
______________________________________________________________________
_
jk F/F
entity jkff is
Port ( pr : in std_logic;
clr : in std_logic;
clk : in std_logic;
jk : in std_logic_vector(1 downto 0);
q : out std_logic;
qb : out std_logic);
end jkff;
architecture Behavioral of jkff is
signal sclk : std_logic;
signal clk1 : std_logic_vector(15 downto 0):= "0000000000000000";
begin
process (clk)
begin
if (rising_edge(clk)) then
clk1 <= clk1 + '1';
sclk <= clk1(15);
end if ;
end process;
process (pr,clr,clk,jk)
variable t : std_logic;
begin
if (pr='1' and clr= '0')then t:='1';
elsif (pr='0' and clr= '1')then t:='0';
elsif (pr='0' and clr= '0')then t:='Z';
elsif (pr='1' and clr= '1')then
if rising_edge(clk) then
case jk is
when "00"=>t:=t;
when "01"=>t:='0';
when "10"=>t:='1';
when "11"=>t:=not t;
when others => null;
end case;
end if ;
q<=t;
qb<=not t;
end if;
end process;
end Behavioral;
______________________________________________________________________
__
1:8 MUX
entity mux8_1 is
Port ( d : in std_logic_vector(7 downto 0);
s : in std_logic_vector(2 downto 0);
e : in std_logic;
y : out std_logic);
end mux8_1;
architecture Behavioral of mux8_1 is
begin
process(d,e,s)
begin
if(e='0')then
if(s="000")then
y<=d(0);
elsif(s="001")then
y<=d(1);
elsif(s="001")then
y<=d(2);
elsif(s="011")then
y<=d(3);
elsif(s="100")then
y<=d(4);
elsif(s="101")then
y<=d(5);
elsif(s="110")then
y<=d(6);
elsif(s="111")then
y<=d(7);
end if;
else
y<='Z';
end if;
end process;
end Behavioral;
______________________________________________________________________
_
nbitcomparator
entity nbitcomp is
generic (N:integer := 1)
;
Port ( a : in std_logic_vector(N downto 0);
b : in std_logic_vector(N downto 0);
agrtb : out std_logic;
alessb : out std_logic;
aeqb : out std_logic);
end nbitcomp;
architecture Behavioral of nbitcomp is
begin
process(a,b)
variable g,l,e:std_logic;
begin
if (a<b)then
g:='0';
l:='1';
e:='0';
elsif (a>b)then
g:='1';
l:='0';
e:='0';
else
g:='0';
l:='0';
e:='1';
end if ;
agrtb <=g;
alessb <=l;
aeqb <=e;
end process ;
end Behavioral;
______________________________________________________________________
__
priority encoder
entity priority_enc is
Port ( d : in std_logic_vector(7 downto 0);
y : out std_logic_vector(2 downto 0));
end priority_enc;
architecture Behavioral of priority_enc is
begin
process (d)
begin
if (d(7)='1') then y<="111";
elsif(d(6)='1') then y<="110";
elsif(d(5)='1') then y<="101";
elsif(d(4)='1') then y<="100";
elsif(d(3)='1') then y<="011";
elsif(d(2)='1') then y<="010";
elsif(d(1)='1') then y<="001";
elsif(d(0)='1') then y<="000";
else y <= "ZZZ";
end if
end process;
end Behavioral;
______________________________________________________________________
__
SR F/F
entity srff is
Port ( sr : in std_logic_vector(1 downto 0);
clk : in std_logic;
clr : in std_logic;
pr : in std_logic;
q : out std_logic;
qb : out std_logic);
end srff;
architecture Behavioral of srff is
signal sclk : std_logic;
signal clk1 : std_logic_vector(15 downto 0):= "0000000000000000";
begin
process (clk)
begin
if (rising_edge(clk)) then
clk1 <= clk1 + '1';
sclk <= clk1(15);
end if ;
end process;
process (sclk,clr,pr,sr)
variable t : std_logic;
begin
if (pr='1' and clr= '0')then t:='0';
elsif (pr='0' and clr= '1')then t:='1';
elsif (pr='0' and clr= '0')then t:='Z';
process(count)
begin
if(count="00") then
sig<="0011";
elsif (count="01") then
sig<="0110";
elsif (count="10") then
sig<="1100";
elsif (count="11") then
sig<="1001";
end if;
end process;
a1<=sig;
end Behavioral;
______________________________________________________________________
_
T F/F
entity tff is
Port ( t : in std_logic;
clk : in std_logic;
clr : in std_logic;
pr : in std_logic;
q : out std_logic;
qb : out std_logic);
end tff;
architecture Behavioral of tff is
signal sclk : std_logic;
signal clk1 : std_logic_vector(15 downto 0):= "0000000000000000";
begin
process (clk)
begin
if (rising_edge(clk)) then
clk1 <= clk1 + '1';
sclk <= clk1(15);
end if ;
end process;
process (sclk)
variable t1: std_logic;
begin
if (pr='1' and clr= '0')then t1:='0';
elsif (pr='0' and clr= '1')then t1:='1';
elsif (pr='0' and clr= '0')then t1:='Z';
elsif (pr='1' and clr= '1')then
if (rising_edge (sclk)) then
case t is
when '0'=>t1:=t1;
when '1'=>t1:=not t1;
when others => null;
end case;
end if ;
q <= t1;
qb <= not t1;
end if;
end process;
end Behavioral;
______________________________________________________________________
_
Decoder 2:4
entity dec24 is
Port ( i : in std_logic_vector(1 downto 0);
y : out std_logic_vector(3 downto 0));
end dec24;
architecture dec24 of dec24 is
begin
process (i)
begin
case i is
when "00" =>y<= "0001";
when "01" =>y<= "0010";
when "10" =>y<= "0100";
when "11" =>y<= "1000";
when others => NULL;
end case;
end process;
end dec24;
______________________________________________________________________
_
elevator
entity elevator is
clk_div<=clk_div+1;
end if;
clkkey<=clk_div(6);
end process;
process(col)
begin
case col is
when "1110"=>keypress<='1';
when "1101"=>keypress<='1';
when "1011"=>keypress<='1';
when "0111"=>keypress<='1';
when others=>keypress<='0';
end case;
end process;
process(clkkey)
begin
if(rising_edge(clkkey)) then
if (skeyscn="1110") then skeyscn<="1101";
elsif(skeyscn="1101") then skeyscn<="1011";
elsif(skeyscn="1011") then skeyscn<="0111";
elsif(skeyscn="0111") then skeyscn<="1110";
else skeyscn<="1110";
end if;
end if;
row<=skeyscn;
end process;
process(keypress)
begin
if(rising_edge(keypress)) then lkeyscn<=skeyscn;
lkeyret<=col;
end if;
end process;
process(keypress)
begin
if(rising_edge(keypress)) then
if(lkeyscn="1110" and lkeyret="1110") then skeyval<=0;
elsif(lkeyscn="1110" and lkeyret="1110") then skeyval<=0;
elsif(lkeyscn="1110" and lkeyret="1101") then skeyval<=1;
elsif(lkeyscn="1110" and lkeyret="1011") then skeyval<=2;
elsif(lkeyscn="1110" and lkeyret="0111") then skeyval<=3;
elsif(lkeyscn="1101" and lkeyret="1110") then skeyval<=4;
elsif(lkeyscn="1101" and lkeyret="1101") then skeyval<=5;
elsif(lkeyscn="1101" and lkeyret="1011") then skeyval<=6;
elsif(lkeyscn="1101" and lkeyret="0111") then skeyval<=7;
elsif(lkeyscn="1011" and lkeyret="1110") then skeyval<=8;
elsif(lkeyscn="1011" and lkeyret="1101") then skeyval<=9;
elsif(lkeyscn="1011" and lkeyret="1011") then skeyval<=10;
elsif(lkeyscn="1011" and lkeyret="0111") then skeyval<=11;
elsif(lkeyscn="0111" and lkeyret="1110") then skeyval<=12;
elsif(lkeyscn="0111" and lkeyret="1101") then skeyval<=13;
elsif(lkeyscn="0111" and lkeyret="1011") then skeyval<=14;