Verilog-A 自定义函数与编译器指令
自定义函数(analog function)
analog function [type] function_name
input varA;
real varA;
// ... 其他输入
function_name = ...; // 返回变量 = 函数名
endfunction
type默认real;函数至少 1 个输入、1 个返回值。- 调用直接用函数名:
V(out) <+ maxvalue(V(in), V(ip));
⚠️ 函数内禁止:
- ddt / idt / idtmod 操作
- 模拟事件
- 拉普拉斯/Z 变换等模拟算子
示例(最大值函数):
analog function real maxvalue
input a, b;
real a, b;
maxvalue = max(a, b);
endfunction
编译器指令(以反引号 ` 开头)
类似 C 宏,编译阶段工作,不以
;结尾。注意区分 ` 与 '。
宏定义
`define macro_name macro_text
`undef macro_name
带参数宏:
`define sum(a,b) ((a)+(b))
// 使用:`sum(p+q) < 5
- 宏名前面也要加反引号。
- 不用 `undef 时有效范围为整个代码文件。
宏条件判断
`ifdef macro_name
`else
`endif
包含文件
`include "file_name"
- 原文内容插入到 include 位置(如
include "constants.vams")。
timescale
`timescale time_period/time_precision
- time_period 只影响数字域语句。
- time_precision(必须 < time_period)影响数字域、transition/Z 域/延时函数的默认精度。
- 单位:s / ms / us / ns / ps / fs,数字可为 1/10/100。
- 例:
`timescale 1ns/1ps
默认限定类型
`default_discipline discipline qualifier scope
- 设置默认网线类型(reg/wire/tri/wand/trior/wreal/trireg/supply0/...,均为数字域)。
- 模拟域网线必须显式写
electrical。 - 建议显式声明类型,不依赖宏。
默认上升/下降时间
`default_transition time
- 未显式指定时 transition 等函数的默认边沿时间;未定义时默认 0,由仿真器步长决定。
重置
`resetall
- 恢复所有默认设置,通常放代码第一行。
完整模块骨架(含指令)
`resetall
`timescale 1ns/1ps
`include "constants.vams"
`include "disciplines.vams"
module my_module(p, n);
inout p, n;
electrical p, n;
parameter real r = 100;
analog begin
V(p,n) <+ r*I(p,n);
end
endmodule
相关笔记
- 语法基础 → 02 - VerilogA 语法基础
- 模块定义 → 05 - VerilogA 模块定义与实例化
- 仿真器函数 → 09 - VerilogA 仿真器函数