Verilog进行结构描述(三):Verilog模块实例化

目录

  • [1.模块实例化(module instantiation)](#1.模块实例化(module instantiation))
  • [2.实例数组(Array of Instances)](#2.实例数组(Array of Instances))

微信公众号获取更多FPGA相关源码:

1.模块实例化(module instantiation)

  • 模块实例化时实例必须有一个名字。
  • 使用位置映射时,端口次序与模块的说明相同。
  • 使用名称映射时,端口次序与位置无关
  • 没有连接的输入端口初始化值为x。
verilog 复制代码
module comp (o1, o2, i1, i2);
      output   o1, o2;
      input   i1, i2;
      . . .
endmodule

module test;
      comp c1 (Q, R, J, K); // Positional mapping
      comp c2 (.i2(K),   .o1(Q),  .o2(R),  .i1(J)); // Named mapping
      comp c3 (Q,   ,  J,  K);       // One port left unconnected
      comp c4 (.i1(J),  .o1(Q));   // Named, two unconnected ports
endmodule

2.实例数组(Array of Instances)

实例名字后有范围说明时会创建一个实例数组。在说明实例数组时,实例必须有一个名字 (包括基本单元实例)。其说明语法为:

复制代码
      <模块名字>  <实例名字>  <范围>  (<端口>);
verilog 复制代码
module driver (in, out, en);
      input [2: 0] in;
      output [2: 0] out;
      input en;
      bufif0  u[2:0]  (out, in, en);   // array of buffers
endmodule
verilog 复制代码
module driver_equiv (in, out, en);
      input [2: 0] in;
      output [2: 0] out;
      input en;
  // Each primitive instantiation is done separately
      bufif0 u2 (out[2], in[2], en);
      bufif0 u1 (out[1], in[1], en);
      bufif0 u0 (out[0], in[0], en);
endmodule
  • 如果范围中MSB与LSB相同,则只产生一个实例。
  • 一个实例名字只能有一个范围。
  • 下面以模块comp为例说明这些情况
verilog 复制代码
module oops;
      wire y1, a1, b1;
      wire [3: 0] a2, b2, y2, a3, b3, y3;

      comp u1  [5: 5] (y1, a1, b1); // 只产生一个comp实例
      comp m1 [0: 3] (y2, a2, b2);
      comp m1 [4: 7] (y3, a3, b3); //  非法
endmodule

微信公众号获取更多FPGA相关源码:

相关推荐
XINVRY-FPGA6 小时前
EPM240T100I5N Altera FPGA MAX II CPLD
人工智能·嵌入式硬件·fpga开发·硬件工程·dsp开发·射频工程·fpga
第二层皮-合肥11 小时前
FPGA实现ETH接口
单片机·嵌入式硬件·fpga开发
璞致电子14 小时前
【PZ-ZU47DR-KFB】璞致FPGA ZYNQ UltraScalePlus RFSOC QSPI Flash 固化常见问题说明
嵌入式硬件·fpga开发·fpga·软件无线电·sdr
陌夏微秋15 小时前
FPGA硬件设计2 最小芯片系统-ZYNQ7020/7010
嵌入式硬件·fpga开发·硬件架构·硬件工程·信息与通信·智能硬件
风已经起了1 天前
FPGA学习笔记——IIC协议简介
笔记·学习·fpga开发
逐梦之程2 天前
FPGA-Vivado2017.4-建立AXI4用于单片机与FPGA之间数据互通
fpga开发
XINVRY-FPGA2 天前
10CL016YF484C8G Altera FPGA Cyclone
嵌入式硬件·网络协议·fpga开发·云计算·硬件工程·信息与通信·fpga
嵌入式-老费2 天前
产品开发实践(常见的软硬结合方式)
fpga开发
FakeOccupational3 天前
【电路笔记 通信】AXI4-Lite协议 FPGA实现 & Valid-Ready Handshake 握手协议
笔记·fpga开发
I'm a winner3 天前
FPGA+护理:跨学科发展的探索(五)
fpga开发