新手上路
- 积分
- 46
- 金钱
- 46
- 注册时间
- 2016-2-14
- 在线时间
- 36 小时
|
10金钱
/*通过除法计算值,资源占比非常大*/
// swp1_cnt1 <= (1000/(sw_fre/10)*CLK_FREQ/1_000_000);
// swp1_cnt2 <= (sw_dut>sw_dut_max_real) ? (1000/(sw_fre/10)*CLK_FREQ/1_000_000)*sw_dut_max_real/100 : (1000/(sw_fre/10)*CLK_FREQ/1_000_000)*sw_dut/100;
/*通过直接赋值0,资源占比相对小*/
swp1_cnt1 <= 1'b0;
swp1_cnt2 <= 1'b0;
完整程序如下所示,请问是什么原因导致,或者怎么查看具体哪些程序占用了多少资源?
module sw_set(
input sys_clk,
input sys_rst_n,
input sw_up_en,
input sw_en,
input sw_p3_hl,
input sw_p4_hl,
input ad1_done_flag,
input ad2_done_flag,
input [15:0] sw_fre,
input [15:0] sw_dut,
input [15:0] sw_dt,
input [15:0] sw1_ctl,
input [15:0] sw2_ctl,
input [15:0] ad1_data_m,
input [15:0] ad2_data_m,
input [15:0] ad1_set_rl,
input [15:0] ad2_set_rl,
output reg sw_p1,
output reg sw_p2,
output reg sw_p3,
output reg sw_p4,
output reg sw_p5
);
`include "par.v"
parameter CLK_FREQ = 32_000_000;
reg ad1_done_flag_d0;
reg ad1_done_flag_d1;
wire ad1_done_flag_flag;
reg sw_up_en_d0;
reg sw_up_en_d1;
wire sw_up_en_flag;
reg [35:0] swp1_cnt; //计时
reg [35:0] swp1_cnt1; //周期
reg [35:0] swp1_cnt2; //开启时间
reg [35:0] swp1_cnt3; //死区时间
reg [35:0] swp3_cnt1; //开启时间
reg [35:0] swp4_cnt1; //开启时间
reg [15:0] sw_dut_max_real;
reg sw_up_en1;
reg sw_up_en1_d0;
reg sw_up_en1_d1;
wire sw_up_en1_flag;
assign ad1_done_flag_flag = (~ad1_done_flag_d1) & ad1_done_flag_d0;
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
begin
ad1_done_flag_d0 <= 1'b0;
ad1_done_flag_d1 <= 1'b0;
end
else
begin
ad1_done_flag_d0 <= ad1_done_flag;
ad1_done_flag_d1 <= ad1_done_flag_d0;
end
end
assign sw_up_en_flag = (~sw_up_en_d1) & sw_up_en_d0;
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
begin
sw_up_en_d0 <= 1'b0;
sw_up_en_d1 <= 1'b0;
end
else
begin
sw_up_en_d0 <= sw_up_en;
sw_up_en_d1 <= sw_up_en_d0;
end
end
//数据更新,更新占空比和死去时间的算法
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
begin
sw_dut_max_real<=1'b0;
swp1_cnt3<=CLK_FREQ/1_000_000*sw_dt/10;
end
else if(sw_up_en_flag)
begin
if((1000/(sw_fre/10)*CLK_FREQ/1_000_000) > (CLK_FREQ/1_000_000*sw_dt/10*2))
begin
// sw_dut_max_real <= (((1000/sw_fre*10*CLK_FREQ/1_000_000)-(CLK_FREQ/1_000_000*sw_dt/10*2))/(1000/sw_fre*10*CLK_FREQ/1_000_000)*100>`sw_dut_max)? `sw_dut_max:sw_dut_max_real;
if(((1000/sw_fre*10*CLK_FREQ/1_000_000)-(CLK_FREQ/1_000_000*sw_dt/10*2))/(1000/sw_fre*10*CLK_FREQ/1_000_000)*100>`sw_dut_max)
begin
sw_dut_max_real <= `sw_dut_max;
swp1_cnt3 <= CLK_FREQ/1_000_000*sw_dt/10;
sw_up_en1 <= 1'b1;
end
else
begin
sw_dut_max_real <= sw_dut;
swp1_cnt3 <= CLK_FREQ/1_000_000*sw_dt/10;
sw_up_en1 <= 1'b1;
end
end
else
begin
sw_up_en1<=1'b0;
swp1_cnt3<=swp1_cnt3;
end
end
else
begin
sw_up_en1 <= 1'b0;
swp1_cnt3 <=swp1_cnt3;
end
end
assign sw_up_en1_flag = (~sw_up_en1_d1) & sw_up_en1_d0;
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
begin
sw_up_en1_d0 <= 1'b0;
sw_up_en1_d1 <= 1'b0;
end
else
begin
sw_up_en1_d0 <= sw_up_en1;
sw_up_en1_d1 <= sw_up_en1_d0;
end
end
//根据占空比和死区时间计算计数值
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
begin
swp1_cnt1 <= 1'b0;
swp1_cnt2 <= 1'b0;
end
else if(sw_up_en1_flag)
begin
/*通过除法计算值,资源占比非常大*/
// swp1_cnt1 <= (1000/(sw_fre/10)*CLK_FREQ/1_000_000);
// swp1_cnt2 <= (sw_dut>sw_dut_max_real) ? (1000/(sw_fre/10)*CLK_FREQ/1_000_000)*sw_dut_max_real/100 : (1000/(sw_fre/10)*CLK_FREQ/1_000_000)*sw_dut/100;
/*通过直接赋值0,资源占比相对小*/
swp1_cnt1 <= 1'b0;
swp1_cnt2 <= 1'b0;
end
else
begin
swp1_cnt1 <= swp1_cnt1;
swp1_cnt2 <= swp1_cnt2;
end
end
always @(posedge sys_clk or negedge sys_rst_n)
begin
if (!sys_rst_n)
swp1_cnt <= 32'd0;
else if(swp1_cnt<swp1_cnt1)
swp1_cnt<= swp1_cnt+32'd1;
else
swp1_cnt<= 32'd0;
end
//pw1 pw2输出
always @(posedge sys_clk or negedge sys_rst_n)
begin
if (!sys_rst_n)
begin
sw_p1 <= 1'b1;
end
else if(sw_en==1'b1)
begin
if(sw1_ctl == 8'd0)
begin
if (swp1_cnt < swp1_cnt2)
sw_p1 <= 1'b0;
else
sw_p1 <= 1'b1;
end
else if(sw1_ctl == 8'd1)
sw_p1 <= 1'b0;
else if(sw1_ctl == 8'd2)
sw_p1 <= 1'b1;
else
sw_p1 <= sw_p1;
end
else
sw_p1 <= 1'b1;
end
|
-
cnt1 2除法计算
-
最佳答案
查看完整内容[请看2#楼]
你那个计算的挺复杂,乘除法是比较耗资源的。你可以看看那个计算能不能再化简一下,毕竟每个计算都是靠逻辑资源来实现的
|