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相关源码:

相关推荐
千宇宙航5 小时前
闲庭信步使用图像验证平台加速FPGA的开发:第十四课——图像二值化的FPGA实现
图像处理·计算机视觉·fpga开发
千宇宙航8 小时前
闲庭信步使用图像验证平台加速FPGA的开发:第十五课——基于sobel算子边缘检测的FPGA实现
图像处理·计算机视觉·fpga开发
szxinmai主板定制专家11 小时前
基于光栅传感器+FPGA+ARM的测量控制解决方案
arm开发·人工智能·嵌入式硬件·fpga开发
千宇宙航1 天前
闲庭信步使用图像验证平台加速FPGA的开发:第十课——图像gamma矫正的FPGA实现
图像处理·计算机视觉·缓存·fpga开发
fei_sun1 天前
【FPGA】LUT如何实现组合逻辑、时序逻辑
fpga开发
小眼睛FPGA1 天前
【RK3568+PG2L50H开发板实验例程】FPGA部分 | 以太网传输实验例程
科技·单片机·嵌入式硬件·ai·fpga开发·fpga
千宇宙航1 天前
闲庭信步使用图像验证平台加速FPGA的开发:第十二课——图像增强的FPGA实现
图像处理·计算机视觉·fpga开发
hahaha60162 天前
通过Tcl脚本命令:set_param labtools.auto_update_hardware 0
fpga开发
霖002 天前
FPGA通信设计十问
运维·人工智能·经验分享·vscode·fpga开发·编辑器
悲喜自渡7213 天前
硬件加速(FPGA)
fpga开发