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

边栏推荐
- 【核心概念】图像分类和目标检测中的正负样本划分以及架构理解
- Exploring Plain Vision Transformer Backbones for Object Detection 论文阅读笔记
- 关于IDEA开发工具的介绍
- 在 Excel 内使用 ODBC 消费 SAP ABAP CDS view
- Quickly learn database management
- 基于稳态视觉诱发电位和注意力脑电的混合脑机接口系统
- am335x 看门狗驱动&看门狗应用例程序
- DCM middleware family welcomes a new member
- ipv4和ipv6对比(IPV4)
- WPF中报错:“未将对象引用设置到对象的实例。”
猜你喜欢

Mysql环境变量的配置(详细图解)

AWS Amazon cloud account registration, free application for 12 months Amazon cloud server detailed tutorial

普林斯顿微积分读本03第二章--编程实现函数图像绘制、三角学回顾

Use docker to build mysql master-slave

字符函数和字符串函数

ApiPost is really fragrant and powerful, it's time to throw away Postman and Swagger

消息队列面试题(2022最新整理)

imx6ull看门狗使用

Docker build Mysql master-slave replication

The 2nd activity of the TOGAF10 Standard Reading Club continues wonderfully, and the highlights will be reviewed!
随机推荐
How to correctly write the binary stream of the file returned by the server to the local file and save it as a file
kubernetes之服务发现
ipv4和ipv6对比(IPV4)
imx6ull看门狗使用
学习爬虫之Scrapy框架学习(1)---Scrapy框架初学习及豆瓣top250电影信息获取的实战!
Selenium自动化测试之Selenium IDE
Is the working process of the belt you know the story - actionreducerstore
Json和对象之间转换的封装(Gson)
MySQL日志中“binlog”的三种格式玩起来真爽
Indoor real-time laser SLAM control method based on biological excitation neural network
线性表的基本概念
一周精彩内容分享(第14期)
Acwing第 62 场周赛【未完结】
VBA输出日志到工作簿demo
列表页优化思路
亲测可用!!!WPF中遍历整个窗口的所有TextBox组件,对每个输入框做非空判断。
Use Excel to read data exposed by SAP ABAP CDS View through ODBC
Use docker to build mysql master-slave
这款悄然崛起的国产API接口管理工具,你一定要晓得
Docker实践经验:Docker 上部署 mysql8 主从复制