Technika cyfrowa – projekt: Sumator 4bitowy...
Click here to load reader
-
Upload
truongthuy -
Category
Documents
-
view
218 -
download
0
Transcript of Technika cyfrowa – projekt: Sumator 4bitowy...
Technika cyfrowa – projekt:Sumator 4bitowy równoległy
Autorzy: Paweł BaraRobert Boczek
Przebieg prac projektowych:
Zadany układ dostaje na wejściu dwie czterobitowe liczby naturalne, sumuje je, po czym co najwyżej pięciobitowy wynik wyprowadza na siedmiosegmentowy wyświetlacz. Całość oparta jest o półsumator i trzy sumatory pełne:
a) półsumator:
A B S P0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
A i B – dwa bityS – wynik (A xor B)P – bit przeniesienia (A and B)
W ten sposób otrzymujemy najmłodszy bit wyniku i pierwszy bit przeniesienia.
b) sumator pełny:
Ai Bi Pi1 Si Pi
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
i = 2, 3, 4
Wejście:• Ai – ity bit liczby a• Bi – ity bit liczby b• Pi1 – poprzedni bit przeniesienia
Wyjście• Si – ity bit sumy (Ai xor Bi xor Pi1)• Pi – kolejny bit przeniesienia (Ai * Bi + (Ai xor Bi) * Pi1)
Cała operacja przebiega następująco:
P4 P3 P2 P1
A4 A3 A2 A1
+ B4 B3 B2 B1
S5 S4 S3 S2 S1
Korzystając z narzędzia Quartus przenosimy złożony układ na płytkę UP2. Osiem przełączników FLEX_SWITCH reprezentuje bity liczb wejściowych. Wynik przekazujemy na wyświetlacz siedmiosegmentowy FLEX_DIGIT zaprogramowany odpowiednią funkcją w języku VHDL przekształcającą cztery pierwsze bity wyniku na czytelną postać szesnastkową. Najstarszy bit wyniku reprezentujemy kropką dziesiętną, oznaczającą zwiększenie wyświetlanej liczby o 16.
Rys. 1. Schemat blokowy w Multisimie.
Rys. 2. Schemat bloku w Quartusie.
W programie Quartus wykonaliśmy dwie wersje układu jedną w całości w języku VHDL, drugą z wykorzystaniem bloczka I/O, kodu VHDL i zestawu bramek.
Kod wyświetlający liczby szesnastkowe na wyświetlaczu:
ARCHITECTURE mojBolok_architecture OF mojBolok IS SIGNAL LED: std_logic_vector(6 downto 0); BEGIN
process(c1,c2,c3,c4) begin if (not c1 and not c2 and not c3 and c4)='1' then
LED <= "1111001"; 1 elsif (not c1 and not c2 and c3 and not c4)='1' then
LED <= "0100100"; 2 elsif ( not c1 and not c2 and c3 and c4 )='1' then 3
LED <= "0110000"; 3 elsif ( not c1 and c2 and not c3 and not c4 )='1' then 4
LED <= "0011001"; 4 elsif ( not c1 and c2 and not c3 and c4 )='1' then 5
LED <= "0010010"; 5 elsif ( not c1 and c2 and c3 and not c4 )='1' then 6
LED <= "0000010"; 6 elsif ( not c1 and c2 and c3 and c4 )='1' then 7
LED <= "1111000"; 7 elsif ( c1 and not c2 and not c3 and not c4 )='1' then 8
LED <= "0000000"; 8 elsif ( c1 and not c2 and not c3 and c4 )='1' then 9
LED <= "0010000"; 9 elsif ( c1 and not c2 and c3 and not c4 )='1' then A
LED <= "0001000"; A elsif ( c1 and not c2 and c3 and c4 )='1' then b
LED <= "0000011"; b elsif ( c1 and c2 and not c3 and not c4 )='1' then C
LED <= "1000110"; C elsif ( c1 and c2 and not c3 and c4 )='1' then d
LED <= "0100001"; d elsif ( c1 and c2 and c3 and not c4 )='1' then E
LED <= "0000110"; E elsif ( c1 and c2 and c3 and c4 )='1' then F
LED <= "0001110"; F else 0
LED <= "1000000"; end if; end process; process (LED) begin
a<=LED(0); b<=LED(1); c<=LED(2); d<=LED(3); e<=LED(4); f<=LED(5); g<=LED(6); end process;
END mojBolok_architecture;
Wersja napisana wyłącznie w języku VHDL ma postać:
LIBRARY ieee; USE ieee.std_logic_1164.all;
ENTITY robercik IS PORT( a1, a2, a3, a4, b1, b2, b3, b4 : IN STD_LOGIC;
a,b,c,d,e,f,g, p : OUT STD_LOGIC );
END robercik;
ARCHITECTURE sumator of robercik IS signal c1, c2, c3, c4, c5: STD_LOGIC; signal tmp: STD_LOGIC_VECTOR ( 2 downto 0); signal LED : STD_LOGIC_VECTOR ( 6 downto 0);
BEGIN
tmp(0) <= ( not a4 and not b4 ); tmp(1) <= (((not a3 xor not b3) and (tmp(0))) or (not a3 and not b3)); tmp(2) <= (((not a2 xor not b2) and (tmp(1))) or (not a2 and not b2));
process (tmp) begin
bit przeniesienia p <= not (((not a1 xor not b1) and (tmp(2))) or (not a1 and not b1)); c4 <= (not b4 xor not a4); c1 <= ((not a1 xor not b1) xor tmp(2)); c2 <= ((not a2 xor not b2) xor tmp(1)); c3 <= ((not a3 xor not b3) xor tmp(0));
end process;
process(c1,c2,c3,c4) begin if (not c1 and not c2 and not c3 and c4)='1' then
LED <= "1111001"; 1 elsif (not c1 and not c2 and c3 and not c4)='1' then
LED <= "0100100"; 2 elsif ( not c1 and not c2 and c3 and c4 )='1' then 3
LED <= "0110000"; 3 elsif ( not c1 and c2 and not c3 and not c4 )='1' then 4
LED <= "0011001"; 4 elsif ( not c1 and c2 and not c3 and c4 )='1' then 5
LED <= "0010010"; 5 elsif ( not c1 and c2 and c3 and not c4 )='1' then 6
LED <= "0000010"; 6 elsif ( not c1 and c2 and c3 and c4 )='1' then 7
LED <= "1111000"; 7 elsif ( c1 and not c2 and not c3 and not c4 )='1' then 8
LED <= "0000000"; 8 elsif ( c1 and not c2 and not c3 and c4 )='1' then 9
LED <= "0010000"; 9 elsif ( c1 and not c2 and c3 and not c4 )='1' then A
LED <= "0001000"; A elsif ( c1 and not c2 and c3 and c4 )='1' then b
LED <= "0000011"; b elsif ( c1 and c2 and not c3 and not c4 )='1' then C
LED <= "1000110"; C elsif ( c1 and c2 and not c3 and c4 )='1' then d
LED <= "0100001"; d elsif ( c1 and c2 and c3 and not c4 )='1' then E
LED <= "0000110"; E elsif ( c1 and c2 and c3 and c4 )='1' then F
LED <= "0001110"; F else 0
LED <= "1000000"; end if; end process; process (LED) begin a<=LED(0); b<=LED(1); c<=LED(2); d<=LED(3); e<=LED(4); f<=LED(5); g<=LED(6);
end process;
END sumator;
Porty a, b, c, d, e, f i g to odpowiednie segmenty wyświetlacza FLEX_DIGIT. Port p to z kolei bit przeniesienia w naszym układzie jest nią kropka dziesiętna wyświetlacza. Po odpowiednim przypisaniu portów za pomocą Assignment Editora układ jest gotowy. Wystarczy skompilować kod i za pomocą Programmera zaprogramować płytkę.