认识全加器
半加器
半加器是能够对两个一位的二进制数进行相加得到半加和以及半加进位的组合电路
半加器的输出表达式为S=A⊕B,C=AB,逻辑电路图如下
![](https://img-blog.csdnimg.cn/img_convert/4cd6baaf2704d2c733166658d1c398e3.png)
一位全加器
全加器的真值表如下,其中Ain表示被加数,Bin表示加数,Cin表示低位进位,Cout表示高位进位,Sum表示本位和
![](https://img-blog.csdnimg.cn/img_convert/4c6262b804cfe1769349ee03c4278461.png)
即输出表达式为
Sum=Ain⊕Bin⊕Cin
Cout=(Ain⊕Bin)⋅Cin+Ain·Bin=(Ain&Bin)∣(Bin&Cin)∣(Ain&Cin)
![](https://img-blog.csdnimg.cn/img_convert/9ce428a2b25676158cb46dedb7cfe19d.png)
输出原理图实现一位加法器
首先启动quartus软件,选择file,找到new project wizard
![](https://img-blog.csdnimg.cn/img_convert/7f320297aaaf0a33ba4929036c79991b.png)
![](https://img-blog.csdnimg.cn/img_convert/3e1b936f64d5675f3d379896387addc5.png)
![](https://img-blog.csdnimg.cn/img_convert/828543083f1211af9d5c1574f5e42d2f.png)
半加器原理图输入
首先选择file,选择new,进入选择Block Diagram/Schematic File
![](https://img-blog.csdnimg.cn/img_convert/e23dc0ecd45a34e31c9b4a08c6960eeb.png)
![](https://img-blog.csdnimg.cn/img_convert/6410ad24630d53e1ed45cd8a558aaf68.png)
选择元件,添加一个and2,一个xor,两个input,两个output,组成如下图的电路
![](https://img-blog.csdnimg.cn/img_convert/36e0508395d2b83775b123d20b0edc36.png)
保存文件,编译
![](https://img-blog.csdnimg.cn/img_convert/4ad86ed4140dd8dd9fe9134bfb58e975.png)
通过Tools->Netlist Viewers->RTL Viewer查看电路图
![](https://img-blog.csdnimg.cn/img_convert/6344abd2173372f0e1cff92b91169ad6.png)
得到如图。
![](https://img-blog.csdnimg.cn/img_convert/b9a578f62c87608d20f723d5fbc73663.png)
创建一个向量波形文件,选择菜单项File->New->University Program VWF
然后按照如下图所示操作
![](https://img-blog.csdnimg.cn/img_convert/338ad9fb7dc886be271ef385e207e313.png)
![](https://img-blog.csdnimg.cn/img_convert/61d95fafc2d748788164adec3222c2c4.png)
![](https://img-blog.csdnimg.cn/img_convert/4e16046dc74ef28dc1cccb100d945ce0.png)
![](https://img-blog.csdnimg.cn/img_convert/026fcfbe31be474dbaed87f753308318.png)
编辑并保存
![](https://img-blog.csdnimg.cn/img_convert/7bfe41006b0bb9f0926ffb697bd422e2.png)
功能仿真结果
![](https://img-blog.csdnimg.cn/img_convert/8d1214dabfe82d47f8ce53aec0409daa.png)
时序仿真结果
![](https://img-blog.csdnimg.cn/img_convert/3a91df5078a65a5b38ff17f8b07a86d2.png)
全加器原理图输入
将设计项目设置为可调用的元件
在打开半加器原理图文件half_adder.bdf的情况下,选择菜中File中的Create/Update→CreateSymbolFilesforCurrentFile项,即可将当前文件h_adder.bdf变成一个元件符号存盘,以待在高层次设计中调用。
![](https://img-blog.csdnimg.cn/img_convert/f98fcb0f528b204b11d7c33830ac813c.png)
接下来我们再绘制一个,还是老样子,选择file->new,选择Block Diagram/Schematic File
![](https://img-blog.csdnimg.cn/img_convert/fd39948caa4367448929621fb3025b08.png)
加入元件
![](https://img-blog.csdnimg.cn/img_convert/0d496a7c62971ecdc0837e5c9dd1061c.png)
名字出了点问题。
做成如图所示
![](https://img-blog.csdnimg.cn/img_convert/57c62921614db8c81e7f9d61bf8ddbe2.png)
这里先把这个文件置顶
![](https://img-blog.csdnimg.cn/img_convert/0fcfcc098af7092d26f276487705c10b.png)
这里是如上相同的方式,保存编译查看电路图,仿真实现
![](https://img-blog.csdnimg.cn/img_convert/77ee891992e2dbb9eb68b501eb3af974.png)
![](https://img-blog.csdnimg.cn/img_convert/7948d75e0e0403fca7f800014bbfe125.png)
功能仿真
![](https://img-blog.csdnimg.cn/img_convert/9b9e086fdf19eb7abb6af74757c39ad4.png)
时序仿真
![](https://img-blog.csdnimg.cn/img_convert/0b3ee5717b26af3b0ad9956d6c6fc3d7.png)
Verilog实现一位加法器创建
先创建Verilog文件
![](https://img-blog.csdnimg.cn/img_convert/5f90849ce841f4193726db4fbac2cbb8.png)
输入代码
module Verilog1(//这里的名字与自己的文件名相同
//输入信号,ain表示被加数,bin表示加数,cin表示低位向高位的进位
input ain,bin,cin,
//输出信号,cout表示向高位的进位,sum表示本位的相加和
output reg cout,sum
);
reg s1,s2,s3;
always @(ain or bin or cin) begin
sum=(ain^bin)^cin;//本位和输出表达式
s1=ain&cin;
s2=bin&cin;
s3=ain&bin;
cout=(s1|s2)|s3;//高位进位输出表达式
end
endmodule
![](https://img-blog.csdnimg.cn/img_convert/38a723388341734377bbe39b18d429ae.png)
成功
然后创建波形图文件
![](https://img-blog.csdnimg.cn/img_convert/76f2245d3613f486b7bcd44329a8d2a1.png)
编译运行
功能仿真
![](https://img-blog.csdnimg.cn/img_convert/0a5575345f177ba23ea97e38405f59f9.png)
时序仿真
![](https://img-blog.csdnimg.cn/img_convert/58c333d44825394b3175fc7e55dd7ec8.png)
下载测试
芯片引脚配置表
![](https://img-blog.csdnimg.cn/img_convert/00f1b057473dc62ad4c419fe2bc6130b.png)
找到quartus的pin planner
![](https://img-blog.csdnimg.cn/img_convert/8f4dae0e9d9287d68a2294ab28e619a3.png)
接下来电脑接入FPGA开发板。如果是原理图进行实现的话,绘制的原理图会出现以下变化,输入输出旁边会标注刚刚绑定的引脚编号。
![](https://img-blog.csdnimg.cn/img_convert/04edb99809754bdaedcbd66495468475.png)
然后如下图操作
![](https://img-blog.csdnimg.cn/img_convert/f5f50cdecbef1624d977757b49f44b4f.png)
选择好下图中的移动接口,没有这个接口要到在设备管理器中找到加感叹号的USB-blaster设备,并在一下路径下18.1/quatus/drivers/USB-blaster添加驱动。
![](https://img-blog.csdnimg.cn/img_convert/2fa10cbef8201d01e85006261eb0e827.png)
回到上一级菜单,选中以下2框选处,点击start开始烧录。若4处出现success表示烧录成功。
![](https://img-blog.csdnimg.cn/img_convert/2c292bbf3e42d55edabeefe79897ef87.png)
成功。