数字系统设计Verilog第9章.pptVIP

  • 12
  • 0
  • 约 53页
  • 2017-09-23 发布于河南
  • 举报
(1)级连加法器 8×8并行乘法器的门级综合原理图 (2)移位相加乘法器 移位相加乘法器将乘法变为加法实现,其设计思路是:乘法通过逐次移位相加实现,每次判断乘数的最低位,若为1则将被乘数移位相加。 (3)加法树乘法器 【例9.7】 8位加法树乘法器 module add_tree(out,a,b,clk); input[7:0] a,b; input clk; output wire[15:0] out; wire[14:0] out1,c1; wire[12:0] out2; wire[10:0] out3,c2; wire[8:0] out4; reg[14:0] temp0; reg[13:0] temp1; reg[12:0] temp2; reg[11:0] temp3; reg[10:0] temp4; reg[9:0] temp5; reg[8:0] temp6; reg[7:0] temp7; function[7:0] mult8x1; //该函数实现8×1乘法 input[7:0] operand; input sel; begin mult8x1=(sel)?(operand):8 end endfunction always @(posedge clk) //调用函数实现操作数b各位与操作数a的相乘 begin temp7=mult8x1(a,b[0]);temp6=((mult8x1(a,b[1]))1); temp5=((mult8x1(a,b[2]))2);temp4=((mult8x1(a,b[3]))3); temp3=((mult8x1(a,b[4]))4);temp2=((mult8x1(a,b[5]))5); temp1=((mult8x1(a,b[6]))6);temp0=((mult8x1(a,b[7]))7); end assign out1=temp0+temp1; //加法树运算 assign out2=temp2+temp3;assign out3=temp4+temp5;assign out4=temp6+temp7; assign c1=out1+out2;assign c2=out3+out4;assign out=c1+c2; endmodule (4)查找表乘法器 查找表乘法器将乘积直接存放在存储器中,将操作数(乘数和被乘数)作为地址访问存储器,得到的输出数据就是乘法运算的结果。 查找表方式的乘法器速度只局限于所使用存储器的存取速度。但由于查找表规模随操作数位数增加而迅速增大,因此如用于实现位数宽的乘法操作,需要FPGA器件具有较大的片内存储器模块。比如,要实现8×8乘法,要求存储器的地址位宽为16位,字长为16位,即存储器大小为1M比特。 乘累加器的结构框图 乘累加器(MAC) module MAC(out,opa,opb,clk,clr); output[15:0] out;input[7:0] opa,opb; input clk,clr; wire[15:0] sum; reg[15:0] out; function[15:0] mult; //函数定义,mult函数完成乘法操作 input[7:0] opa,opb; reg [15:0] result; integer i; begin result=opa[0]? opb : 0; for(i=1; i=7; i=i+1) begin if(opa[i]==1) result=result+(opb(i-1));end mult=result; end endfunction? assign sum=mult(opa,opb)+out; always @(posedge clk or posedge clr) begin if(clr) out=0; else out=sum; end endmodule 9.4 奇数分频与小数分频 在实际中我们经常会遇到这样的问题,需要进行奇数次分频,同时又要得到占空比是50%的方波波形。 可采用如下方法:用两个计数器,一个由输入时钟上升沿触发,一个由输入时钟下降沿触发,最后将两个计数器的输出相或,即可得到占空比为50%的方波波形。 【例9.10】 占空比50%的奇数分频(模7) module count7(reset,clk,cout); input clk,reset; output wire cout; reg[2:0] m,n; reg cout1,cout2; assign cout=cout1|cout2; //两个计数器的输出相或 always @(posedge clk) begin if

文档评论(0)

1亿VIP精品文档

相关文档