Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module rgst #(
- parameter w = 8 //register's width
- )(
- input clk,
- input rst_b, //asynchronous reset; active low
- input [w-1:0] d,
- input ld,
- input clr, //synchronous reset; active high
- output reg [w-1:0] q
- );
- always @ (posedge clk, negedge rst_b)
- if (!rst_b)
- q <= 1'd0;
- else if (clr)
- q <= 1'd0;
- else if (ld)
- q <= d;
- endmodule
- module atan_const (input [3:0] itr, output reg [15:0] atan);
- always @ (*)
- case (itr)
- 4'd0: atan = 16'h3244;
- 4'd1: atan = 16'h1dac;
- 4'd2: atan = 16'h0fae;
- 4'd3: atan = 16'h07f5;
- 4'd4: atan = 16'h03ff;
- 4'd5: atan = 16'h0200;
- 4'd6: atan = 16'h0100;
- 4'd7: atan = 16'h0080;
- 4'd8: atan = 16'h0040;
- 4'd9: atan = 16'h0020;
- 4'd10: atan = 16'h0010;
- 4'd11: atan = 16'h0008;
- 4'd12: atan = 16'h0004;
- 4'd13: atan = 16'h0002;
- 4'd14: atan = 16'h0001;
- default:atan = 16'h0000;
- endcase
- endmodule
- module cntr #(parameter w=8)(input clk, rst_b, c_up, clr, output reg [w-1] q);
- always @ (posedge clk, negedge rst_b)
- if (!rst_b)
- q <= 1'd0;
- else if (clr)
- q <= 1'd0;
- else
- q<=q+c_up;
- endmodule
- module add_sub (input [15:0] a, b,input s, output [15:0] o);
- assign o = s ? a-b : a+b;
- endmodule
- module arsh (input [15:0] a, input [3:0] i, output [15:0] o);
- assign o=$unsigned($signed(a)>>>i);
- endmodule
- module cntr_u(input clk, rst_b, bgn, [3:0] itr, output fin, ld, init);
- reg [2:0] st; wire [2;0] st_next;
- assign st_next[0] = st[0]&~bgn|st[2];
- assign st_next[1] = st[0]& bgn | st[1] &(itr!=4'd15);
- assign st_next[2] = st[1]&(itr==4'd15);
- assign init =st[0]& bgn;
- assign ld=st[0]&bgn|st[1];
- assign fin = st[2];
- always @ (posedge clk,negedge rst_b)
- if(!rst_b)
- st<=3'd1;
- else
- st<=st_next;
- endmodule
- module cordic (input clk, rst_b, bgn, [15:0] theta, output fin , [15:0] cos);
- wire [15:0] x_new, x_out, y_new, y_out,z_new, z_out,atan,x_rsh,y_rsh;
- wire [3:0] i;
- wire init, ld;
- ctrl_u u0(.clk(clk),.rst_b(rst_b),.bgn(bgn),.itr(i),.fin(fin), .ld(ld),.init(init));
- cntr #(.w(4)) u1(.clk(clk),.rst_b(rst_b),.c_up(ld),.clr(init),.q(i));
- atan_const u2(.itr(i),.atan(atan));
- rgst #(.w(16)) u3(.clk(clk),.rst_b(rst_b),.ld(ld),.clr(1'd0),.d(x_new),.q(x_out));
- arsh u4(.a(y_out),.o(y_rsh));
- add_sub u5(.a(x_out), .b(y_rsh),.s(~z_out[15]),.o(x_new));
- rgst #(.w(16)) u6(.clk(clk),.rst_b(rst_b),.ld(ld),.clr(1'd0),.d(y_new),.q(y_out));
- arsh u7(.a(x_out),.o(x_rsh));
- add_sub u8(.a(y_out), .b(x_rsh),.s(z_out[15]),.o(y_new));
- rgst #(.w(16)) u9(.clk(clk),.rst_b(rst_b),.ld(ld),.clr(1'd0),.d(z_new),.q(z_out));
- add_sub u10(.a(z_out), .b(atan),.s(~z_out[15]),.o(z_new));
- assign cos+fin?x_out:16'bz;
- endmodule
- module cordic_tb(output reg clk, rst_b, bgn, [15:0] theta,output fin, [15:0] cos);
Advertisement
Add Comment
Please, Sign In to add comment