VHDL实现16位全加器
组成原理课程设计(16位全加器电路的设计与实现)

16位全加器电路的设计与实现学生姓名:杨传福指导老师:王新摘要本课程设计主要利用门电路完成一个16位的全加器电路的设计与实现。
本设计采用逐步求解的方法,即先设计一位全加器,再利用一位全加器设计出四位全加器,最后在四位全加器的基础上设计出16位全加器,并使用VHDL语言编写程序,在MAX-PLUSⅡ仿真平台上进行仿真。
仿真结果表明,本课程设计中设计出的16位全加器能正确完成16位二进制数的加法运算。
关键词全加器;门电路;先行进位Abstract:This curriculum design primarily use the gate circuit to complete a 16-bit full-adder circuit.The design solve this problem with step-by-step approach, namely start designing one full-adder, and then use one full-adder design a four full-adder , the last design the 16-bit full-adder based on the four full-adder,and use VHDL language programming, at MAX-PLUS Ⅱsimulation on simulation platform. The simulation results show that the design of the curriculum design of the 16-bit full-adder to add a 16-bit binary number addition operations.Keywords:Full-adder; Gate circuit; First binary1引言1.1课程设计的背景随着计算机科学技术的发展,人们获得信息的途径更加多样,获取信息的速度更加快捷。
VHDL作业

第5章FPGA课件作业姓名:金大哥专业:电气信息年级:2011级学号:XXXXXXXXXXXXXXX3-11 给出含有异步清零和计数使能的16位二进制加减可控计数器的VHDL描述。
解:LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY ADD_SUB_LOAD_16 ISPORT (CLK,RST,ADD_EN,SUB_EN,LOAD : IN STD_LOGIC; DATA : IN STD_LOGIC_VECTOR(15 DOWNTO 0); CQ : OUT STD_LOGIC_VECTOR(15 DOWNTO 0); COUT : OUT STD_LOGIC);END ENTITY ADD_SUB_LOAD_16;ARCHITECTURE A_S_16 OF ADD_SUB_LOAD_16 ISBEGINPROCESS(CLK,RST,ADD_EN,SUB_EN,LOAD)VARIABLE CQI: STD_LOGIC_VECTOR(15 DOWNTO 0); --VARIABLE LS_LOAD : STD_LOGIC;BEGIN--LS_LOAD:=LOAD;IF RST = '1' THEN CQI:=(OTHERS => '0');ELSIF LOAD = '1' THEN CQI:=DATA; --LS_LOAD:='0';ELSIF CLK'EVENT AND CLK='1' THENIF ADD_EN='1'THENIF CQI<16#FFFF# THEN CQI:=CQI+1;ELSE CQI:=(OTHERS => '0');END IF;IF CQI=16#FFFF# THEN COUT<='1';ELSE COUT <= '0';END IF;END IF;IF SUB_EN='1'THENIF CQI>0 THEN CQI:=CQI-1;ELSE CQI:=(OTHERS => '1');END IF;IF CQI=0 THEN COUT<='1';ELSE COUT <= '0';END IF;END IF;END IF;CQ<=CQI;END PROCESS;END ARCHITECTURE A_S_16;1.VHDL程序一般包含几个组成部分?各部分的作用是什么?解:实体:用于描述所述设计的系统外部接口信号;结构体:用于描述内部功能和结构;配置:用于从库中选取所需但原来组成系统设计的不同版本;程序包:存放各设计模块所能共享的数据类型,模块和子程序等;库:存放已经编译的实体,结构体,程序包和配置。
EDA-16位加法计数器的设计

