完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
源代码:
module sin_cos( clk, rst, en, phasein, //================================================= sin_out, cos_out, eps_out ); parameter dwidth=17; parameter pipeline=15; input clk; input rst; input en; input[dwidth-1:0] phasein; output wire [16:0] sin_out; output wire [16:0] cos_out; output wire [16:0] eps_out; //output[dwidth-1:0]sin; //output[dwidth-1:0]cos; //output[dwidth-1:0]eps; //output bee; reg[dwidth-1:0]sin; reg[dwidth-1:0]cos; reg[dwidth-1:0]eps; reg[dwidth-1:0]phaseinreg; reg[dwidth-1:0]x0,y0,z0; reg[dwidth-1:0]x1,y1,z1; reg[dwidth-1:0]x2,y2,z2; reg[dwidth-1:0]x3,y3,z3; reg[dwidth-1:0]x4,y4,z4; reg[dwidth-1:0]x5,y5,z5; reg[dwidth-1:0]x6,y6,z6; reg[dwidth-1:0]x7,y7,z7; reg[dwidth-1:0]x8,y8,z8; reg[dwidth-1:0]x9,y9,z9; reg[dwidth-1:0]x10,y10,z10; reg[dwidth-1:0]x11,y11,z11; reg[dwidth-1:0]x12,y12,z12; reg[dwidth-1:0]x13,y13,z13; reg[dwidth-1:0]x14,y14,z14; reg[dwidth-1:0]x15,y15,z15; reg quadrant; reg delay_flag; integer i; //assign bee=1; assign sin_out=sin; assign cos_out=cos; assign eps_out=eps; always @(posedge clk or negedge rst) begin if(!rst) phaseinreg<=17'd0; else if(en) begin case(phasein[16]) 1'b1:phaseinreg<=phasein+17'h08000;//phase+pi/2 1'b0:phaseinreg<=phasein-17'h08000;//phase-pi/2 endcase end end always @(posedge clk or negedge rst) begin if(!rst) begin x0<=0;y0<=0;z0<=0; end else if(en) begin x0<=17'h04ad2;y0<=0;z0<=phaseinreg;//x=0.607253 end end //1111111111111111111111111111111111111111111111111 always @(posedge clk or negedge rst) begin if(!rst) begin x1<=0;y1<=0;z1<=0; end else if(en) begin if(z0[dwidth-1]==0)//判断旋转方向 begin x1<=x0-y0; y1<=y0+x0; z1<=z0-17'h4000; end else begin x1<=x0+y0; y1<=y0-x0; z1<=z0+17'h4000; end end end //2222222222222222222222222222222222222222222222222222222222 always @(posedge clk or negedge rst) begin if(!rst) begin x2<=0;y2<=0;z2<=0; end else if(en) begin if(z1[dwidth-1]==0) begin x2<=x1-{y1[dwidth-1],y1[dwidth-1:1]}; y2<=y1+{x1[dwidth-1],x1[dwidth-1:1]}; z2<=z1-17'h25c8; end else begin x2<=x1+{y1[dwidth-1],y1[dwidth-1:1]}; y2<=y1-{x1[dwidth-1],x1[dwidth-1:1]}; z2<=z1+17'h25c8; end end end //33333333333333333333333333333333333333333333333333333333333333333 always @(posedge clk or negedge rst) begin if(!rst) begin x3<=0;y3<=0;z3<=0; end else if(en) begin if(z0[dwidth-1]==0) begin x3<=x2-{{2{y2[dwidth-1]}},y2[dwidth-1:2]}; y3<=y2+{{2{x2[dwidth-1]}},x2[dwidth-1:2]}; z3<=z2-17'h13F6; end else begin x3<=x2+{{2{y2[dwidth-1]}},y2[dwidth-1:2]}; y3<=y2-{{2{x2[dwidth-1]}},x2[dwidth-1:2]}; z3<=z2+17'h13F6; end end end //444444444444444444444444444444444444444444444444444444444444444 always @(posedge clk or negedge rst) begin if(!rst) begin x4<=0;y4<=0;z4<=0; end else if(en) begin if(z3[dwidth-1]==0) begin x4<=x3-{{3{y3[dwidth-1]}},y3[dwidth-1:3]}; y4<=y3+{{3{x3[dwidth-1]}},x3[dwidth-1:3]}; z4<=z3-17'h0a22; end else begin x4<=x3+{{3{y3[dwidth-1]}},y3[dwidth-1:3]}; y4<=y3-{{3{x3[dwidth-1]}},x3[dwidth-1:3]}; z4<=z3+17'h0a22; end end end //55555555555555555555555555555555555555555555555555555555555555555555555555 always @(posedge clk or negedge rst) begin if(!rst) begin x5<=0;y5<=0;z5<=0; end else if(en) begin if(z4[dwidth-1]==0) begin x5<=x4-{{4{y4[dwidth-1]}},y4[dwidth-1:4]}; y5<=y4+{{4{x4[dwidth-1]}},x4[dwidth-1:4]}; z5<=z4-17'h0516; end else begin x5<=x4+{{4{y4[dwidth-1]}},y4[dwidth-1:4]}; y5<=y4-{{4{x4[dwidth-1]}},x4[dwidth-1:4]}; z5<=z4+17'h0516; end end end //66666666666666666666666666666666666666666666666666666666666666666666666 always @(posedge clk or negedge rst) begin if(!rst) begin x6<=0;y6<=0;z6<=0; end else if(en) begin if(z5[dwidth-1]==0) begin x6<=x5-{{5{y5[dwidth-1]}},y5[dwidth-1:5]}; y6<=y5+{{5{x5[dwidth-1]}},x5[dwidth-1:5]}; z6<=z5-17'h028c; end else begin x6<=x5+{{5{y5[dwidth-1]}},y5[dwidth-1:5]}; y6<=y5-{{5{x5[dwidth-1]}},x5[dwidth-1:5]}; z6<=z5+17'h028c; end end end //777777777777777777777777777777777777777777777777777777777777777 always @(posedge clk or negedge rst) begin if(!rst) begin x7<=0;y7<=0;z7<=0; end else if(en) begin if(z6[dwidth-1]==0) begin x7<=x6-{{6{y6[dwidth-1]}},y6[dwidth-1:6]}; y7<=y6+{{6{x6[dwidth-1]}},x6[dwidth-1:6]}; z7<=z6-17'h0146; end else begin x7<=x6+{{6{y6[dwidth-1]}},y6[dwidth-1:6]}; y7<=y6-{{6{x6[dwidth-1]}},x6[dwidth-1:6]}; z7<=z6+17'h0146; end end end //8888888888888888888888888888888888888888888888888888888888 always @(posedge clk or negedge rst) begin if(!rst) begin x8<=0;y8<=0;z8<=0; end else if(en) begin if(z7[dwidth-1]==0) begin x8<=x7-{{7{y7[dwidth-1]}},y7[dwidth-1:7]}; y8<=y7+{{7{x7[dwidth-1]}},x7[dwidth-1:7]}; z8<=z7-17'h00a3; end else begin x8<=x7+{{7{y7[dwidth-1]}},y7[dwidth-1:7]}; y8<=y7-{{7{x7[dwidth-1]}},x7[dwidth-1:7]}; z8<=z7+17'h00a3; end end end //9999999999999999999999999999999999999999999999999999999 always @(posedge clk or negedge rst) begin if(!rst) begin x9<=0;y9<=0;z9<=0; end else if(en) begin if(z8[dwidth-1]==0) begin x9<=x8-{{8{y8[dwidth-1]}},y8[dwidth-1:8]}; y9<=y8+{{8{x8[dwidth-1]}},x8[dwidth-1:8]}; z9<=z8-17'h0052; end else begin x9<=x8+{{8{y8[dwidth-1]}},y8[dwidth-1:8]}; y9<=y8-{{8{x8[dwidth-1]}},x8[dwidth-1:8]}; z9<=z8+17'h0052; end end end //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA always @(posedge clk or negedge rst) begin if(!rst) begin x10<=0;y10<=0;z10<=0; end else if(en) begin if(z9[dwidth-1]==0) begin x10<=x9-{{9{y9[dwidth-1]}},y9[dwidth-1:9]}; y10<=y9+{{9{x9[dwidth-1]}},x9[dwidth-1:9]}; z10<=z9-17'h0029; end else begin x10<=x9+{{9{y9[dwidth-9]}},y9[dwidth-1:9]}; y10<=y9-{{9{x9[dwidth-9]}},x9[dwidth-1:9]}; z10<=z9+17'h0029; end end end //BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB always @(posedge clk or negedge rst) begin if(!rst) begin x11<=0;y11<=0;z11<=0; end else if(en) begin if(z10[dwidth-1]==0) begin x11<=x10-{{10{y10[dwidth-1]}},y10[dwidth-1:10]}; y11<=y10+{{10{x10[dwidth-1]}},x10[dwidth-1:10]}; z11<=z10-17'h0014; end else begin x11<=x10+{{10{y10[dwidth-10]}},y10[dwidth-1:10]}; y11<=y10-{{10{x10[dwidth-10]}},x10[dwidth-1:10]}; z11<=z10+17'h0014; end end end //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC always @(posedge clk or negedge rst) begin if(!rst) begin x12<=0;y12<=0;z12<=0; end else if(en) begin if(z11[dwidth-1]==0) begin x12<=x11-{{11{y11[dwidth-1]}},y11[dwidth-1:11]}; y12<=y11+{{11{x11[dwidth-1]}},x11[dwidth-1:11]}; z12<=z11-17'h000a; end else begin x12<=x11+{{11{y11[dwidth-11]}},y11[dwidth-1:11]}; y12<=y11-{{11{x11[dwidth-11]}},x11[dwidth-1:11]}; z12<=z11+17'h000a; end end end //DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD always @(posedge clk or negedge rst) begin if(!rst) begin x13<=0;y13<=0;z13<=0; end else if(en) begin if(z12[dwidth-1]==0) begin x13<=x12-{{12{y12[dwidth-1]}},y12[dwidth-1:12]}; y13<=y12+{{12{x12[dwidth-1]}},x12[dwidth-1:12]}; z13<=z12-17'h0005; end else begin x13<=x12+{{12{y12[dwidth-12]}},y12[dwidth-1:12]}; y13<=y12-{{12{x12[dwidth-12]}},x12[dwidth-1:12]}; z13<=z12+17'h0005; end end end //EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE always @(posedge clk or negedge rst) begin if(!rst) begin x14<=0;y14<=0;z14<=0; end else if(en) begin if(z13[dwidth-1]==0) begin x14<=x13-{{13{y13[dwidth-1]}},y13[dwidth-1:13]}; y14<=y13+{{13{x13[dwidth-1]}},x13[dwidth-1:13]}; z14<=z13-17'h0003; end else begin x14<=x13+{{13{y13[dwidth-13]}},y13[dwidth-1:13]}; y14<=y13-{{13{x13[dwidth-13]}},x13[dwidth-1:13]}; z14<=z13+17'h0003; end end end //FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF always @(posedge clk or negedge rst) begin if(!rst) begin x15<=0;y15<=0;z15<=0; end else if(en) begin if(z14[dwidth-1]==0) begin x15<=x14-{{14{y14[dwidth-1]}},y14[dwidth-1:14]}; y15<=y14+{{14{x14[dwidth-1]}},x14[dwidth-1:14]}; z15<=z14-17'h0001; end else begin x15<=x14+{{14{y14[dwidth-14]}},y14[dwidth-1:14]}; y15<=y14-{{14{x14[dwidth-14]}},x14[dwidth-1:14]}; z15<=z14+17'h0001; end end end //---------------------------------------------------------------------------- always @(posedge clk or negedge rst) begin if(!rst) for(i=0;i<=pipeline;i=i+1) quadrant<=1'b0; else if(en) begin for(i=0;i if(i==15) begin delay_flag<=1; quadrant<=phasein[dwidth-1]; end end end end always @(posedge clk or negedge rst) begin if(!rst) begin sin<=0;cos<=0;eps<=0; end else if(en) begin if(delay_flag) begin if(quadrant) begin sin<=~(x15)+1;cos<=y15;eps<=z15;end else begin sin<=x15;cos<=~(y15)+1;eps<=z15;end end end end endmodule tb代码: `timescale 1ns/1ns module sin_cos_top; reg clk; reg rst; reg en; reg [16:0]phasein; //reg [16:0]sin; //reg [16:0]cos; //reg [16:0]eps; initial begin clk=1; rst=1; en=0; phasein=17'd0; #1000 rst=0; #2000 en=1; end always begin #10 clk=1'b1;#10 clk=1'b0;end always @(posedge clk) begin if(en) begin if(phasein==17'h1ffff) phasein<=0; else phasein<=phasein+1'b1; end else phasein<=phasein; end sin_cos sincos( .clk(clk), .rst(rst), .en(en), .phasein(phasein), .sin_out (sin_out), .cos_out (cos_out), .eps_out (eps_out) ); endmodule 得到的Object内的信号如图: 得到输出波形如图:
|
|
相关推荐
2个回答
|
|
已经解决,tb文件中要设置输出,没设置
|
|
|
|
已经解决,tb文件中要设置输出,没设置
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1702 浏览 1 评论
1460 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
1671 浏览 0 评论
943 浏览 0 评论
2469 浏览 0 评论
1507 浏览 38 评论
5706 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 11:01 , Processed in 1.034067 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号