Professional Documents
Culture Documents
I. Nhim v v yu cu:
1. Nhim v:
Thit k v kim tra t ng b cng s thc 32 bit theo chun IEEE 754, h tr
mt kiu lm trn ti gn nht chn.
2.Yu cu:
2.1 Yu cu c bn.
Thit k m phng cv kim tra trn ModelSim vi mt s lng ln t hp
u vo nht nh. Khuyn khch kim tra t ng.
Thit k phi tng hp c trn XiLinx ISE.
2.2 Yu cu nng cao.
Kim tra thit k trn mch tht FPGA, s dng IC chc nng v cc giao tip c
sn trn mch th nghim: UART, USB/UART, PS/2, LCD1602A, 7SEG-LED
dislay, Leds, Swiths, Buttons trong phi c 1 giao tip thc hin vi my tnh.
Kho st v hiu sut lm vic ca mch bng cch thay i tn s u vo, lp
bo co v mc s dng ti nguyn hiu sut(tc lm vic ca mch).
begin
sa <= a(31);
sb <= b(31);
ea <= a(30 downto 23);
eb <= b(30 downto 23);
ma <= a(22 downto 0);
mb <= b(22 downto 0);
end process;
end dataflow;
S chn:
signal b_1
: std_logic_vector(8 downto 0);
signal s1
: std_logic_vector(8 downto 0);
signal a1, b1
: std_logic_vector(8 downto 0);
begin
b1 <= '0' & b;
b_1 <= not(b1) + 1;
a1 <= '0' & a;
s1 <= a1 + b_1;
process (a, b, s1(8))
begin
if (s1(8)='0') then
-- ea > eb
c <= a;
--dau ra c la so mu lon hon
elsif(s1(8)='1') then
-- ea < eb
c <= b;
end if;
end process;
s <= to_integer(signed(s1))
-- ea - eb
end subtract;
S chn:
port (a
: in std_logic_vector(22 downto 0);
b
: in std_logic_vector(22 downto 0);
ea,eb : in std_logic_vector(7 downto 0);
s
: in integer;
c
: out std_logic_vector(24 downto 0);
d
: out std_logic_vector(24 downto 0);
e
: out std_logic
);
end mux;
--------------------------------------------------------------architecture mux of mux is
signal a1
: std_logic_vector(24 downto 0);
signal b1
: std_logic_vector(24 downto 0);
signal a2
: std_logic_vector(24 downto 0);
signal b2
: std_logic_vector(24 downto 0);
signal sum
: std_logic_vector(24 downto 0);
signal temp1
: std_logic_vector(24 downto 0);
component cla_adder is
port ( a, b
: in std_logic_vector(24 downto 0);
s
: out std_logic_vector(24 downto 0)
);
end component;
component sub_norm is
port
(
a,b
: in std_logic_vector(22 downto 0);
ea , eb
: in std_logic_vector(7 downto 0);
a_o, b_o
: out std_logic_vector(24 downto 0)
);
end component;
-----------------------------------------------------------------begin
U0: component sub_norm
port map (a,b,ea,eb,a1,b1);
temp1 <= not(b1) + 1;
------------------------------------------------------------------U1: component cla_adder
port map(a1, temp1, sum);
--tru 2 phan thap phan cho nhau (a1 - b1)
U2: process (a1, b1, s, sum)
begin
if (s > 0) then -- exp(a) > exp(b) va a1 > b1
a2 <= a1;
b2 <= b1;
e <= '0';
elsif (s = 0 and sum(24) = '0') then
a2 <= a1;
b2 <= b1;
e <= '0';
elsif (s = 0 and sum(24) = '1') then
a2 <= b1;
b2 <= a1;
e <= '1';
elsif (s < 0) then
a2 <= b1;
b2 <= a1;
e <= '1';
end if;
end process;
c <= a2;
d <= b2;
end mux;
-----------------------------------------------------------------------------------------------------
ea , eb
a_o, b_o
);
end entity;
---------------------------------------------------------------architecture behav of sub_norm is
begin
process(a, b,ea,eb)
begin
if(ea="00000000" ) then
a_o <= '0' & a & '0';
else
a_o <= "01" & a;
end if;
if(eb="00000000" ) then
b_o <= '0' & b & '0';
else
b_o <= "01" & b;
end if;
end process;
end behav;
---------------------------------------------------------------------------------------------------library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--------------------------------entity cla_adder is
port( a, b
: in std_logic_vector(24 downto 0);
s
: out std_logic_vector(24 downto 0)
);
end cla_adder;
---------------------------------architecture cla_adder of cla_adder is
begin
s <= a + b;
end cla_adder;
S chn:
b3 <= b4;
elsif(sa /= sb) then
b3 <= not(b4);
end if;
end process;
U1:process(s3, b3,sa,sb,b)
begin
if(s3 = 0) then
if sa=sb then
c <=b3;
G <= '0';
R <= '0';
S <= '0';
cin <= '0';
elsif sa /= sb then
c <= b3;
G <= '0';
R <= '0';
S <= '0';
cin <= '1';
end if;
elsif(s3 = 1) then
if sa=sb then
c <=b3;
G <= b(0);
R <= '0';
S <= '0';
cin <= '0';
elsif sa /= sb then
if b(0)='0' then
c <=b3;
G <='0';
R <= '0';
S<= '0';
cin <= '1';
elsif b(0)='1' then
c <=b3;
G <='1';
R <= '0';
S <= '0';
S <='0';
else
S <='1';
end if;
cin <= '0';
elsif sa/=sb then
if b(22 downto 0) = temp2(22 downto 0)then
if (b(24)='1' and b(23)='1') then
c <=b3;
G <='0';
R <='1';
S <='0';
cin <= '0';
elsif (b(24)='1' and b(23)='0') then
c <=b3;
G <='1';
R <='0';
S <='0';
cin <= '0';
elsif (b(24)='0' and b(23)='1') then
c <=b3;
G <='1';
R <='1';
S <='0';
cin <= '0';
elsif (b(24)='0' and b(23)='0') then
c <=b3;
G <='0';
R <='0';
S <='0';
cin <= '1';
end if;
else
c <=b3;
G <= not(b(24));
R <= not(b(23));
S <='1';
cin <= '0';
end if;
end if;
R<='0';
S<='0';
cin <= '0';
elsif sa/=sb then
c<=b3;
G<='1';
R<='1';
S<='0';
cin <= '0';
end if;
end if;
end process;
end shifter;
S chn:
sb
: in std_logic;
s_out : out std_logic_vector(24 downto 0); -sign : out std_logic
cung
);
end add_sub;
---------------------------------architecture add_sub of add_sub is
signal s : std_logic_vector (24 downto 0);
component cla_adder1 is
port(
a, b
: in std_logic_vector(24 downto 0);
cin
: in std_logic;
s
: out std_logic_vector(24 downto 0)
);
end component;
begin
U1: component cla_adder1
port map (a, b,cin, s);
U2:
process(sa, sb, e)
begin
if (sa = '0' and sb = '0') then
sign <= '0';
elsif (sa = '1' and sb = '1') then
sign <= '1';
elsif (sa = '0' and sb = '1' and e = '0') then
sign <= '0';
elsif (sa = '0' and sb = '1' and e = '1') then
sign <= '1';
elsif (sa = '1' and sb = '0' and e = '0') then
sign <= '1';
elsif (sa = '1' and sb = '0' and e = '1') then
sign <= '0';
end if;
end process;
s_out <= s;
end add_sub;
--------------------------------------------------------------------------------------------------------------
S chn:
port (
S chn:
begin
temp3 <= to_integer(unsigned(shv));
temp1 <= to_integer(unsigned(exp_in));
end process;
U1:process (exp_in, shv, temp1, temp3)
begin
if(shv = "11111") then
temp2 <= temp1 + 1;
else
temp2 <= temp1 - temp3;
end if;
end process;
exp_out <= std_logic_vector(to_unsigned(temp2, 8));
end adjust;
S chn:
port( a, b
: in std_logic_vector(24 downto 0);
s
: out std_logic_vector(24 downto 0)
);
end component;
signal b1 : std_logic_vector(24 downto 0);
signal s1 : std_logic;
begin
U0:cla_adder port map (a, "0000000000000000000000001", b1);
U1:process (R, S, a, b1)
begin
if (R = '0') then b <= a;
elsif (R = '1' and S = '1') then b <= b1;
elsif (R = '1' and S = '0' and a(0) = '1') then b <= b1;
elsif (R = '1' and S = '0' and a(0) = '0') then b <= a;
end if;
end process;
end round;
-------------------------------------------------------------------------------------------------------
S chn:
end process;
s_out <= to_stdlogicvector(temp2);
end normalize2;
S chn:
use ieee.numeric_std.all;
--------------------------------------------------------entity adder_fp is
port( a : in std_logic_vector(31 downto 0);
b : in std_logic_vector(31 downto 0);
c : out std_logic_vector(31 downto 0)
);
end adder_fp;
---------------------------------------------------------architecture structure of adder_fp is
signal ma1, mb1, mb2, mc1, mc2, mc3, mc : std_logic_vector(24 downto 0);
signal ma, mb: std_logic_vector(22 downto 0);
signal ea, eb, ec1, ec2, ec : std_logic_vector(7 downto 0);
signal e, sign, sa, sb, G1, R1, S1, R2, S2,cin,cin1 : std_logic;
signal shv1, shv2 : signed(4 downto 0);
signal s : integer;
component separate is
port ( a, b
: in std_logic_vector(31 downto 0);
sa, sb : out std_logic;
ea, eb : out std_logic_vector(7 downto 0);
ma, mb : out std_logic_vector(22 downto 0)
);
end component;
component subtract is
port( a, b
: in std_logic_vector(7 downto 0); --a>b
c
: out std_logic_vector(7 downto 0);
s
: out integer
);
end component;
component mux is
port (a
: in std_logic_vector(22 downto 0);
b
: in std_logic_vector(22 downto 0);
ea,eb : in std_logic_vector(7 downto 0);
s
: in integer;
c
: out std_logic_vector(24 downto 0);
d
: out std_logic_vector(24 downto 0);
: out std_logic
);
end component;
component shifter is
port (b
sa, sb
s0
c
G, R, S,cin
);
end component;
component add_sub is
port( a, b
: in std_logic_vector(24 downto 0);
e,cin : in std_logic;
sa
: in std_logic;
sb
: in std_logic;
s_out : out std_logic_vector(24 downto 0);
sign : out std_logic
);
end component;
component normalize is
port ( sa,sb :in std_logic;
ea,eb : in std_logic_vector(7 downto 0);
s_i
: in std_logic_vector(24 downto 0);
G, R, S : in std_logic;
s_a
: out std_logic_vector(24 downto 0);
shv
: out signed(4 downto 0);
R1, S1 : out std_logic
);
end component;
component round is
port ( a
: in std_logic_vector(24 downto 0);
R, S : in std_logic;
b
: out std_logic_vector(24 downto 0)
);
end component;
component normalize2 is
port ( s
: in std_logic_vector(24 downto 0);
s_out : out std_logic_vector(24 downto 0);
shv
: out signed(4 downto 0)
);
end component;
component adjust is
port ( exp_in : in std_logic_vector(7 downto 0);
shv
: in signed(4 downto 0);
exp_out : out std_logic_vector(7 downto 0)
);
end component;
begin
U0: separate port map (a, b, sa, sb, ea, eb, ma, mb);
U1: subtract port map (ea, eb, ec1, s);
U2: mux
port map (ma, mb,ea,eb, s, ma1, mb1, e);
U3: shifter
port map (mb1, sa, sb, s, mb2, G1, R1, S1,cin1);
U4: add_sub
port map (ma1, mb2, e,cin1, sa, sb, mc1, sign);
U5: normalize port map (sa,sb,ea,eb,mc1, G1, R1, S1, mc2, shv1, R2, S2);
U6: adjust
port map (ec1, shv1, ec2);
U7: round
port map (mc2, R2, S2, mc3);
U8: normalize2 port map (mc3, mc, shv2);
U9: adjust
port map (ec2, shv2, ec);
-----------------------------------------------------------------process(a,b,mc,ec,sign)
begin
c <= sign & ec & mc(22 downto 0);
if(a(31)/= b(31) and a(30 downto 0)=b(30 downto 0)) then
c<=x"00000000";
end if;
if a(30 downto 23)="11111111" then
c(22 downto 0) <= "00000000000000000000001";
elsif b(30 downto 23)="11111111" then
c(22 downto 0) <= "00000000000000000000001";
--TH VO CUNG
--elsif a(30 downto 23)="11111111" and a(22 downto 0) = "0" then
-c(22 downto 0) <= "00000000000000000000001";
#
GND
: 1
#
INV
: 38
#
LUT1
: 1
#
LUT2
: 121
#
LUT3
: 196
#
LUT4
: 1158
#
MULT_AND
: 1
#
MUXCY
: 513
#
MUXF5
: 72
#
VCC
: 1
#
XORCY
: 108
# FlipFlops/Latches
: 84
#
LD
: 29
#
LDCP
: 54
#
LDE
: 1
# Clock Buffers
: 2
#
BUFG
: 2
# IO Buffers
: 96
#
IBUF
: 64
#
OBUF
: 32
=========================================================================
Device utilization summary:
--------------------------Selected Device : 3s500epq208-5
Number of Slices:
831 out of
4656
17%
Number of Slice Flip Flops:
84 out of
9312
0%
Number of 4 input LUTs:
1514 out of
9312
16%
Number of IOs:
96
Number of bonded IOBs:
96 out of
158
60%
Number of GCLKs:
2 out of
24
8%
is 219452 kilobytes
:
0 (
0 filtered)
:
53 (
0 filtered)
:
12 (
0 filtered)
V. Tng kt
Bi ton thit k b cng s thc c nhm chng em hon thnh, n
gii quyt tt c cc trng hp c th xy ra li, cc trng hp c bit. Tuy nhin,
bn cnh n ca chng em cn mt s hn ch l cha chy c trn mch
FPGA, cha ti u mt cch tt nht v ngn gn nht code VHDL.