add: virtual DAC (100%) and ADC (80%)
upd: makefile
This commit is contained in:
53
designs/reflectometer_base/adc_model.sv
Normal file
53
designs/reflectometer_base/adc_model.sv
Normal file
@ -0,0 +1,53 @@
|
||||
// AN9238 virtual ADC model (1 port)
|
||||
|
||||
module virtual_adc_model #(
|
||||
parameter int unsigned ADC_DATA_WIDTH = 12,
|
||||
|
||||
// Bipolar input range: +/- VOLTAGE_RANGE
|
||||
parameter real VOLTAGE_RANGE = 1.0,
|
||||
|
||||
// Analog input correction
|
||||
parameter real VOLTAGE_GAIN = 0.2,
|
||||
parameter real GROUND_BIAS = 0.0,
|
||||
|
||||
// ADC timing parameters
|
||||
parameter time CONVERSION_DELAY = 150ps
|
||||
)(
|
||||
input logic clk_i,
|
||||
input real voltage_i,
|
||||
|
||||
output logic otr_o,
|
||||
output logic [ADC_DATA_WIDTH-1:0] data_o
|
||||
);
|
||||
|
||||
localparam int unsigned ZERO_CODE = (1 << (ADC_DATA_WIDTH - 1));
|
||||
localparam real VOLTAGE_STEP = VOLTAGE_RANGE / real'(ZERO_CODE);
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Convert analog voltage to ADC code TODO: add OTR check
|
||||
//------------------------------------------------------------
|
||||
function automatic real code_to_voltage(
|
||||
input logic [ADC_DATA_WIDTH-1:0] code
|
||||
);
|
||||
return (int'(code) - int'(ZERO_CODE)) * VOLTAGE_STEP;
|
||||
endfunction
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Initial state
|
||||
//------------------------------------------------------------
|
||||
initial begin
|
||||
data_o = ZERO_CODE; // 0V
|
||||
otr_o = 0;
|
||||
end
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Update analog output
|
||||
//------------------------------------------------------------
|
||||
always @(posedge clk_i) begin
|
||||
#(CONVERSION_DELAY);
|
||||
data_o = ;
|
||||
otr_o = ;
|
||||
|
||||
end
|
||||
|
||||
endmodule
|
||||
Reference in New Issue
Block a user