From bbf9bf3f0cfc7f0e4a81513b179443b205026ac9 Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Tue, 30 May 2023 13:49:23 +0100 Subject: [PATCH] Further adjust bit offsets, improve accuracy from 1.34601 to 0.455326 --- cordic.sv | 2 +- saw2sin.sv | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cordic.sv b/cordic.sv index e3629cd..1c39097 100644 --- a/cordic.sv +++ b/cordic.sv @@ -62,7 +62,7 @@ end /* verilator lint_on ALWCOMBORDER */ always_comb - if (i_qph > 16'd65508) o_sin = 16'hFFFF; + if (i_qph > 16'd65508) o_sin = 16'hFFFE; else if (i_qph < 16'd32) o_sin = i_qph + (i_qph >> 1); else o_sin = y[19][17:2]; diff --git a/saw2sin.sv b/saw2sin.sv index c9e753b..c74347d 100644 --- a/saw2sin.sv +++ b/saw2sin.sv @@ -22,8 +22,13 @@ cordic cordic , .o_sin (qsin) ); -always_comb o_sin = invert - ? ~{1'b1, qsin[15:1]} + 1 // Invert - : {1'b1, qsin[15:1]}; // Normal +logic [16:0] sin; +always_comb sin = reverse + ? (invert ? ~{1'b1, qsin[15:0]} // Reverse, Invert + : {1'b1, qsin[15:0]} + 17'd1) // Reverse, Normal + : (invert ? ~{1'b1, qsin[15:0]} + 17'd2 // Normal, Invert + : {1'b1, qsin[15:0]} + 17'd0); // Normal, Normal + +always_comb o_sin = sin[16:1]; endmodule