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 小时前
Zynq开发实践(FPGA之第一个vivado工程)
fpga开发
贝塔实验室5 小时前
两种常用的抗单粒子翻转动态刷新方法
论文阅读·经验分享·笔记·科技·学习·程序人生·fpga开发
minglie114 小时前
zynq arm全局计时器和私有定时器
fpga开发
章咸鱼1213820 小时前
nios simple soket tcp在面对arp洪流时崩溃的处理
fpga开发·tcp
望获linux21 小时前
望获实时Linux:亚微秒级时间控制
linux·运维·服务器·计算机·fpga开发·嵌入式软件·飞腾
嵌入式-老费2 天前
Zynq开发实践(FPGA之spi实现)
fpga开发
太爱学习了2 天前
FPGA雷达信号处理之:自适应门限阈值
fpga开发·信号处理
国科安芯2 天前
前沿探索:RISC-V 架构 MCU 在航天级辐射环境下的可靠性测试
网络·单片机·嵌入式硬件·fpga开发·硬件架构·risc-v
范纹杉想快点毕业2 天前
请创建一个视觉精美、交互流畅的进阶版贪吃蛇游戏
数据库·嵌入式硬件·算法·mongodb·游戏·fpga开发·交互
第二层皮-合肥3 天前
FPGA硬件设计-基础流程
fpga开发