Verilog-AMS 混合信号仿真

在同一个模块内同时描述数字与模拟行为。需要掌握 Verilog-HDL 基础(本文不展开数字语法)。

基本概念

域(Domain)

域 信号表示 步长
模拟域 连续(电压/电流) 迭代计算,步长自适应
数字域 离散(H/L/Z) 固定步长

上下文(Context)

网线/节点/端口/信号

模拟与数字的互动

一个模块可含多个 always,但只能有一个 analog 块。

模拟上下文访问数字量

数字域 模拟域 说明
real real 数值不变
integer integer 数值不变
bit integer H/L→1/0;Z/X 无法转换会报错
bit[n:0] integer bit[n] 恒 0;数值=Σbit[i]·2ⁱ
module dac_1bit(in, out);
input in; inout out;
wire in; logic in; electrical out;
real vout;
analog begin
    if(in == 0) vout = 0.0;
    else        vout = 3.0;
    V(out) <+ vout;
end
endmodule

数字上下文访问模拟量

module sampler(in, clk, out);
inout in; inout clk; output out;
electrical in;
wire clk; reg out;
always @(posedge clk) begin
    out = V(in);   // 默认转换:>0 → 1
end
endmodule

模拟上下文检测数字事件

module sampler(in, clk, out);
input in, clk; output out;
wire clk; real vout;
electrical in, clk, out;
analog begin
    @(posedge clk, 1) begin
        vout = V(in);
    end
    V(out) <+ vout;
end
endmodule

数字上下文检测模拟事件

module sampler2(in, clk, out);
input in, clk; output out;
wire in; reg out; electrical clk;
always @(cross(V(clk) - 2.5, 1))
    out = in;
endmodule

连接模块(Connect Module)

模拟网线与数字网线不能直接计算,跨域连接点需要连接模块转换。

分类

类型 功能 类比
d2a 数字输入→模拟输出 DAC
a2d 模拟输入→数字输出 ADC
bidir 双向 —

定义 connectmodule

connectmodule bidir(anax, digx);
inout anax; inout digx;
logic digx; electrical anax;
reg tmp;

assign digx = tmp;

analog begin
    V(anax) <+ transition(digx == 1 ? 5.0 : 0.0, 3n, 3n);
end
always @(cross(V(anax) - 2.5, +1)) tmp = 1'b1;
always @(cross(V(anax) - 2.5, -1)) tmp = 1'b0;
endmodule

自动插入(connectrules)

connectrules rule_name;
    connect_insertion | connect_resolution
endconnectrules

工作原理(要点)

  1. 域内连接不插模块。
  2. 数字输出→模拟输入:插 1bit DAC 型模块(逻辑电平→Vsupply/Vgnd)。
  3. 模拟输出→数字输入:插 1bit ADC 型模块。
  4. 数字节点连到模拟端口 → 在连接点插模块;外部混合信号网线则两侧各插一个(DA + AD)。
  5. 信号是否经过模拟仿真器,决定是否有天然延迟——d1→d2 若经过模拟域则带延迟。

混合信号仿真的局限(设计须知)

数字→模拟转换:

模拟→数字转换:

设计建议:顶层尽量只分数字/模拟两大块,减少跨域转换点(连接模块复杂 + 仿真时间浪费),详见 13 - VerilogA 建模与系统设计。

相关笔记