当前位置:网站首页>手撕Verilog PWM呼吸灯
手撕Verilog PWM呼吸灯
2022-07-31 12:12:00 【IC学习者】
pwm的频率通过parameter传递,
对clk按 (分频参数+1)进行分频,
占空比从0增加到 分频参数/(分频参数+1)
rtl
module pwm#(
parameter [10:0] FREQUENCY = 11'd4
)(
input clk,
input rst_n,
output pwm
);
reg [10:0] freq;
reg [10:0] duty;
always @(posedge clk ) begin
if(!rst_n)
freq <= 11'd0;
else if(freq == FREQUENCY) begin
freq <= 11'd0;
end
else begin
freq <= freq + 1'b1;
end
end
always @(posedge clk ) begin
if(!rst_n)
duty <= 11'd0;
else if(freq == FREQUENCY) begin
if(duty < FREQUENCY)
duty <= duty + 1'b1;
else
duty <= 11'd0;
end
end
assign pwm = (freq < duty)? 1'b1: 1'b0;
endmodule
tb
module tb_pwm(
);
parameter CYCLE = 10;
reg clk;
reg rst_n;
wire pwm;
initial begin
clk = 1'b0;
rst_n = 1'b0;
#20 rst_n = 1'b1;
end
always #(CYCLE/2) clk = ~clk;
pwm u1(
.clk(clk),
.rst_n(rst_n),
.pwm(pwm)
);
endmodule
仿真结果

边栏推荐
- Experience innovation and iteration through the development of lucky draw mini-programs
- Use ODBC in Excel to read data from CDS view on SAP BTP platform
- If the value of the enum map does not exist, deserialization is not performed
- Addition logic for SAP Commerce Cloud Product Review
- 科学论文和学术论文写作
- 使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
- Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
- Spark GC日志分析
- JVS函数公式使用场景介绍
- 栈和队列的基本概念
猜你喜欢
随机推荐
串的基本概念与操作
Different lower_case_table_names settings for server ('1') and data dictionary ('0') solution
[core]-ARMV7-A, ARMV8-A, ARMV9-A Architecture Introduction "Recommended Collection"
vb.net 画曲线
JVS轻应用的组成与配置
Service discovery of kubernetes
Redis学习笔记-3.慢查询和其他高级数据结构
cesium-Web网页优化进阶
Addition logic for SAP Commerce Cloud Product Review
纷享销客罗旭对话元气森林黄晓枫:零售数字化的终点不是创新,而是数据
Docker installs canal and mysql for simple testing and achieves cache consistency between redis and mysql
Encapsulation of conversion between Json and objects (Gson)
Use docker to build mysql master-slave
订song餐系统
Selenium自动化测试之Selenium IDE
ESP8266-Arduino编程实例-MCP9808数字温度传感器驱动
A40i/T3 uboot启动时对PMU部分初始化
线性表的基本概念
Data Lake (19): SQL API reads Kafka data and writes it to Iceberg table in real time
dosbox基础使用[通俗易懂]









