mirror of
https://github.com/supleed2/cordic.git
synced 2024-12-22 05:35:51 +00:00
Add saw2sin_poly.sv
Polynomial approximation to sine Input 0-65535 represents 0-90 degrees Output 0-65535 represents 0-1
This commit is contained in:
parent
12139ee462
commit
e00149bb62
30
saw2sin_poly.sv
Normal file
30
saw2sin_poly.sv
Normal file
|
@ -0,0 +1,30 @@
|
|||
`default_nettype none
|
||||
|
||||
module saw2sin_poly
|
||||
( input var [15:0] i_saw
|
||||
, output var [15:0] o_sin
|
||||
);
|
||||
|
||||
logic invert;
|
||||
always_comb invert = i_saw[15];
|
||||
|
||||
logic reverse;
|
||||
always_comb reverse = i_saw[14];
|
||||
|
||||
logic [15:0] qsaw;
|
||||
always_comb qsaw = reverse
|
||||
? {~i_saw[13:0], 2'b01} // Reverse
|
||||
: {i_saw[13:0], 2'b00}; // Normal
|
||||
|
||||
logic [63:0] x_in, x_17;
|
||||
always_comb x_in = {48'd0, qsaw};
|
||||
always_comb x_17 = 64'd131072 - x_in;
|
||||
|
||||
logic [63:0] qsin;
|
||||
always_comb qsin = (64'd262144 * x_in * x_17) / (64'd21474836480 - (x_in * x_17));
|
||||
|
||||
always_comb o_sin = invert
|
||||
? ~{1'b1, qsin[15:1]} + 1 // Invert
|
||||
: {1'b1, qsin[15:1]}; // Normal
|
||||
|
||||
endmodule
|
Loading…
Reference in a new issue