当前位置:网站首页>Chapter003 FPGA learning PWM LED breathing lamp
Chapter003 FPGA learning PWM LED breathing lamp
2022-07-21 03:53:00 【ASWaterbenben】
Hardware principle
The above equipment is similar to FPGA The comparison table of pins is as follows :
equipment | Pin name | Corresponding FPGA Pin |
---|---|---|
LED0 | PL_LED | J16 |
Reset | sys_rst | N16 |
The clock | sys_clk | U18 |
Design objectives
The design goal is to make the above LED To achieve the effect of breathing lamp
The core goal is to FPGA Implemented on PWM( Pulse width modulation ), It's different from changing PWM The duty cycle in the cycle changes the equivalent voltage , Final realization LED The breathing effect of the lamp .【 Unclear PWM And breathing lamp is what little partner can be in CSDN Take remedial classes 】
Code editing
In this experiment Verilog Language code can be implemented with only one module , Therefore, the experiment does not involve the concepts of modularity and instantiation , Edit only one code module and one constraint file .
Input content
- The system clock
- System reset ( Low level active )
Output content
- 1 individual LED The lamp
Therefore, the module code can be obtained (PWM_LED.v) as follows :
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2022/07/11 20:31:57
// Design Name:
// Module Name: PWM_LED
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module PWM_LED(
input sys_clk, // The system clock
input sys_rst_n, // System reset
output led //LED The lamp
);
reg [15:0] period_cnt; // Cycle counter frequency :1kHz cycle :1ms Count value :1ms/20ns=50000
reg [15:0] duty_cycle; // Duty cycle
reg inc_dec_flag; //0 Increasing 1 Decline
/***************************************************
main code
****************************************************/
// Output according to the relationship between duty cycle and counter value LED
assign led = (period_cnt >= duty_cycle) ? 1'b1 : 1'b0;
// Cycle counter
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)
period_cnt <= 16'd0;
else if(period_cnt == 16'd50000)
period_cnt <= 16'd0;
else
period_cnt <= period_cnt + 1'b1;
end
// Increase or decrease the duty cycle at the beat of the cycle counter
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
duty_cycle <= 16'b0;
inc_dec_flag <= 1'b0;
end
else begin
if(period_cnt == 16'd50000)begin // timing 1ms
if(inc_dec_flag == 1'd0)begin // Incremental mode
if(duty_cycle == 16'd50000)
inc_dec_flag <= 1'd1;
else
duty_cycle <= duty_cycle + 16'd25;
end
else begin
if(duty_cycle == 16'd0)
inc_dec_flag <= 1'd0;
else
duty_cycle <= duty_cycle - 16'd25;
end
end
end
end
endmodule
Constraint code
#IO constraint
set_property IOSTANDARD LVCMOS33 [get_ports led]
set_property IOSTANDARD LVCMOS33 [get_ports sys_clk]
set_property IOSTANDARD LVCMOS33 [get_ports sys_rst_n]
set_property PACKAGE_PIN U18 [get_ports sys_clk]
set_property PACKAGE_PIN N16 [get_ports sys_rst_n]
set_property PACKAGE_PIN J16 [get_ports led]
At this point, a binary stream is generated , And download ( I don't know how to download it. See you Chapter001)
experimental result
Second from top to bottom LED The lamp has a breathing effect , So the experiment was successful !
边栏推荐
- 矿业工程毕业论文题目
- 城市规划设计毕业论文范文
- 【CANN訓練營】基於昇思的GAN實現隨筆
- (6) Pytorch deep learning: loading datasets
- Detection model of 2D target detection overview (2)
- 深度学习笔记——卷积层和池化层的一些“冷门”小知识点
- After xshell is installed, an error is reported when starting: mfc110 cannot be found DLL, unable to continue code execution. Reinstalling the program may fix this problem
- SQL subquery
- [système robotique Ros] navigation autonome + détection de cibles Yolo + annonce vocale
- 第一章 关于Mask R-CNN及课程初衷
猜你喜欢
随机推荐
Tensorflow 1 based on Huawei self-developed NPU ascend 910 X training script migration and enable mixed accuracy recording
Application practice of shengteng industrial quality inspection
玩转CANN目标检测与识别一站式方案【基础篇】
Pytorch实现手写数字识别 | MNIST数据集(CNN卷积神经网络)
SourceTree对代码版本管理的操作流程及故障处理(不定时更新)
Chapter003-FPGA学习之PWM的LED呼吸灯
运算放大器的简要理解
Understand the seperable revolution
理解WGAN 和 Spectral Normalization(归一化)
[cann training camp] AI CPU operator development based on shengteng cann platform
stm32板间串口通信escape协议
Spark SQL case (I)
[système robotique Ros] navigation autonome + détection de cibles Yolo + annonce vocale
RIoTBoard开发板系列笔记(七)—— Framebuffer的使用
Understand wgan and spectral normalization
(6) Pytorch deep learning: loading datasets
微分与梯度的概念理解
[cann training camp] cann training camp_ Shengteng AI interesting application realizes AI interesting application (Part 1) essay
RIoTBoard开发板系列笔记(四)—— 使用VPU硬件解码
Chapter006-FPGA学习之LCD显示