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

相关推荐
9527华安7 小时前
FPGA实现40G网卡NIC,基于PCIE4C+40G/50G Ethernet subsystem架构,提供工程源码和技术支持
fpga开发·架构·网卡·ethernet·nic·40g·pcie4c
search79 小时前
写Verilog 的环境:逻辑综合、逻辑仿真
fpga开发
search715 小时前
Verilog 语法介绍 1-1结构
fpga开发
小眼睛FPGA19 小时前
【RK3568+PG2L50H开发板实验例程】Linux部分/FPGA dma_memcpy_demo 读写案例
linux·运维·科技·ai·fpga开发·gpu算力
幸运学者20 小时前
xilinx axi datamover IP使用demo
fpga开发
搬砖的小码农_Sky20 小时前
XILINX Zynq-7000系列FPGA的架构
fpga开发·架构
热爱学习地派大星1 天前
FPGA矩阵算法实现
fpga开发
热爱学习地派大星1 天前
Xilinx FPGA功耗评估
fpga开发·verilog·vivado·fpga功耗·xpe
搬砖的小码农_Sky2 天前
XILINX Ultrascale+ Kintex系列FPGA的架构
fpga开发·架构
XvnNing2 天前
【Verilog硬件语言学习笔记4】FPGA串口通信
笔记·学习·fpga开发