logo资料库

VHDL八位乘法器.doc

第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
资料共7页,全文预览结束
一. 设计思路 VHDL 八位乘法器 纯组合逻辑构成的乘法器虽然工作速度比较快,但过于占用硬件资源,难以 实现宽位乘法器,基于 PLD 器件外接 ROM 九九表的乘法器则无法构成单片系统, 也不实用。这里介绍由八位加法器构成的以时序逻辑方式设计的八位乘法器,具 有一定的实用价值,而且由 FPGA 构成实验系统后,可以很容易的用 ASIC 大型 集成芯片来完成,性价比高,可操作性强。其乘法原理是:乘法通过逐项移位相 加原理来实现,从被乘数的最低位开始,若为 1,则乘数左移后与上一次的和相 加;若为 0,左移后以全零相加,直至被乘数的最高位。 二.方案设计与论证 此设计是由八位加法器构成的以时序逻辑方式设计的八位乘法器,它的核心器件 是八加法器,所以关键是设计好八位加法器。 方案:由两个四位加法器组合八位加法器,其中四位加法器是四位二进制并行加 法器,它的原理简单,资源利用率和进位速度方面都比较好。综合各方面的考虑, 决定采用方案二。 三.工作原理 ARICTL 是乘法运算控制电路,它的 START 信号上的上跳沿与高电平有 2 个功能, 即 16 位寄存器清零和被乘数 A[7...0]]向移位寄存器 SREG8B 加载;它的低电平 则作为乘法使能信号,乘法时钟信号从 ARICTL 的 CLK 输入。当被乘数被加载于 8 位右移寄存器 SREG8B 后,随着每一时钟节拍,最低位在前,由低位至高位逐 位移出。当为 1 时,一位乘法器 ANDARITH 打开,8 位乘数 B[7..0]在同一节拍 进入 8 位加法器,与上一次锁存在 16 位锁存器 REG16B 中的高 8 位进行相加, 其和在下一时钟节拍的上升沿被锁进此锁存器。而当被乘数的移出位为 0 时,一 位乘法器全零输出。如此往复,直至 8 个时钟脉冲后,由 ARICTL 的控制,乘法 运算过程自动中止,ARIEND 输出高电平,乘法结束。此时 REG16B 的输出即为 最后的乘积。 四.工作原理框图
arictl clk start clkout rstall ariend inst3 B[7..0] INPUT VCC A[7..0] INPUT VCC sreg8b andarith qb clk load din[7..0] dout[7..0] abin din[7..0] inst6 inst2 adder8b cin a[7..0] b[7..0] inst1 s[7..0] cout q[15..0] OUTPUT dout[15..0] reg16b clk clr d[8..0] inst5 OUTPUT dout5[15..0] ----四位二进制并行加法器 五.程序清单 1.library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity add4b is port( cin:in std_logic; a,b:in std_logic_vector(3 downto 0); s:out std_logic_vector(3 downto 0); cout:out std_logic); end; architecture one of add4b is signal sint,aa,bb:std_logic_vector(4 downto 0); begin aa<='0' & a; bb<='0' & b; sint<=aa+bb+cin; s<=sint(3 downto 0); cout<=sint(4); end; 2.library ieee; 制加法器; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity adder8b is port( cin:in std_logic; a,b:in std_logic_vector(7 downto 0); s:out std_logic_vector(7 downto 0); cout:out std_logic); end; architecture one of adder8b is component add4b 明 port( cin:in std_logic; --由两个四位二进制并行加法器级联而成的八位二进 --对要调用的元件add4b 的端口进行说
a,b:in std_logic_vector(3 downto 0); s:out std_logic_vector(3 downto 0); cout:out std_logic); end component; signal carryout: std_logic; begin u1:add4b port map(cin,a(3 downto 0),b(3 downto 0),s(3 downto u2:add4b port map(carryout,a(7 downto 4),b(7 downto 4),s(7 downto 0),carryout); 4),cout); end; --一位乘法器; 3.library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity andarith is port( abin:in std_logic; din:in std_logic_vector(7 downto 0); dout:out std_logic_vector(7 downto 0)); end; architecture one of andarith is begin process(abin,din) begin for i in 0 to 7 loop dout(i)<=din(i) and abin; end loop; end process; end; --乘法运算控制器 4.library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity arictl is port( clk,start:in std_logic; clkout,rstall,ariend:out std_logic); end; architecture one of arictl is signal cnt4b:std_logic_vector(3 downto 0); begin rstall<=start; process(clk,start) begin if start='1' then cnt4b<="0000";
elsif clk'event and clk='1' then if cnt4b<8 then --小于 8 则计数,等于 8 则表明乘法运算已经结 束 cnt4b<=cnt4b+1; end if; end if; end process; process(clk,cnt4b,start) begin if start='0' then if cnt4b<8 then clkout<=clk; ariend<='0'; else clkout<='0'; ariend<='1'; end if; else clkout<=clk; ariend<='0'; end if; end process; end; --16 位锁存器 5.library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity reg16b is port( clk,clr:in std_logic; d:in std_logic_vector(8 downto 0); q:out std_logic_vector(15 downto 0)); end; architecture one of reg16b is signal r16s:std_logic_vector(15 downto 0); begin process(clk,clr) begin if clr='1' then r16s<="0000000000000000"; elsif clk'event and clk='1' then r16s(6 downto 0)<=r16s(7 downto 1); r16s(15 downto 7)<=d; end if; end process; q<=r16s; end; 6.library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; --8 位右移寄存器
entity sreg8b is port( clk,load:in std_logic; din:in std_logic_vector(7 downto 0); qb:out std_logic); end; architecture one of sreg8b is signal reg8:std_logic_vector(7 downto 0); begin process(clk,load) begin if clk'event and clk='1' then if load='1' then reg8<=din; else reg8(6 downto 0)<=reg8(7 downto 1); end if; end if; end process; qb<=reg8(0); end; 7.library ieee;--8 位乘法器顶层设计 use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity mult8x8 is port( clk:in std_logic; start:in std_logic; a,b:in std_logic_vector(7 downto 0); dout:out std_logic_vector(15 downto 0); ariend:out std_logic); end; architecture struc of mult8x8 is component adder8b is port( cin:in std_logic; a,b:in std_logic_vector(7 downto 0); s:out std_logic_vector(7 downto 0); cout:out std_logic); end component; component andarith is port( abin:in std_logic; din:in std_logic_vector(7 downto 0); dout:out std_logic_vector(7 downto 0)); end component; component arictl is port( clk,start:in std_logic; clkout,rstall,ariend:out std_logic);
d:in std_logic_vector(8 downto 0); q:out std_logic_vector(15 downto 0)); din:in std_logic_vector(7 downto 0); qb:out std_logic); :std_logic; :std_logic; :std_logic; end component; signal gndint signal intclk signal rstall signal qb :std_logic; signal andsd :std_logic_vector(7 downto 0); signal dtbin :std_logic_vector(8 downto 0); signal dtbout :std_logic_vector(15 downto 0); begin end component; component reg16b is port( clk,clr:in std_logic; end component; component sreg8b is port( clk,load:in std_logic; dout<=dtbout; gndint<='0'; u1:arictl port map( clk,start,intclk,rstall,ariend); u2:sreg8b port map(intclk,rstall,b,qb); u3:andarith port map(qb,a,andsd); u4:adder8b port map(gndint,dtbout(15 downto 8),andsd,dtbin(7 downto 0),dtbin(8)); u5:reg16b port map(intclk,rstall,dtbin,dtbout); end; 六.仿真结果图
以下是 8 位乘法器顶层设计的仿真波形图,其它各模块的仿真波形图省略。
分享到:
收藏