From 12686391ee0e88ffd1ba5426d6bbba41e5e31ec6 Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Thu, 20 Oct 2022 19:43:13 -0400 Subject: [PATCH] use integer saturation for dac value adjustment --- firmware/rtl/control_loop/control_loop.v | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/firmware/rtl/control_loop/control_loop.v b/firmware/rtl/control_loop/control_loop.v index 4518447..23dde32 100644 --- a/firmware/rtl/control_loop/control_loop.v +++ b/firmware/rtl/control_loop/control_loop.v @@ -296,7 +296,6 @@ wire signed[RTRUNC_WID-1:0] rtrunc = */ wire signed[DAC_DATA_WID-1:0] dac_adj_val; -reg signed[DAC_DATA_WID-1:0] stored_dac_val; intsat #( .IN_LEN(RTRUNC_WID), @@ -306,6 +305,19 @@ intsat #( .outp(dac_adj_val) ); +reg signed[DAC_DATA_WID-1:0] stored_dac_val; + +wire [DAC_DATA_WID:0] total_dac_val_add = stored_dac_val + dac_adj_val; +wire [DAC_DATA_WID-1:0] total_dac_val; + +intsat #( + .IN_LEN(DAC_DATA_WID), + .LTRUNC(1) +) total_dac_trunc ( + .inp(total_dac_val_add), + .outp(total_dac_val) +); + /**** Write to DAC ****/ reg [DELAY_WID-1:0] timer = 0; @@ -446,8 +458,8 @@ always @ (posedge clk) begin arm_mul <= 0; dac_arm <= 1; dac_ss <= 1; - stored_dac_val <= stored_dac_val + dac_adj_val; - to_dac <= b'0001 << DAC_DATA_WID | (stored_dac_val + dac_adj_val); + stored_dac_val <= total_dac_val; + to_dac <= b'0001 << DAC_DATA_WID | total_dac_val; state <= WAIT_ON_DAC; end WAIT_ON_DAC: if (dac_finished) begin