EDA-16位加法计数器的设计北京理工大学用程序输入方法设计一个16位二进制加法计数器学院:机械xxxx学院专业班级:10机械电子工程x班姓名:陈xx学号: 10xxxxxx指导教师:xxx 老师目录摘要 (1)1 绪论 (2)2 计数器的工作原理 (3)3 设计原理 (4)4 电路系统的功能仿真 (4)6 个人小结 (23)参考文献 (24)摘要计数器是数字系统中使用较多的一种时序逻辑器件。
计数器的基本功能是统计时钟脉冲的个数,即对脉冲实现计数操作。
计数器也可以作为分频、定时、脉冲节拍产生器和脉冲序列产生器使用。
计数器的种类很多,按构成计数器中的各触发器是否使用一个时钟脉冲源来分,可分为同步计数器和异步计数器;按进位体制的不同,可分为二进制计数器、十进制计数器和任意进制计数器;按计数过程中数字增减趋势的不同,可分为加法计数器、减法计数器和可逆计数器;还有可预制数和可编计数器等等。
本次课程设计将利用众多集成电路软件软件中的Quartus II软件,使用VHDL语言编程完成论文《用程序输入方法设计一个16位二进制加法计数器》,调试结果表明,所设计的计数器正确实现了计数功能。
关键词:二进制;加法计数器;VHDL语言1 绪论现代电子设计技术的核心已日趋转向基于计算机的电子设计自动化,即EDA(Electronic Design Automation)技术。
EDA技术就是依赖功能强大的计算机,在集成电路软件平台上,对以硬件描述语言HDL(Hardware Description Language)为系统逻辑描述手段完成的设计文件,自动完成逻辑编译、化简、分割、综合、布局布线以及逻辑优化和仿真测试,直至实现既定的电子线路系统功能。
现在对EDA的概念或范畴用得很宽。
包括在机械、电子、通信、航空航天、化工、矿产、生物、医学、军事等各个领域,都有EDA的应用。
目前EDA技术已在各大公司、企事业单位和科研教学部门广泛使用。
16位vhdl乘法器详解,加仿真图

