|
发表于 2025-1-20 08:52:21
|
显示全部楼层
`include "constants.vams" `include "disciplines.vams" module sar_adc(vin, clk, rst, dout); // Ports definition input vin; // Analog input input clk, rst; // Clock and reset output [11:0] dout; // 12-bit digital output // Electrical nodes electrical vin; electrical vdac; // DAC output node // Parameters parameter real vdd = 1.8; // Supply voltage parameter real vss = 0; // Ground parameter real vref = 1.8; // Reference voltage parameter real tdel = 0.1n; // Delay time parameter integer N = 12; // Resolution bits // Internal variables real sample; // Sampled input real comp_out; // Comparator output integer i; // Bit counter real [11:0] result; // Conversion result real dac_value; // DAC output value // Analog behavior analog begin @(initial_step) begin result = 0; i = N-1; end @(cross(V(clk) - vdd/2, +1)) begin // Rising edge of clock if (V(rst) > vdd/2) begin // Reset condition result = 0; i = N-1; end else begin // Sample input on first clock if (i == N-1) begin sample = V(vin); end // SAR algorithm if (i >= 0) begin // Set current bit result[i] = 1; // Calculate DAC value dac_value = 0; for (integer j=0; j<N; j=j+1) begin dac_value = dac_value + result[j] * vref * pow(2, j-N); end // Compare if (sample < dac_value) begin result[i] = 0; // Reset bit if comparison fails end i = i - 1; // Move to next bit end end end // DAC output V(vdac) <+ transition(dac_value, tdel); // Digital output assignment dout = result; end endmodule |
|