New Hardware Git
This commit is contained in:
22
Verilog/test/test.v
Normal file
22
Verilog/test/test.v
Normal file
@@ -0,0 +1,22 @@
|
||||
module pwm (
|
||||
input wire clk, // 时钟输入
|
||||
input wire rst, // 异步复位
|
||||
input wire [7:0] duty, // 占空比(0~255)
|
||||
output reg pwm_out // 输出信号
|
||||
);
|
||||
reg [7:0] counter = 0; // 8位计数器,周期为 256
|
||||
|
||||
always @(posedge clk or posedge rst) begin
|
||||
if (rst) begin
|
||||
counter <= 0;
|
||||
pwm_out <= 0;
|
||||
end else begin
|
||||
counter <= counter + 1;
|
||||
// 比较占空比设置
|
||||
if (counter < duty)
|
||||
pwm_out <= 1;
|
||||
else
|
||||
pwm_out <= 0;
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
Reference in New Issue
Block a user