控制模块:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity cont_modu isport(Clk : in std_logic ;Start : in std_logic; //数据输入开始信号en_sig : out std_logic; //控制运算信号,为‘1’运算数据out_sig : out std_logic // 运算完成信号);end entity;architecture rlt_cont_modu of cont_modu issignal cnt :integer range 0 to 15 :=0;//定义从0到15type state is(S_idle,S_work,S_1d,S_2d);//运算状态信号,状态机signal st_ty : state :=S_idle;beginprocess(Clk)beginif rising_edge(Clk) thencase st_ty is 选择语句;S_idle为空闲状态,当输入数据后Start信号为1就开始工作when S_idle => if Start ='1' then 如果为1就跳转到S_work状态,并且使能信号置1st_ty <= S_work;en_sig <='1';else 不然继续在S_idle状态st_ty <= S_idle;en_sig <='0';end if;out_sig <='0';when S_work => if cnt =15 then 在S_work状态下,cnt信号一直加1,加满16个数就跳转到S_1d,然后使能信号en_sig 就为0。
quartusII设计16位加法器

Exercise 1aObjectives:∙Build a 16-bit adder using the ‘+’ operator∙Practice coding ENTITY-ARCHITECTURE structure ∙See the effect of libraries references on compilationStep 1: Unzip the exercise files and open a Quartus II project____ 1.Unzip the lab project files, if necessary. In an Windows Explorer window, go to the directory C:\altera_trn\VHDL. (If you see a subfolder already there namedIntroduction_to_VHDL_91, please delete.) Double-click the executable filenamed Introduction_to_VHDL_9_1_v1.exe found in the C:\altera_trn\VHDLdirectory. If you still cannot find this directory or file, ask your instructor forassistance. After double-clicking, in the WinZip dialog box, simply click Unzipto automatically extract the files into a newly created folder namedIntroduction_to_VHDL_91. Close WinZip.____ 2.Start the Quartus II software. In the Windows Start menu from the All Programs list, go to the Altera folder and then the Quartus II 9.1 folder. ClickQuartus II 9.1 (32-Bit) to start the program. There may also be a shortcut onthe desktop.If using another operating system, please ask the instructor how to open theQuartus II software if you are unsure.____ 3.Open the adder project. From the Quartus II File menu, choose Open Project.Browse to the directory C:\altera_trn\VHDL\Introduction_to_VHDL_91\lab1aand select the file adder.qpf.The project opens and you are ready to start coding your adder block.Step 2: Write the code for a 16-bit adder____ 1.Create a VHDL file using the Quartus II text editor. From the Quartus II Filemenu select New or click on the button. The New File dialog box willappear; select VHDL File. Click OK.____ 2.Write the source code for a 16-bit adder using the ‘+’ operator. Use the following information as a guide:e the names in the diagram above to name your block and its ports (alllower-case)b.All inputs and outputs should be declared as standard logic.c.Do not worry about rollover with this adder. This adder is already wideenough to account for all the values it will be adding together.d.Make sure to include the library and package declarations at the beginningof the file. You will need the STD_LOGIC_1164 andSTD_LOGIC_UNSIGNED packages.e.If you would prefer using a different text editor, please feel free to do so.Just make sure you save your VHDL file in the project directory.____ 3.Save the file as adder.vhd. From the Quartus II File menu, select Save and save your VHDL file as adder.vhd. It should be located in theC:\altera_trn\VHDL\Introduction_to_VHDL_91\lab1a directory.Step 3: Synthesize the design & check the code for correctness____ 1.Synthesize the design. From the Quartus II Processing menu, select Start ⇒Start Analysis & Synthesis OR click on the button.This will perform checks on the source code to make sure it using valid VHDLsyntax as well as check the design for being synthesizable.____ 2.Correct any warnings and errors. Check the Messages window of the Quartus II software for any warning or error messages. Correct as needed. Be awarethat most error messages point to the line number that is causing the error. Youmay also right-click on the message itself and choose Help to access the onlinehelp within the Quartus II software for clues on how to fix your warning or error.Of course, ask your instructor if you are unsure how to fix a particular warning ormessage. Repeat synthesis and error checking until the Quartus II softwarereports that the “Analysis & Synthesis was successful.”Step 4: Check operator overloading____ ment out the second USE clause. In your adder.vhd file, use the VHDL comment character to comment out the second of the two USE clauses (the oneenabling the use of the STD_LOGIC_UNSIGNED package) at the beginning ofthe file. You should comment out only 1 line.____ 2.Synthesize the design. From the Processing menu, select Start ⇒ StartAnalysis & Synthesis again OR click on the button.What error messages did you receive? You should see the messages below.The reason for the error message is operator overloading. The VHDL compilerdoes not understand the arithmetic operation for STD_LOGIC_VECTOR datatypes. The STD_LOGIC_UNSIGNED package contains the function definitionthat describes this arithmetic operation when used on STD_LOGIC_VECTORdata types. Therefore, the library that contains this package and the packageitself need to be referenced in the design file.____ 3.Restore (uncomment) the USE clause in adder.vhd and save.Step 5: Perform an RTL simulationYou will now use the ModelSim-Altera Starter Edition simulation tool (or similar) to verify the functionality of your design. A VHDL testbench file (adder_tb.vhd)has already been created for you to provide the test vectors for your RTLsimulation.____ 1.Open the ModelSim-Altera simulation tool. In the Windows Start menu from the All Programs list, go to the Altera folder and then the ModelSim-Altera6.5b (Quartus II 9.1) Starter Edition folder. Click ModelSim-Altera 6.5b(Quartus II 9.1) Starter Edition to start the program. There may also be ashortcut on the desktop.If using another simulation tool, see your instructor for steps on how to open andexecute that tool.____ 2.Close the introductory window (if it appears).____ 3.Set the project directory. From the ModelSim File menu, select Change Directory. Browse to the locationC:\altera_trn\VHDL\Introduction_to_VHDL_91\lab1a.A ModelSim macro file called a .DO file has been created for you. This filenamed adder_tb.do contains all of the stepts to run the ModelSim tool and peformsimulation. This includes:a.Creating a working library using the vlib commandpiling all of the VHDL files into the working library with the vcomcommand.c.Loading the simulator with the top-level testbench file using the vsimcommand.d.Opening the waveform window with the wave command.e.Adding target signals to the wave window (and formatting them) using theadd wave command.f.Advancing simulation using the run command.You may open the adder_tb.do file in a text editor if you wish to view the specificcommands used.____ 4.Execute the macro file. From the ModelSim Tools menu, select Tcl ⇒ Execute Macro. Select the file adder_tb.do and click Open.The ModelSim tool will now compile all of the VHDL files and start simulation.The waveform window will open (as a separate window) with the dataa, datab andsum signals added so you can verify that your vhdl code is functioning correctly. ____ 5.Check simulation results for correct functionality. Bring the Wave window to the foreground. From the View menu, click Zoom ⇒ Zoom Full. Your resultsshould look similar to the image below.If your simulation does not match the above, edit your VHDL code as needed andthen save it. Re-run the adder_tb.do file (repeat #’s 4 and 5 above) to check your changes.____ 6.End your simulation. From the ModelSim Simulate menu, select End Simulation OR type quit –sim in the ModelSim Transcript window.Exercise Summary∙Coded a 16-bit adder block in VHDL using the STD_LOGIC data type and an overloaded ‘+’ operator∙Simulated the VHDL code in the ModelSim tool to verify correct functionality。
VHDL-16

采用std_logic类型端口的8 采用std_logic类型端口的8位加法器 std_logic类型端口的
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; entity vadd is port (a,b: in std_logic_vector( 7 downto 0 ); c : in std_logic; s : out std_logic_vector(8 downto 0)); end vadd;
ห้องสมุดไป่ตู้
组合运算模块的设计特点
VHDL的算术运算可以采用不同方式进行: VHDL的算术运算可以采用不同方式进行: 的算术运算可以采用不同方式进行 利用算术量和算术运算进行行为描述. 利用算术量和算术运算进行行为描述. 利用signed和unsigned类型直接进行二 利用signed和unsigned类型直接进行二 signed 进制加减运算(对应于加法器); 进制加减运算(对应于加法器); 直接设计加法的基本逻辑单元,再通过 直接设计加法的基本逻辑单元, 结构设计方式形成加法器和乘法器等功能单 元.
各种运算结果的类型 entity vadd is port (a,b: in unsigned( 7 downto 0 ); c : in signed ( 7 downto 0 ); d : in std_logic_vector( 7 downto 0 ); s : out unsigned (8 downto 0); t : out signed (8 downto 0); u : out signed (7 downto 0); v : out std_logic_vector(8 downto 0)); end vadd;
VHDL加法器设计1

VHDL 加法器设计设计要求:采用QuartusII 集成开发环境利用VHDL 硬件描述语言设计传播进位加法器,直接进位加法器,线形进位加法器,平方根进位加法器,并比较这四种加法器的性能。
为了便于比较性能,将四种加法器都设定为28位。
一、全加器设计全加器是上述四种加法器的基础部件,首先应当设计一位全加器。
设计原理:i i i iS ABC ABC ABC ABC A B C=+++=⊕⊕0i i C AB BC AC =++VHDL 程序:仿真结果:--一位全加器设计library ieee;use ieee.std_logic_1164.all; entity fulladd isport ( A: in std_logic;B: in std_logic; cin:in std_logic; sumbit:out std_logic; cout:out std_logic );end fulladd;architecture behav of fulladd is beginsumbit<=(A xor B) xor cin;cout<=(a and b) or (cin and a) or (cin and b); end behav;二、传播进位加法器设计实际上加法器就是是全加器的级联,其中的每个FA网络为一个全加器(采用上文所述的全加器)VHDL代码:--传播进位加法器library ieee;use ieee.std_logic_1164.all;use work.all;entity carry_propogate_adder isport (A: in std_logic_vector(27 downto 0);B: in std_logic_vector(27 downto 0);cin:in std_logic;sum:out std_logic_vector(27 downto 0);cout:out std_logic);end carry_propogate_adder;architecture behav of carry_propogate_adder issignal ct:std_logic_vector(28 downto 0);component fulladd isport (A: in std_logic;B: in std_logic;cin:in std_logic;sumbit:out std_logic;cout:out std_logic);end component;beginct(0)<=cin;cout<=ct(28);G1: for i in 0 to 27 generatel1:fulladd port map (A(i),B(i),ct(i),sum(i),ct(i+1));end generate G1;end behav;功能仿真:延时测定:由图中的两个时间bar 的差值可看出,sum 值和cout 值几乎同时计算出,其Tdelay=28.332ns (cin 无关)三、直接进位加法器设计 设计原理:首先将AB 输入转换为PG 输入,若每级的P 输入都是‘1’则直接将Ci 传给Co ,否则像传播进位加法器一样计算其AB-PG 转换网络原理:Fa 全加器原理:P A B G AB=⊕=o i iC G PC S P C =+=⊕VHDL 代码:-- FA 子单元 library ieee;use ieee.std_logic_1164.all;entity Fa isport (Pi,Gi,Ci:in std_logic; Coi,Si:out std_logic); end Fa;architecture Fabehav of Fa is beginCoi<=Gi or (Pi and Ci);Si<=Pi xor Ci; end Fabehav; --ABtoPG 转换网络 library ieee;use ieee.std_logic_1164.all;entity PGNet isport(Ai,Bi:in std_logic; Pi,Gi:out std_logic); end PGNet;architecture PGbehav of PGNet is beginPi<=Ai xor Bi;Gi<=Ai and Bi; end PGbehav; --传播进位加法器 library ieee;use ieee.std_logic_1164.all; entity bypass_adder is port(A,B:in std_logic_vector(27 downto 0); Ci:in std_logic; Sum:out std_logic_vector(27 downto 0); Co:out std_logic );end bypass_adder;architecture adderbehav of bypass_adder is component Fa is port (Pi,Gi,Ci:in std_logic; Coi,Si:out std_logic ); end component; component PGNet is port(Ai,Bi:in std_logic; Pi,Gi:out std_logic ); end component;signal P,G:std_logic_vector(27 downto 0); signal C:std_logic_vector(28 downto 0); signal BP:std_logic; begin C(0)<=Ci; G1: for i in 0 to 27 generate l1: PGNet port map(A(i),B(i),P(i),G(i)); end generate G1; G2: for i in 0 to 27 generate l2:Fa port map (P(i),G(i),C(i),C(i+1),Sum(i)); end generate G2; BP<='1' when P="11111111111111111111111111111111" else '0'; Co<=Ci when BP='1' else C(8); end adderbehav;功能仿真:延时仿真:当通过直接进位网络(图中testp值全部为1时),进位信号有一定提前,但由于计算所有的P值本身也需要一定时间,所以改善并不明显。
基于VHDL的16位CPU设计

基于VHDL的16位CPU设计一.设计要求:①完成一个16位CPU的顶层系统设计;完成其指令系统的规划。
②完成所有模块的VHDL设计。
③采用QuartusII完成所有模块及顶层的仿真。
④采用DE2 FPGA系统完成整体CPU系统的验证。
二.CPU的概念CPU 即中央处理单元的英文缩写,它是计算机的核心部件。
计算机进行信息处理可分为两个步骤:1) 将数据和程序(即指令序列)输入到计算机的存储器中。
2) 从第一条指令的地址起开始执行该程序,得到所需结果,结束运行。
CPU 的作用是协调并控制计算机的各个部件执行程序的指令序列,使其有条不紊地进行。
因此它必须具有以下基本功能:a)取指令:当程序已在存储器中时,首先根据程序入口地址取出一条程序,为此要发出指令地址及控制信号。
b)分析指令:即指令译码。
是对当前取得的指令进行分析,指出它要求什么操作,并产生相应的操作控制命令。
c)执行指令:根据分析指令时产生的“操作命令”形成相应的操作控制信号序列,通过运算器,存储器及输入/输出设备的执行,实现每条指令的功能,其中包括对运算结果的处理以及下条指令地址的形成。
三.16位CPU结构框图16位cpu结构由8个16 位的寄存器 reg0~ reg7、一个运算器 ALU、一个移位寄存Shifter、一个程序计数器 PortCnt、一个指令寄存器 InstrReg、一个工作寄存器OpReg,一个比较器 Comp、一个地址寄存器 Addreg、和一个控制单元 Control组成。
这些模块共用一组 16 位的三台数据总线。
系统采用自顶向下的方法进行设计。
顶层设计由微处理器和存储器通过一组双向数据总线连接,它们由一组地址总线和一些控制总线组成。
处理器从外存储器中读取指令,并通过执行这些指令来运行程序。
这些指令存储在指令寄存器中,并由控制单元译码。
控制单元使得相应的信号互相作用,并使处理单元执行这些指令。
四.各模块的设计分析和设计思路4.1 算术逻辑单元ALUa[15..0] b[15..0] sel[3..0]c[15..0]aluinst算术逻辑运算单元根据输入不同操作码分别实现相应的加、与、异或、跳转等基本操作运算。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
[键入公司名称][键入文档标题][键入文档副标题]姓名:托列吾别克•马杰尼班级:电路与系统01班学号:201221020141[键入公司名称]2013/11/24基于VHDL的16位全加器的设计1.1设计题目的内容及要求i.i.i 目的:CMOS数字集成电路设计流程及数字集成电路自动化设计,包括功能验证、VHDL/Verlog建模、同步电路设计、异步数据获取、能耗与散热、信号完整性、物理设计、设计验证等技术1.1.2内容:主要实验内容是用0.18阿数字CMOS工艺,VHDL或Verlog设计-个16位全加器,用Synthesis仿真工具验证功能,电路合成,及性能检测。
1.1.3主要测试参数及指标范围:16位的全加器主要的设计指标是高于1GHz的频率,功耗,物理面积大小等参数。
1.2全加器的组成和原理分析全加器是常用的组合逻辑模块中的一种,对全加器的分析和对组合逻辑电路的分析一样。
组合逻辑电路的分析,就是找出给定电路输入和输出之间的逻辑关系,从而了解给定逻辑电路的逻辑功能。
组合逻辑电路的分析方法通常采用代数法,一般按下列步骤进行:(1)根据所需要的功能,列出真值表。
(2)根据真值表,写出相应的逻辑函数表达式。
(3)根据真值表或逻辑函数表达式,画出相应的组合逻辑电路的逻辑图(4)用VHDL编写程序在QUARTUS U上进行模拟,并分析结果的正确性。
1.3全加器简介全加器是组合逻辑电路中最常见也最实用的一种,考虑低位进位的加法运算就是全加运算,实现全加运算的电路称为全加器。
它主要实现加法的运算,其中分为并行全加器和串行全加器,所谓并行就是指向高位进位时是并行执行的,而串行就是从低位到高位按顺序执行,为了提高运算,必须设法减小或消除由于进位信号逐级传递所消耗的时间,为了提高运算速度,制成了超前进位加法器,这是对全加器的一种创新[2]。
1.3.1半加器的基本原理如果不考虑有来自低位的进位将两个1位二进制数相加,称为半加。
实现半加运算的电路称为半加器。
按照二进制加法运算规则可以列出如表2所示的半加器真值表,其中A、B 是两个加数,S是相加的和,CO是向咼位的进位。
将S、CO和A、B的关系写成逻辑表达式则得到S=A B+A B=A+BCO=AB因此,半加器是由一个异或门和一个与门组成的,如图1所示。
图1半加器原理图1.3.2 一位全加器的原理全加器执行加数,被减数和低位来的进位信号相加,并根据求和结果给出该进位信号。
(1)根据全加器所需要的功能,我们可以设计出一位全加器的组合逻辑框图。
如图2所示。
G HXi柠G图2一位全加器的逻辑图(2根据逻辑图我们可以写出各个器件的逻辑功能。
C i = X i 丫i C i-i +X i 丫i C i-i +X i 丫i C i-i +X i 丫i C i-i = (X i ①丫i)C i-i +X i 丫iF i = XY C / + X i YC M +XY C / + XY C / = X i®Y i®C M(3)由上面可得。
X i和Y i为两个输入的一位二进制书,C i-i为低位二进制数相加的进位输出到本位的输入,则F i为本位二进制数X i、Y i和低位进位输入C i-i的相加之和,C i为X i、Y i和低位进位输入C M相加向高位的进位输出。
因此,该电路可以完成一位二进制数全加的功能,称为全加器。
此电路的真值表如表2所示。
表2 一位全加器真值表1.4十六位全加器的设计设计16位的全加器思路非常简单且清晰,第一种方法就是先设计一个半加器和一个或门,然后两个半加器合并成一个一位的全加器,最后用16个一位的全加器组合成为一个16位的全加器;第二种方法就是先设计一个一位的全加器, 然后在用16个串联或并联就组成了一个16位的全加器,而本次设计采用采用的是第一种方法。
十六位全加器有十六个一位全加器的级联组成的,最低位的借位信号时整个全加器的借位信号Ci n,最高位的进位信号是十六位全加器的进位信号,每位之间通过进位信号链接,两个十六位加数的每一位并联输入,和数SUM的每-位并联输出,完成两个十六位的数的加法。
1.5用VHDL编写代码实现16位全加器本次实验使用Altera FPGA/CPLD 的开发工具Quartus U,利用编写VHDL代码设计方法设计一个16位加法器,并用Quartus的综合仿真工具实现电路的综合,电路功能的验证,并最后查看综合后的RLT电路框图来验证设计与原逻辑设计符不符合要求,我们还可以借用powerplay功率分析工具对设计后的电路进行功耗分析。
本次设计有一个顶层模块(16位全加器)和三个底层模块,它们分别为一位全加器和组成一位全加器的半加器模块和或门模块。
因此我们要用从底层到顶层的设计思路,以半加器+或门一一>一位全加器一一>16位全加器的为设计顺序。
以下为半加器和活门的VHDL程序代码(1)半加器的VHDL代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_ un sig ned.all;en tity h_adder isport(a,b:in std」o gic;co:out std_logic;so:out std_logic );end h_adder;architecture one of h_adder isbegi nso<=a xor b;co<=a and b;end one;(2) 或门的VHDL代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_ un sig ned.all;en tity or2a isport(a,b:in std」o gic;c:out std」o gic );end or2a;architecture one of or2a isbegi nc<=a or b;end one;由全加器的逻辑图可以看出,全加器由两个半加器和一个或门组成。
在VHDL语言中我们可以在一个模块的代码中用component语句调用低层的模块这样可以避免写更多的繁琐的代码,也可以提高程序的可读性,也有利于实际电路在延时等关键技术性问题上的优越性。
(3) —位全加器的VHDL代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_ un sig ned.all;en tity f_adder isport(ai n:in std」o gic;bin:in std_logic;cin:in std_logic;coutf:out std」o gic;sumf:out std_logic );end f_adder;architecture one of f adder iscomp onent h_adderport(a:in std」ogic;b:in std」o gic);end comp onent;comp onent or2aport(a:in std _lo gic;b:in std_logic);end comp onent;sig nal d,e,f:std」o gic;begi nu1:h_adder port map(a=>a in, b=>b in, co=>d,so=>e);u2:h_adder port map(a=>e,b=>c in, co=>f,so=>sumf);u3:or2a port map(a=>d,b=>f,c=>coutf);end one;从上述的设计思路中和全加器的级联设计方案中看到,实现16位全加器的关键是实现每级全加器到下一级全加器的信号的控制,以此实现模块之间的协调和整个系统的稳定性。
在实现16加法器中我们同样用上述的comp on e nt语句, 在顶层中调用底层的模块,并巧妙地实现每个模块之间的级联。
以下为一种设(4) 16位加法器的VHDL代码library ieee;use ieee.std_logic_ un sig ned.all;en tity n ew_adder16 isport(a:in std」ogic_vector(15 downto 0);b:in std_logic_vector(15 downto 0);cin:in std_logic;sum:out std_logic_vector(15 downto 0););end;architecture one of n ew_adder16 is comp onent f_adderport(ain:in std」ogic;bin:in std_logic;cin:in std_logic coutf:out std」o gic;sumf:out std_logic );end comp onent;sig nal temp:std_logic_vector(16 dow nto 0);beg intemp(0)<=ci n;add:for i in 0 to 15 gen erate loopadd:f_adder port map(a in=>a(i).bin=>b(i).cin=>temp(i).coutf=>temp(i+1).sumf=>sum(i));end gen erate add;cout<=temp(16);end one;上述代码中用for…gen erate循环语句和compo ne nt语句的调用语句实现15 位信号的加法。
因为for…generate不像for….loop那样顺序执行而是并行执行的,使用了for...loop,所以对应RTL Viewer就比较复杂,所以for…gen erate语句更有效。
2.1用QuartusII实现16位全加器电路的综合仿真1) 以new_adder16为工程名新建一个工程,我们可以预先设置硬件的选择,本次设计用MAX系列芯片。
2) 新建四个VHDL文件,分别编写进上四个模块的VHDL代码。
顶层模块的文件名要工程名一致,在此为n ew_adder16.vhd其余的文件名跟模块名要一致,以便于以后的综合和验证过程的调试。
3) 实现编译和综合,若无误则可以仿真了,综合后Quartus软件给出设计中所用到的逻辑单元,弓I脚等信息,如图4所示。