diff --git a/firmware/rtl/control_loop/control_loop.v b/firmware/rtl/control_loop/control_loop.v index 13e81ab..7ed3ce9 100644 --- a/firmware/rtl/control_loop/control_loop.v +++ b/firmware/rtl/control_loop/control_loop.v @@ -1,6 +1,10 @@ -/* TODO: standardised access that isn't ad-hoc: wishbone - * bus */ - +/* TODO: The control loop outputs the adjustment value, not the + * total value to the DAC. Write code that gets the value from + * the DAC and writes the adjusted value to it. + * + * This can be in another module which only gets the value from + * the DAC on reset. + */ /************ Introduction to PI Controllers * The continuous form of a PI loop is * @@ -125,11 +129,10 @@ module control_loop parameter ADC_POLARITY = 1, parameter ADC_PHASE = 0, parameter DAC_POLARITY = 0, - parameter DAC_PHASE = 1 + parameter DAC_PHASE = 1, + parameter DATA_WID = CONSTS_WID ) ( input clk, - input arm, - output running, input signed [ADC_WID-1:0] measured_value, output adc_conv, @@ -137,43 +140,41 @@ module control_loop input adc_finished, output signed [DAC_WID-1:0] to_dac, + input signed [DAC_WID-1:0] from_dac, output dac_ss, output dac_arm, - input dac_finished + input dac_finished, - input reg read_err_cur, - output reg read_err_cur_finished, - output signed [ERR_WID-1:0] err_cur, - output signed [CONSTS_WID-1:0] adj, - - input signed [ADC_WID-1:0] setpt_in, - input signed [CONSTS_WID-1:0] cl_alpha_in, - input signed [CONSTS_WID-1:0] cl_p_in, - input [DELAY_WID-1:0] delay_in + /* Hacky ad-hoc read-write interface. */ + input reg [CONTROL_LOOP_CMD_WIDTH-1:0] cmd, + input reg [DATA_WIDTH-1:0] word_in, + output reg [DATA_WIDTH-1:0] word_out, + input start_cmd, + output reg finish_cmd ); -/* Registers used to lock in values at the start of each iteration */ reg signed [ADC_WID-1:0] setpt = 0; reg signed [CONSTS_WID-1:0] cl_alpha_reg = 0; reg signed [CONSTS_WID-1:0] cl_p_reg = 0; reg [DELAY_WID-1:0] saved_delay = 0; +reg running = 0; /* Registers for PI calculations */ reg signed [ERR_WID-1:0] err_prev = 0; /****** State machine * - * -> WAIT_ON_ARM -> WAIT_ON_ADC -> WAIT_ON_MUL -\ + * -> CYCLE_START -> WAIT_ON_ADC -> WAIT_ON_MUL -\ * \------\------------ WAIT_ON_DAC