upsilon/gateware/rtl/control_loop/control_loop_sim_top.v

158 lines
2.9 KiB
Coq
Raw Normal View History

2023-06-15 12:24:35 -04:00
/* Copyright 2023 (C) Peter McGoron
* This file is a part of Upsilon, a free and open source software project.
* For license terms, refer to the files in `doc/copying` in the Upsilon
* source distribution.
*/
2022-11-11 21:57:58 -05:00
2022-11-21 21:41:50 -05:00
module control_loop_sim_top #(
2022-09-16 18:01:34 -04:00
parameter ADC_WID = 18,
2022-11-21 21:41:50 -05:00
parameter ADC_WID_SIZ = 5,
2022-09-16 18:01:34 -04:00
parameter ADC_POLARITY = 1,
parameter ADC_PHASE = 0,
2022-11-11 21:57:58 -05:00
parameter DAC_POLARITY = 0,
parameter DAC_PHASE = 1,
2022-09-16 18:01:34 -04:00
parameter DAC_DATA_WID = 20,
2022-11-11 21:57:58 -05:00
parameter DAC_WID = 24,
2022-11-21 21:41:50 -05:00
parameter DAC_WID_SIZ = 5,
2023-06-28 17:38:41 -04:00
parameter CYCLE_COUNT_WID = 18,
2022-11-11 21:57:58 -05:00
2022-11-21 21:41:50 -05:00
parameter CONSTS_WHOLE = 21,
parameter CONSTS_FRAC = 43,
`define CONSTS_WID (CONSTS_WHOLE + CONSTS_FRAC)
parameter CONSTS_SIZ = 7,
2022-09-16 18:01:34 -04:00
parameter DELAY_WID = 16
2022-10-17 00:44:30 -04:00
)(
2022-09-16 18:01:34 -04:00
input clk,
2023-05-10 14:35:57 -04:00
input rst_L,
output in_loop,
2022-10-17 00:44:30 -04:00
2022-11-21 21:41:50 -05:00
output [DAC_DATA_WID-1:0] curset,
output dac_err,
2022-11-11 21:57:58 -05:00
2022-11-21 21:41:50 -05:00
input [ADC_WID-1:0] measured_value,
output request,
input fulfilled,
output adc_err,
2023-06-28 17:38:41 -04:00
input assert_change,
output change_made,
input run_loop_in,
input [ADC_WID-1:0] setpt_in,
input [`CONSTS_WID-1:0] P_in,
input [`CONSTS_WID-1:0] I_in,
input [DELAY_WID-1:0] delay_in,
output [CYCLE_COUNT_WID-1:0] cycle_count,
output [DAC_DATA_WID-1:0] z_pos,
output [ADC_WID-1:0] z_measured
2022-11-11 21:57:58 -05:00
);
2022-10-17 00:44:30 -04:00
/* Emulate a control loop environment with simulator controlled
SPI interfaces.
*/
2022-09-16 18:01:34 -04:00
2022-11-21 21:41:50 -05:00
wire adc_miso;
wire adc_sck;
wire adc_ss_L;
2022-10-17 00:44:30 -04:00
/* ADC */
2022-11-21 21:41:50 -05:00
adc_sim #(
2022-09-16 18:01:34 -04:00
.WID(ADC_WID),
2022-10-17 00:44:30 -04:00
.WID_LEN(5),
2022-11-21 21:41:50 -05:00
.POLARITY(ADC_POLARITY),
.PHASE(ADC_PHASE)
) adc (
2022-10-17 00:44:30 -04:00
.clk(clk),
2023-05-10 14:35:57 -04:00
.rst_L(rst_L),
2022-11-21 21:41:50 -05:00
.indat(measured_value),
.request(request),
.fulfilled(fulfilled),
.err(adc_err),
2022-10-17 00:44:30 -04:00
.miso(adc_miso),
2022-11-21 21:41:50 -05:00
.sck(adc_sck),
.ss_L(adc_ss_L)
2022-10-17 00:44:30 -04:00
);
2022-11-21 21:41:50 -05:00
wire dac_miso;
wire dac_mosi;
wire dac_ss_L;
wire dac_sck;
2022-10-17 00:44:30 -04:00
/* DAC */
2022-11-21 21:41:50 -05:00
dac_sim #(
2022-10-17 00:44:30 -04:00
.WID(DAC_WID),
2022-11-21 21:41:50 -05:00
.DATA_WID(DAC_DATA_WID),
2022-10-17 00:44:30 -04:00
.WID_LEN(5),
2022-11-21 21:41:50 -05:00
.POLARITY(DAC_POLARITY),
.PHASE(DAC_PHASE)
) dac (
2022-10-17 00:44:30 -04:00
.clk(clk),
2023-05-10 14:35:57 -04:00
.rst_L(rst_L),
2022-11-21 21:41:50 -05:00
.curset(curset),
2022-10-17 00:44:30 -04:00
.mosi(dac_mosi),
2022-11-21 21:41:50 -05:00
.miso(dac_miso),
2022-10-17 00:44:30 -04:00
.sck(dac_sck),
2022-11-21 21:41:50 -05:00
.ss_L(dac_ss_L),
.err(dac_err)
2022-10-17 00:44:30 -04:00
);
2022-09-16 18:01:34 -04:00
control_loop #(
.ADC_WID(ADC_WID),
2022-11-21 21:41:50 -05:00
.ADC_WID_SIZ(ADC_WID_SIZ),
2022-10-17 00:44:30 -04:00
.ADC_POLARITY(ADC_POLARITY),
.ADC_PHASE(ADC_PHASE),
2022-11-21 21:41:50 -05:00
/* Keeping cycle half wait and conv wait the same
* since it doesn't matter for this simulation */
2023-06-28 17:38:41 -04:00
.CYCLE_COUNT_WID(CYCLE_COUNT_WID),
2022-11-21 21:41:50 -05:00
.CONSTS_WHOLE(CONSTS_WHOLE),
.CONSTS_FRAC(CONSTS_FRAC),
.CONSTS_SIZ(CONSTS_SIZ),
.DELAY_WID(DELAY_WID),
.DAC_WID(DAC_WID),
.DAC_WID_SIZ(DAC_WID_SIZ),
.DAC_DATA_WID(DAC_DATA_WID),
2022-10-17 00:44:30 -04:00
.DAC_POLARITY(DAC_POLARITY),
.DAC_PHASE(DAC_PHASE)
2022-09-16 18:01:34 -04:00
) cloop (
2022-10-17 00:44:30 -04:00
.clk(clk),
2023-05-10 14:35:57 -04:00
.rst_L(rst_L),
.in_loop(in_loop),
2022-11-21 21:41:50 -05:00
.dac_mosi(dac_mosi),
.dac_miso(dac_miso),
.dac_ss_L(dac_ss_L),
.dac_sck(dac_sck),
2022-09-16 18:01:34 -04:00
2022-11-21 21:41:50 -05:00
.adc_miso(adc_miso),
.adc_conv_L(adc_ss_L),
.adc_sck(adc_sck),
2023-06-28 17:38:41 -04:00
.assert_change(assert_change),
.change_made(change_made),
.run_loop_in(run_loop_in),
.setpt_in(setpt_in),
.P_in(P_in),
.I_in(I_in),
.delay_in(delay_in),
.cycle_count(cycle_count),
.z_pos(z_pos),
.z_measured(z_measured)
2022-09-16 18:01:34 -04:00
);
2022-11-21 21:41:50 -05:00
`ifdef VERILATOR
initial begin
$dumpfile("control_loop.fst");
$dumpvars;
end
`endif
2022-09-16 18:01:34 -04:00
endmodule
2022-11-21 21:41:50 -05:00
`undefineall