|
module pwm_controller
(
input CLK,
input nRST,
input[10:0] FRE,
input[6:0] DUTY,
output reg PWM
);
reg [31:0] counter1;
always @(posedge CLK or negedge nRST) begin
if (!nRST)
counter1 <= 24'd0;
else if (counter1 < 100000000/FRE)
counter1 <= counter1 + 1;
else
counter1 <= 24'd0;
end
always @(posedge CLK or negedge nRST) begin
if (!nRST)
PWM <= 1'b0;
else if (counter1 < 100000000/FRE/100*DUTY)
PWM<= 1'b1;
else
PWM <= 1'b0;
end
endmodule
主模块给pwm模块 传递频率和 占空比参数. 可能是因为有乘除法的原因, 单个pwm就占用1k资源,求优化方法 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|