Beruflich Dokumente
Kultur Dokumente
Name: Prabhjot kaur Subject : Digital System Design(EE-310-E) Sem: 6th (ECE/CSE)
Unit: 4
t : in STD_LOGIC; pr : in STD_LOGIC; cr : in STD_LOGIC; clk : in STD_LOGIC; q : inout STD_LOGIC; qbar : out STD_LOGIC ); end tff; --}} End of automatically maintained section architecture tff of tff is begin process(clk,pr,cr) begin if (pr='0' and cr='1')then q <='1'; elsif(pr='1'and cr='0')then q<='0'; elsif(pr='1' and cr='1' and clk='0' and clk'event)then q<=(not t and q) or (not q and t); end if; qbar<= not q; end process;
end tff;
architecture srff of srff is begin process(clk,s,r) begin if (clk='0' and clk'event)then if (s='0' and r ='0' ) then q<= 'X'; elsif(s='1' and r ='0' ) then q<= '1'; elsif(s='0' and r ='1' ) then q<= '0'; elsif(s='1' and r ='1' ) then q<= 'X'; end if; else q<= 'X'; end if; end process; end srff;
entity jkff is port( j : in STD_LOGIC; k : in STD_LOGIC; clk : in STD_LOGIC; q : out STD_LOGIC ; qbar: out std_logic ); end jkff; --}} End of automatically maintained section architecture jkff of jkff is begin process(clk,j,k) begin if (clk='0' and clk'event)then if(j='1' and k ='0' ) then q<= '1'; qbar<= '0'; elsif(j='0' and k
='1' ) then 4
q<= '0'; qbar<= '1'; elsif(j='1' and k q <= 'X'; end if; else q <= 'X'; qbar<='X'; end if; end process; end jkff;
='1' ) then
z<= '1'; elsif (pr='1' and cr='0'and clk='0' and clk'event ) then q0<= '0'; q1<= '0'; q2<= '0'; z<= '0'; elsif (pr='0' and cr='0' and clk='0' and clk'event) then q0<= 'X'; q1<= 'X'; q2<= 'X'; z<= 'X'; end if; end process ; end \siso(dff)\;
q(0)<='1'; q(1)<='1'; q(2)<='1'; q(3)<= '1'; elsif(pr='0' and cr='0')then q(0)<='0'; q(1)<='0'; q(2)<='0'; q(3)<= '0'; end if; end process; end sipo;
library IEEE; use IEEE.STD_LOGIC_1164.all; entity pipo is port( clk : in STD_LOGIC; pr,cr: in std_logic; d : in STD_LOGIC_VECTOR(3 downto 0); q : out STD_LOGIC_VECTOR(3 downto 0) ); end pipo; architecture pipo of pipo is begin process( d,clk) BEGIN if(pr='1' and cr='1' and clk='0' and clk'event)then q(0)<=d(0); q(1)<=d(1); q(2)<=d(2); q(3)<= d(3); elsif(pr='1' and cr='0')then q(0)<='0'; q(1)<='0'; q(2)<='0'; q(3)<= '0'; elsif(pr='0' and cr='1')then q(0)<='1'; q(1)<='1'; q(2)<='1'; 7
q(3)<= '1'; elsif(pr='0' and cr='0')then q(0)<='X'; q(1)<='X'; q(2)<='X'; q(3)<= 'X'; end if; end process; end pipo;
--}} End of automatically maintained section architecture ring_counter of ring_counter is begin process(clk) begin if(clk='1' and clk'event)then q1<=q(10); q(2)<=q1; q(3)<=q(2); q(4)<=q(3); q(5)<=q(4); q(6)<=q(5); q(7)<=q(6); q(8)<=q(7); q(9)<=q(8); q(10)<=q(9); end if; end process;
end binary_counter;
begin process(clk) begin if (clk='1' and clk'event)then qa<= not qa; qb<= qb xor ((qa and up)or ((not qa) and (not up))); qc<= qc xor ((qa and qb and up)or ((not qa)and (not qb) and (not up))); end if; end process; -- enter your statements here -end sync_up_down;
12
VHDL code for a 4-bit register with a positive-edge clock, asynchronous set and clock enable. entity flop is port(C, CE, PRE : in std_logic; D : in std_logic_vector (3 downto 0); Q : out std_logic_vector (3 downto 0)); end flop; architecture archi of flop is begin process (C, PRE) begin if (PRE='1') then Q = "1111"; elsif (C'event and C='1')then if (CE='1') then Q = D; end if; end if; end process; end archi; VHDL code for a 4-bit unsigned Up counter with asynchronous clear. entity counter is port(C, CLR : in std_logic; Q : out std_logic_vector(3 downto 0)); end counter; architecture archi of counter is signal tmp: std_logic_vector(3 downto 0); begin process (C, CLR) begin if (CLR='1') then tmp = "0000"; elsif (C'event and C='1') then tmp = tmp + 1; end if; end process; Q = tmp; end archi;
13
VHDL code for a 4-bit unsigned Down counter with synchronous set. entity counter is port(C, S : in std_logic; Q : out std_logic_vector(3 downto 0)); end counter; architecture archi of counter is signal tmp: std_logic_vector(3 downto 0); begin process (C) begin if (C'event and C='1') then if (S='1') then tmp = "1111"; else tmp = tmp - 1; end if; end if; end process; Q = tmp; end archi;
Following is the VHDL code for a 4-bit unsigned Up Counter with asynchronous load from primary input.
entity counter is port(C, ALOAD : in std_logic; D : in std_logic_vector(3 downto 0); Q : out std_logic_vector(3 downto 0)); end counter; architecture archi of counter is signal tmp: std_logic_vector(3 downto 0); begin process (C, ALOAD, D) begin 14
if (ALOAD='1') then tmp = D; elsif (C'event and C='1') then tmp = tmp + 1; end if; end process; Q = tmp; end archi;
Following is the VHDL code for a 4-bit unsigned Up Counter with synchronous load with a constant.
entity counter is port(C, SLOAD : in std_logic; Q : out std_logic_vector(3 downto 0)); end counter; architecture archi of counter is signal tmp: std_logic_vector(3 downto 0); begin process (C) begin if (C'event and C='1') then if (SLOAD='1') then tmp = "1010"; else tmp = tmp + 1; end if; end if; 15
VHDL code for a 4-bit unsigned Up counter with asynchronous clear and clock enable.
entity counter is port(C, CLR, CE : in std_logic; Q : out std_logic_vector(3 downto 0)); end counter; architecture archi of counter is signal tmp: std_logic_vector(3 downto 0); begin process (C, CLR) begin if (CLR='1') then tmp = "0000"; elsif (C'event and C='1') then if (CE='1') then tmp = tmp + 1; end if; end if; end process; Q = tmp; 16
end archi;
The VHDL code for a 4-bit unsigned Up/Down counter with asynchronous clear
entity counter is port(C, CLR, up_down : in std_logic; Q : out std_logic_vector(3 downto 0)); end counter;
architecture archi of counter is signal tmp: std_logic_vector(3 downto 0); begin process (C, CLR) begin if (CLR='1') then tmp = "0000"; elsif (C'event and C='1') then if (up_down='1') then tmp = tmp + 1; else tmp = tmp - 1; end if; end if; end process; Q = tmp; end archi; 17
process (signal names) begin if (clock event and clock = 1) then output <= data; end if; end process ; VHDL code for a D Flip Flop with Reset and Clear
if reset = 0 then output <= 0; elsif set = 0 then output <= 1; elsif (clock event and clock = 1) then output <= data; end if; VHDL code for a D Flip Flop
if (clockevent and clock = 0) then if (reset = 0 and data = 0) then output <= 0; elsif (reset = 0 and data = 1) then output <= 0; elsif (reset = 1 and data = 0) then output <= 0; elsif (reset = 1 and data = 1) then Output <= 1; end if; 18
if (clockevent and clock = 1) then if (in1 = 0 and in2 = 0) then output <= output; elsif (in1 = 1 and in2 = 0) then output <= 1; elsif (in1 = 0 and in2 = 1) then output <= 0; elsif (in1 = 1 and in2 = 1) then output <= not(output); end if; end if;
if clear = 0 then shift_reg <= 00000000; elsif (clockevent and clock = 1) then shift_reg(7 downto 1) <= (6 downto 0); shift_reg(0) <= serial; end if;
19
if load = 0 then shift_reg <= parallel; elsif (clockevent and clock = 1) then serial <= shift_reg(7); shift_reg(7 downto 1) <= (6 downto 0); end if;
if load = 0 then output <= 1111; elsif (clockevent and clock = 1) then output <= data - 1; end if; carry <= 0 when output = 0000 else 1; load <= carry;
elsif (a or b) = 1 then sum <= 1; carry <= 0 end if; elsif c = 1 then if (a and b) = 1 then sum <= 1; carry <= 1; elsif (a or b) = 1 then sum <= 0; carry <= 1; end if; end if;
if reset = 0 then state <= stateA; output <= 0; elsif (clockevent and clock) = 1 then case state is when stateA output <= 0; state <= stateB when stateB output <= 1; if input = 1 then state <= stateB; else state <=stateC; end if; when stateC output <= 0 state <= stateA; end case;
21