首页 > 其他分享 >PWM

PWM

时间:2022-09-18 22:34:06浏览次数:53  
标签:duty cnt WIDTH rst input PWM cycle

 

module PWM #
(
parameter	WIDTH = 32	//ensure that 2**WIDTH > cycle
)
(
input					clk,
input					rst_n,
input		[WIDTH-1:0]	cycle,	//cycle > duty
input		[WIDTH-1:0]	duty,	//duty < cycle
output	reg				pwm_out
);

reg	[WIDTH-1:0]	cnt;
//counter for cycle
always @(posedge clk or negedge rst_n)
	if(!rst_n) cnt <= 1'b1;
	else if(cnt >= cycle) cnt <= 1'b1;
	else cnt <= cnt + 1'b1;

//pulse with duty
always @(posedge clk or negedge rst_n)
	if(!rst_n) pwm_out <= 1'b1;
	else if(cnt < duty) pwm_out <= 1'b1;
	else pwm_out <= 1'b0;

endmodule

  

 

标签:duty,cnt,WIDTH,rst,input,PWM,cycle
From: https://www.cnblogs.com/54programer/p/16706059.html

相关文章

  • 采用STM32的HRTIM实现三相同步三角载波PWM输出
    1.应用需求与实现思路对于常用的三相两电平变流器,通常应使三桥臂的载波为同步的三角载波。为方便控制,常在三角载波过零处进入中断进行采样何控制。当采用STM32的HRTIM实......