当前位置:网站首页>手撕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
仿真结果

边栏推荐
- Cognitive-exercise rehabilitation medical robot application design
- 线性表的基本概念
- 订song餐系统
- MySQL日志中“binlog”的三种格式玩起来真爽
- imx6ull看门狗使用
- PAT exam summary (exam experience)
- Docker build Mysql master-slave replication
- Data Lake (19): SQL API reads Kafka data and writes it to Iceberg table in real time
- busybox之reboot命令流程分析
- 【Shader】Shader官方示例[通俗易懂]
猜你喜欢

MySQL row-level locks (row locks, adjacent key locks, gap locks)

MySql模糊查询大全

想吃菌子,当然是自己上山找了

DCM middleware family welcomes a new member

Exploring Plain Vision Transformer Backbones for Object Detection Paper Reading Notes

JVS轻应用的组成与配置

deeplab implements its own remote sensing geological segmentation dataset

mysql根据多字段分组——group by带两个或多个参数

Docker build Mysql master-slave replication

The item 'node.exe' was not recognized as the name of a cmdlet, function, script file, or runnable program.
随机推荐
jmeter性能测试步骤入门(性能测试工具jmeter)
am335x 看门狗驱动&看门狗应用例程序
0x80070570 The file or directory is damaged and cannot be deleted (how to delete 0x80070091)
科学论文和学术论文写作
带有对称约束切换线性系统的结构可控性
Quickly learn database management
Initial JDBC programming
R语言:文本(字符串)处理与正则表达式
A40i/T3 uboot启动时对PMU部分初始化
The 2nd activity of the TOGAF10 Standard Reading Club continues wonderfully, and the highlights will be reviewed!
Json和对象之间转换的封装(Gson)
Docker搭建Mysql主从复制
Data Lake (19): SQL API reads Kafka data and writes it to Iceberg table in real time
ipv4和ipv6对比(IPV4)
认知—运动康复医疗机器人应用设计
PAT exam summary (exam experience)
Wearing detection and action recognition of protective gear based on pose estimation
关于==和equals的区别和联系,面试这么回答就可以
apisix-Getting Started
Markdown编辑器语法