当前位置:   article > 正文

【基于FPGA的芯片设计】4位超前进位加法器

超前进位加法器

目录

实验原理

源代码

仿真代码

管脚配置


实验板卡:xc7a100tlc sg324-2L,共20个开关

实验原理

 

 

 

 

源代码

顶层模块

  1. `timescale 1ns / 1ps
  2. module Four_Bits_Lookahead_Adder(a,b,cin,S,C);
  3. input [3:0] a;
  4. input [3:0] b;
  5. input cin;
  6. output [3:0] S;
  7. output C;
  8. wire [4:1] c;
  9. wire drop;
  10. Lookahead uut(a,b,cin,c);
  11. assign C=c[4];
  12. Full_Adder u1(a[0],b[0],cin,S[0],drop);
  13. Full_Adder u2(a[1],b[1],c[1],S[1],drop);
  14. Full_Adder u3(a[2],b[2],c[2],S[2],drop);
  15. Full_Adder u4(a[3],b[3],c[3],S[3],drop);
  16. endmodule

超前进位模块

  1. `timescale 1ns / 1ps
  2. module Lookahead(a,b,cin,C);
  3. input [3:0] a;
  4. input [3:0] b;
  5. input cin;
  6. output [4:1] C;
  7. wire [3:0] G;
  8. wire [3:0] P;
  9. assign G[0]=a[0]&b[0];
  10. assign G[1]=a[1]&b[1];
  11. assign G[2]=a[2]&b[2];
  12. assign G[3]=a[3]&b[3];
  13. assign P[0]=a[0]|b[0];
  14. assign P[1]=a[1]|b[1];
  15. assign P[2]=a[2]|b[2];
  16. assign P[3]=a[3]|b[3];
  17. assign C[1]=G[0]|(P[0]&cin);
  18. assign C[2]=G[1]|(P[1]&G[0])|(P[1]&P[0]&cin);
  19. assign C[3]=G[2]|(P[2]&G[1])|(P[2]&P[1]&G[0])|(P[2]&P[1]&P[0]&cin);
  20. assign C[4]=G[3]|(P[3]&G[2])|(P[3]&P[2]&G[1])|(P[3]&P[2]&P[1]&G[0])|(P[3]&P[2]&P[1]&P[0]&cin);
  21. endmodule

全加器模块

  1. `timescale 1ns / 1ps
  2. module Full_Adder(a,b,cin,S,C);
  3. input a,b,cin;
  4. output S,C;
  5. wire S1,T1,T2,T3;
  6. xor
  7. X1(S1,a,b),
  8. X2(S,S1,cin);
  9. and
  10. A1(T3,a,b),
  11. A2(T2,b,cin),
  12. A3(T1,a,cin);
  13. or
  14. O1(C,T1,T2,T3);
  15. endmodule

仿真代码

  1. `timescale 1ns / 1ps
  2. module sim_Four_Lookahead_Adder();
  3. reg [3:0] a;
  4. reg [3:0] b;
  5. reg cin;
  6. wire [3:0] S;
  7. wire C;
  8. Four_Bits_Lookahead_Adder uut(
  9. a[3:0],
  10. b[3:0],
  11. cin,
  12. S[3:0],
  13. C
  14. );
  15. initial begin
  16. a[3:0]=0;
  17. b[3:0]=0;
  18. cin=0;
  19. end
  20. always
  21. #10
  22. {a[3],a[2],a[1],a[0],b[3],b[2],b[1],b[0],cin}={a[3],a[2],a[1],a[0],b[3],b[2],b[1],b[0],cin}+1;
  23. endmodule

管脚配置

注:vivado版本为2018版,板卡为xc7a100tlcsg324-2L

  1. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN V5} [get_ports a[3]]
  2. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN T4} [get_ports a[2]]
  3. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN V6} [get_ports a[1]]
  4. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN T5} [get_ports a[0]]
  5. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN T6} [get_ports b[3]]
  6. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN V7} [get_ports b[2]]
  7. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN R8} [get_ports b[1]]
  8. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN U9} [get_ports b[0]]
  9. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN T9} [get_ports cin]
  10. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN U6} [get_ports C]
  11. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN R5} [get_ports S[3]]
  12. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN U7} [get_ports S[2]]
  13. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN R6} [get_ports S[1]]
  14. set_property -dict {IOSTANDARD LVCMOS18 PACKAGE_PIN R7} [get_ports S[0]]

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号