|
`include "disciplines.vams"
module sar_logic_1b (
start, // analog trigger, e.g. 0↔1.2V
comp_out, // comparator out (electrical, 0/0.9V)
msb, // trial bit to DAC
cmclk, // comparator sample clock ← 改名对齐
done, // decision done
dac_p, dac_n // drive to CDAC
);
input start, comp_out;
output msb, cmclk, done, dac_p, dac_n;
electrical start, comp_out, msb, cmclk, done, dac_p, dac_n;
// ---- params ----
parameter real vdd = 0.9, vss = 0.0, vth = 0.45;
parameter real VREFP = 0.6, VREFN = -0.6, VCM = 0.45;
parameter real trf = 200p;
parameter real samp_pw = 2n; // cmclk 脉宽
parameter real t_settle = 0.8n;// DAC/comp 安定等待
parameter real r_drv = 50.0; // 输出串阻
// ---- regs (real) ----
real msb_v, clk_v, done_v, dp_tgt, dn_tgt;
// 产生一个脉冲:上升->保持->下降
task automatic pulse_cmclk;
begin
clk_v = vdd; @(timer(samp_pw)); clk_v = vss;
end
endtask
analog begin
@(initial_step) begin
msb_v = vss; clk_v = vss; done_v = vss;
dp_tgt = VCM; dn_tgt = VCM;
end
// 上升沿启动一次 1-bit 决策
@(cross(V(start)-vth, +1)) begin
done_v = vss;
// 先打一拍采样(可当“采样/比较器置位”)
pulse_cmclk();
@(timer(t_settle));
// 读 comp_out 决定极性 → 开始试探
if ( V(comp_out) > 0.5*vdd ) begin
// voutp > voutn → 选择一种差分方向
dp_tgt = VREFN; // P 拉向 -0.6
dn_tgt = VREFP; // N 拉向 +0.6
msb_v = vdd;
end else begin
dp_tgt = VREFP; // P 拉向 +0.6
dn_tgt = VREFN; // N 拉向 -0.6
msb_v = vss;
end
// 等待比较器再稳一次,然后再打一拍确认
@(timer(t_settle));
pulse_cmclk();
@(timer(t_settle));
done_v = vdd;
end
// 下降沿:回到共模,准备下次触发
@(cross(V(start)-vth, -1)) begin
dp_tgt = VCM; dn_tgt = VCM;
clk_v = vss; // 防止残余高电平
end
// 正确的 Thevenin 形式:V = Vsrc - R*I
V(msb) <+ transition(msb_v, 0, trf, trf) - r_drv*I(msb);
V(cmclk) <+ transition(clk_v, 0, trf, trf) - r_drv*I(cmclk);
V(done) <+ transition(done_v, 0, trf, trf) - r_drv*I(done);
V(dac_p) <+ transition(dp_tgt,0, trf, trf) - r_drv*I(dac_p);
V(dac_n) <+ transition(dn_tgt,0, trf, trf) - r_drv*I(dac_n);
end
endmodule
|
|