Transcript 下載/瀏覽
組合邏輯應用電路 m 條 輸出線 n 條 輸入線 組合邏輯電路 (Combinational Circuit) 分析技術 -真值表 -卡諾圖 -列表法 -布林函數 邏輯閘 -AND -OR -NOT -NAND -NOR -XOR 組合邏輯應用電路-半加器 半加器(Half-Adder:HA) -輸入:被加數、加數 -輸出:和(Sum) 、進位(Carry out) 被加數A,加數B,進位C,和S 的真值表 被加數 加數 進位 和 A 0 0 1 1 B 0 1 0 1 C 0 0 0 1 S 0 1 1 0 S ( A, B) AB AB C ( A, B) AB A B 半 加 器 S C 組合邏輯應用電路-半加器VHDL 程式 library ieee; use ieee.std_logic_1164.all; entity half_adder is port ( A,B : in std_logic; S, C : out std_logic); end half_adder; architecture half_adder_logic of half_adder is begin S <= (A xor B); C <= (A and B); end half_adder_logic; 組合邏輯應用電路-全加器 全加器(Full-Adder:FA) -輸入:被加數、加數、前一級的進位輸入(Carry in) -輸出:和(Sum) 、進位輸出(Carry out) 全加器= 「被加數」+「加數」+「進位輸入」 被加數A,加數B,進位輸入Ci,和S,進位輸出Ci+1 的真值表 被加數 加數 進位輸入 進位輸出 合 S C i AB Ci AB Ci AB Ci AB A B Ci Ci+1 S S Ci A B 0 0 0 0 0 Ci 1 Ci ( A B) AB 0 0 1 0 1 Ci 1 Ci A Ci B AB 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 A B Ci 全 加 器 S Ci+1 組合邏輯應用電路-全加器 S Ci A B Ci 1 Ci ( A B) AB Half-Adder Ci Ci Ci+1 1 3 Ci+1 1 3 2 2 B B 1 1 3 3 1 2 2 3 3 3 S 2 1 2 3 2 2 A A 1 1 1 3 2 1 3 2 S Ci A B Ci 1 Ci A Ci B AB Half-Adder Ci Ci+1 S 組合邏輯應用電路-全加器VHDL程式 library ieee; use ieee.std_logic_1164.all; entity FULL_ADDER is port ( A,B,CIN :in std_logic; S, COUT : out std_logic); end FULL_ADDER; architecture full_adder_logic of FULL_ADDER is begin S <= A xor B xor CIN; COUT <= (A and B) or (B and CIN) or (CIN and A); end full_adder_logic; 組合邏輯應用電路-漣波進位加法器 漣波進位加法器: -「半加器」或「全加器」為一位元(one bit)加法器 -多位元的加法器,須將「半加器」或「全加器」以串接方式連接,最左 邊為最高位元(MSB),最右邊為最低位元(LSB) Ci Ci Ci+1 Ci+1 Ci Ci+1 Ci Ci+1 Ci Ci+1 C Ci Ci Ci+1 Ci+1 組合邏輯應用電路-漣波進位加法器 TTL 4位元(4-bit)的全加器: 7483(GND:第12腳,Vcc:第5腳) -被加數為「A4A3A2A1」 -加數為「B4B3B2B1」 -運算和為「Σ4Σ3Σ2Σ1」 -進位輸入為C0 -進位輸出為C4 組合邏輯應用電路-漣波進位加法器VHDL程式 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_signed.all; entity fulladd is port ( cin : in integer range 0 to 1; A, B : in integer range 0 to 128; sum : out integer range 0 to 256); end fulladd; architecture fulladd_logic of fulladd is begin sum <= A + B + cin; end fulladd_logic; 組合邏輯應用電路-漣波進位加法器VHDL程式 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_signed.all; use ieee.std_logic_arith.all; Entity ADDER_16 is port ( A,B :in std_logic_vector(15 downto 0); S :out std_logic_vector(15 downto 0)); End ADDER_16 architecture ADDER_16_logic of ADDER_16 is begin S <= A+B; end ADDER_16_logic ; 組合邏輯應用電路- BCD加法器 @BCD碼是四位元的二進碼,可用 「四位元加法器」完成 @相加和超過9,必須加“6”修正, 使用「四位元加法器」執行 BCD加法運算,以設計「修正 電路」修正結果 @「四位元加法器」之和與BCD碼 的真值表如右 @BCD加法器的「判斷電路」 組合邏輯應用電路- BCD加法器 組合邏輯應用電路- BCD加法器VHDL程式 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity BCD_adder is port (A, B :in std_logic_vector(3 downto 0); Y : out std_logic_vector(4 downto 0)); end BCD_adder; architecture BCD_adder_logic of BCD_adder is signal Z : std_logic_vector(4 downto 0); signal adjust : std_logic; begin Z <= (‘0” & A) + B; adjust <=‘1’ when z>9 else ‘0’; Y<= Z when (adjust=‘0’) else Z+6; end BCD_adder_logic; 組合邏輯應用電路-半減器 半減器 -輸入:被減數(A),減數(B) -輸出:借位輸出(M),差(D) -真值表如右: D AB AB A B M AB S AB AB A B C AB 半加器 組合邏輯應用電路-半減器VHDL程式 library ieee; use ieee.std_logic_1164.all; entity half_suber is port ( A,B :in std_logic; M, D : out std_logic); end half_suber; architecture half_suber_logic of half_suber is begin D <= (A xor B); M <= ((not A) and B); end half_suber_logic; 組合邏輯應用電路-全減器 全減器 -輸入:被減數(A)、減數(B) 、 前一級借位輸入(N) -輸出:差D 、借位輸出(M) -全減器= 「被減數」-「減數」-「借位輸入」 -真值表如下: D ABN ABN ABN ABN A B N M ABN ABN ABN ABN A( B N ) BN N ( A B) AB A B N 全 減 器 D M D ABN ABN ABN ABN A B N M AN AB BN 組合邏輯應用電路-全減器 D A B N M N ( A B ) AB D A B N M AN AB BN 組合邏輯應用電路-全減器VHDL程式 library ieee; use ieee.std_logic_1164.all; entity full_suber is port ( A,B ,N :in std_logic; M, D : out std_logic); end full_suber; architecture full_suber_logic of full_suber is begin D <= (A xor B) xor N; M <= ((not A) and (B xor N)) or (B and N); end full_suber_logic; 組合邏輯應用電路-加減法器 加法: A+B 減法: A B A B 1 (2’S補數) 組合邏輯應用電路-加減法器VHDL程式 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity ADD_SUB is port ( A, B :in bit_vector(3 downto 0); select :in boolean; RESULT : bit_vector(4 downto 0)); end ADD_SUB; architecture ADD_SUB_logic of ADD_SUB is begin process (select, A , B) begin if select=‘0’ then RESULT <=A+B; else RESULT <= A-B; end if; end process end ADD_SUB_logic; 組合邏輯應用電路- 比較器 (Comparator) 比較器:兩個輸入大小比較,輸出的結果有三種: (1)A>B (2)A=B (3)A<B 一位元比較器,真值表如下: 組合邏輯應用電路- 比較器 (Comparator) • 多位元比較器:由多個單一位元比較器串接,運算時需考慮 前一級的比較結果 • 當高位元較大(A>B)或較小(A<B)時,低位元的比較結果都 將無效(不能改變高位元的大小關係) • 當高位元相等(A=B)時,由低位元的大小決定,“可串接” 單一位元比較器 • 結構如下: 組合邏輯應用電路- 比較器 (Comparator) (2)Y ( A B) (1) X ( A B ) (a ) AB (高位元大於) (高位元相等且 (b) ( A B ) x 低位元大於) X AB ( A B ) x (3) Z ( A B ) (a) A B (高位元小於) (b) ( A B ) z (高位元相等且 低位元小於) X AB ( A B ) z (a)( A B) and (高位元相等且 (b) y 1 低位元相等) Y ( A B) y 組合邏輯應用電路- 比較器 (Comparator) 組合邏輯應用電路- 比較器 (Comparator) 使用7485完成一個8位元的比較器 組合邏輯應用電路- 比較器 (Comparator)VHDL程式 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; entity comparator_8 is port ( A,B :in std_logic_vector(7 downto 0); Large, Equal, Small :out std_logic)); end comparator_8; architecture comparator_8_logic of comparator_8 is begin Large <=‘1’ when A>B else ‘0’; Equal <=‘1’ when A=B else ‘0’; Small <=‘1’ when A<B else ‘0’; end comparator_8_logic; 組合邏輯應用電路-多工器(Multiplexer-MUL) 多工器:將多條輸入線訊號,選擇其中一條連接至「單一輸 出線」。多工器的輸入線(一般均為2n條),由一組「選擇線 (n條)」來決定。 組合邏輯應用電路-多工器(Multiplexer-MUL) Y S 0 X 0 S0 X1 組合邏輯應用電路-多工器(Multiplexer-MUL) S1 S0 Y S 1 S 0 X 0 S 1S 0 X 1 S1 S 0 X 2 S0 S1 X 3 組合邏輯應用電路-多工器(Multiplexer-MUL) 組合邏輯應用電路-多工器(Multiplexer-MUL) 組合邏輯應用電路-多工器(Multiplexer-MUL) 組合邏輯應用電路-多工器(Multiplexer-MUL)VHDL程式 library ieee; use ieee.std_logic_1164.all; entity mux8to1 is port ( X :in std_logic_vector(2 downto 0); D0,D1,D2,D3,D4,D5,D6,D7: in std_logic; Y :out std_logic); end mux8to1; architecture mux8to1 _logic of mux8to1 is begin Y <= D0 when X=“000” else D1 when X=“001” else D2 when X=“010” else D3 when X=“011” else D4 when X=“100” else D5 when X=“101” else D6 when X=“110” else D7 ; end mux8to1 _logic; 組合邏輯應用電路-多工器(Multiplexer-MUL)VHDL程式 library ieee; use ieee.std_logic_1164.all; entity mux4to1_8 is port ( X :in std_logic_vector(1 downto 0); D0,D1,D2,D3 : in std_logic_vector(7 downto 0); Y :out std_logic_vector(7 downto 0)); end mux4to1_8; architecture mux4to1_8 _logic of mux4to1_8 is begin Y <= D0 when X=“00” else D1 when X=“01” else D2 when X=“10” else D3 ; end mux4to1 _logic ; 組合邏輯應用電路- 解多工器(DeMultiplexer-DeMUL) 1x4 解多工器 1x2 解多工器 S0 0 1 Y0 X 0 Y0 =S0 X Y1 =S0 X Y1 0 X S1 S0 Y0 Y1 Y2 Y3 Y0 =S1 S0 X 0 0 X 0 0 0 Y1 =S1S0 X 0 1 0 X 0 0 1 0 0 0 X 0 1 1 0 0 0 X Y2 =S1 S0 X Y3 =S1S0 X 組合邏輯應用電路- 解多工器(DeMultiplexer-DeMUL) 1x8 解多工器 1x16 解多工器 組合邏輯應用電路-解多工器(DeMultiplexer-DeMUL)VHDL程式 library ieee; use ieee.std_logic_1164.all; entity demux1to4 is port ( X :in std_logic_vector(2 downto 0); data :in std_logic D0,D1,D2,D3: out std_logic); end demux1to4; architecture demux1to4_logic of demux1to4 is begin D0 <= data when X=“00” else ‘0’; D1 <= data when X=“01” else ‘0’; D2 <= data when X=“10” else ‘0’; D3 <= data when X=“11” else ‘0’; end demux1to4_logic; 組合邏輯應用電路- 編碼器(Encoder) 編碼器 • 將輸入訊號中的一個訊號(每次只能有1條輸入線動作)轉換成被編 碼 的輸出訊號 • 編碼器具有M條輸入線及N條輸出線(其中M≦2N),稱為「M×N編 碼器」 例: 4×2編碼器 -將4個輸入線分別轉換成二進碼輸出 -真值表如下 Y0 =D1 +D3 Y1 =D 2 +D3 組合邏輯應用電路- 編碼器(Encoder) 8×3編碼器 Y0 =D1 +D3 +D5 +D 7 Y1 =D 2 +D3 +D 6 +D 7 Y2 =D 4 +D5 +D 6 +D 7 組合邏輯應用電路- 編碼器(Encoder)VHDL 程式 library ieee; use ieee.std_logic_1164.all; entity encode8to3 is port ( D0,D1,D2,D3,D4,D5,D6,D7: in std_logic; Y2,Y1,Y0 :out std_logic); end encode8to3; architecture encode8to3_logic of encode8to3 is begin Y2 <= D4 or D5 or D6 or D7; Y1 <= D2 or D3 or D6 or D7; Y0 <= D1 or D3 or D5 or D7; end encode8to3_logic; 組合邏輯應用電路- 編碼器(Encoder)VHDL 程式 library ieee; use ieee.std_logic_1164.all; entity encode8to3 is port ( X : in std_logic_vector(7 downto 0); Y : out std_logic_vector(2 downto 0)); end encode8to3; architecture encode8to3_logic of encode8to3 is begin with X select Y <= “000” when “00000001”, “001” when “00000010”, “010” when “00000100”, “011” when “00001000”, “100” when “00010000”, “101” when “00100000”, “110” when “01000000”, “111” when “10000000”, “000” when others, end encode8to3_logic; 組合邏輯應用電路- 編碼器(Encoder) BCD編碼器 Y0 =D1 +D3 +D5 +D 7 +D9 Y1 =D 2 +D3 +D 6 +D 7 Y2 =D 4 +D5 +D 6 +D 7 Y3 =D8 +D9 組合邏輯應用電路- 編碼器(Encoder) 74147 :「BCD優先編碼器」 74148 : 8×3優先編碼器 組合邏輯應用電路- 編碼器(Encoder)VHDL程式 library ieee; use ieee.std_logic_1164.all; entity encoder74147 is port ( D :in std_logic_vector(9 downto1); Y :out std_logic_vector(3 downto 0)); end encoder74147; architecture encoder74147_logic of encoder74147 is begin Y <= “0110” when D(9)=‘0’ else “0111” when D(8)=‘0’ else “1000” when D(7)=‘0’ else “1001” when D(6)=‘0’ else “1010” when D(5)=‘0’ else “1011” when D(4)=‘0’ else “1100” when D(3)=‘0’ else “1101” when D(2)=‘0’ else “1110” when D(1)=‘0’ else “1111”; end encoder74147_logic; 組合邏輯應用電路- 編碼器(Encoder) (a) 用74148 設計 16×4優先編碼器。 (b)當「10」、「5」的訊號驅動時,說明電路的動作。 組合邏輯應用電路- 解碼器(Decoder) 解碼器: -功能與編碼器相反 -具有M個輸入訊號而有N個輸出訊號( N≦2M),稱為「M×N解碼器」 -將輸入的碼轉換成另一種碼輸出,可稱為「碼轉換器」 2x4解碼器 A B Y3 Y2 Y1 Y0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 3x8解碼器 Y0 =AB,Y1 =AB Y2 =AB,Y3 =AB Y0 =ABC,Y1 =ABC Y2 =ABC, Y3 ABC Y4 =ABC,Y5 =ABC Y6 =ABC, Y7 ABC 組合邏輯應用電路- 解碼器(Decoder) BCD 解碼器 組合邏輯應用電路- 解碼器(Decoder)VHDL程式 library ieee; use ieee.std_logic_1164.all; entity encoder_BCD is port ( X :in std_logic_vector(3 downto1); Y :out std_logic_vector(9 downto 0)); end encoder_BCD; architecture encoder_BCD_logic of encoder_BCD is begin Y(0) <= ‘1’ when X=‘0000’ else ‘0’; Y(1) <= ‘1’ when X=‘0001’ else ‘0’; Y(2) <= ‘1’ when X=‘0010’ else ‘0’; Y(3) <= ‘1’ when X=‘0011’ else ‘0’; Y(4) <= ‘1’ when X=‘0100’ else ‘0’; Y(5) <= ‘1’ when X=‘0101’ else ‘0’; Y(6) <= ‘1’ when X=‘0110’ else ‘0’; Y(7) <= ‘1’ when X=‘0111’ else ‘0’; Y(8) <= ‘1’ when X=‘1000’ else ‘0’; Y(9) <= ‘1’ when X=‘1001’ else ‘0’; end encoder_BCD_logic; 組合邏輯應用電路- 解碼器(Decoder) 74138(3×8解碼器) 74139(2×4解碼器) 7442(BCD解碼器) 組合邏輯應用電路- 解碼器(Decoder):IC7442 利用7442設計一個3×8的解碼器 D=0, 3x8 解碼器,Y0~Y7有一個輸出為0 D=1, Y0~Y7 輸出全為”1” 組合邏輯應用電路- 解碼器(Decoder):IC 7442 利用7442設計一個4×16的解碼器 • 當D=0時 -7442-A致能(ON) -7442-B禁能(OFF) - 解碼輸出為Y0~Y7 • 當D=1時 - 7442-A禁能(OFF) -7442-B致能(ON) -解碼輸出為Y8~Y15 組合邏輯應用電路- 解碼器(Decoder):七段顯示器 七段顯示器 -將7個長條形的發光二極體LED排列,可顯示數字0~9(圖A) -類型:共陽型(common-anode)(圖B),共陰型(common-cathode)(圖C): 圖B 圖C 圖A 組合邏輯應用電路- 解碼器(Decoder):七段顯示器 共陰極七段顯示器控制碼 a=A+C+BD+BD; b=A+B+CD+CD c=B+C+D;d=A+BC+BD+CD+BCD e=BD+CD;f=A+BC+BD+CD g=A+BC+BC+CD 共陽極七段顯示器控制碼 組合邏輯應用電路- 解碼器(Decoder):七段顯示器 @7447,74247:「共陽型」七段顯示器解碼器 @7448,74248:「共陰型」七段顯示器解碼器 D、C、B、A輸入腳:D為高位元,A為低位元 a、b、c、d、e、f、g 輸出腳 -連接至七段顯示器LED輸入端,可串接200Ω~300Ω限流電阻避免 LED燒毀 LT(Lamp Test) 燈管測試腳:輸入「低電位」可測試七段顯示器LED好壞 Ripple Blanking Input(RBI腳):控制是否顯示“0”字形 -輸入「低電位」時且DCBA為「0000」時,不顯示“0”當DCBA不為「0000」時,顯示正常 -若輸入為「高電位」則正常顯示。 Blanking Input/Ripple Blanking Output (BI/RBO腳) -為「輸入腳」時,若輸入「低電位」,七段顯示器LED均不亮 -為「輸出腳」時,若輸入腳DCBA=0000且RBI=「0」時,BI/RBO=0,可串接至另一級七段 顯示器RBI,控制不顯示“0”。 組合邏輯應用電路- 解碼器(Decoder):七段顯示器 共陽七段顯示器 顯示控制電路 3位整數及2位小數共 陽型七段顯示器電路 (整數:前面位數值為 「0」,「0」值不顯 示;小數:後面位數值 為「0」,「0」值顯 示。 組合邏輯應用電路-解碼器(Decoder):七段顯示器VHDL程式 library ieee; use ieee.std_logic_1164.all; entity encoder_7seg is port ( X : in std_logic_vector(3 downto1); Y : out std_logic_vector(9 downto 0); comm : out std_logic ); end encoder_7seg; architecture encoder_7seg _logic of encoder_7seg is begin comm <=‘1’; with X select Y <= “0000001” when “0000”, Y <= “1001111” when “0001”, Y <= “0010010” when “0010”, Y <= “0000110” when “0011”, Y <= “1001100” when “0100”, Y <= “0100100” when “0101”, Y <= “0100000” when “0110”, Y <= “0000111” when “0111”, Y <= “0000000” when “1000”, Y <= “0000100” when “1001”, Y <= “0001000” when “1010”, Y <= “1100000” when “1011”, Y <= “0110001” when “1100”, Y <= “1000010” when “1101”, Y <= “0110000” when “1110”, Y <= “0111000” when “1111”; Y <= “1111111” when others; end encoder_7seg_logic;