当前位置:网站首页>手撕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
仿真结果
边栏推荐
- Addition logic for SAP Commerce Cloud Product Review
- Docker practical experience: Deploy mysql8 master-slave replication on Docker
- A Week of Wonderful Content Sharing (Issue 14)
- Three-Phase PWM Rectifier Predictive Direct Power Control
- 列表页优化思路
- Use Excel to read data exposed by SAP ABAP CDS View through ODBC
- JVS设置不同应用的登录时效时间
- A40i/T3 uboot启动时对PMU部分初始化
- MySQL limit paging query and performance issues
- AWS Amazon cloud account registration, free application for 12 months Amazon cloud server detailed tutorial
猜你喜欢
Power BI----几个常用的分析方法和相适应的视觉对象
生信周刊第38期
AWS Amazon cloud account registration, free application for 12 months Amazon cloud server detailed tutorial
imx6ull看门狗使用
JVS设置不同应用的登录时效时间
Exploring Plain Vision Transformer Backbones for Object Detection 论文阅读笔记
Spark GC日志分析
Service discovery of kubernetes
chroot命令
TOGAF10标准读书会第2场活动精彩继续,高光时刻回顾!
随机推荐
Quickly learn database management
ipv4和ipv6对比(IPV4)
[core]-ARMV7-A, ARMV8-A, ARMV9-A Architecture Introduction "Recommended Collection"
三六零与公安部三所发布报告:关基设施保护成为网络安全博弈关键
关于IDEA开发工具的介绍
在 Excel 里使用 ODBC 读取 SAP BTP 平台上 CDS view 的数据
Structural controllability of switched linear systems with symmetry constraints
最近两个月谷歌 ad 掉的厉害
After Effects 教程,如何在 After Effects 中修复曝光不足的镜头?
DCM 中间件家族迎来新成员
榕树贷款GPU 硬件架构
A Week of Wonderful Content Sharing (Issue 14)
Chrome开发自定义右键菜单实现快速跳转到指定页面
CWE4.8 -- 2022年危害最大的25种软件安全问题
多线程学习笔记-2.final关键字和不变性
R 语言data.frame 中的另一行中减去一行
The item 'node.exe' was not recognized as the name of a cmdlet, function, script file, or runnable program.
Addition logic for SAP Commerce Cloud Product Review
Hybrid brain-computer interface system based on steady-state visual evoked potentials and attentional EEG
Comparison of ipv4 and ipv6 (IPV4)