北邮22信通一枚~
北邮22级信通院数电实验_青山如墨雨如画的博客-CSDN博客
一.代码部分
module pwm
(
input [7:0] duty,
input clk,
output reg out
);
reg [7:0] buffer;
always @ (posedge clk)
begin
buffer <= buffer + 1;
if(buffer < duty)
begin out <= 0;end
else
begin out <= 1;end
end
endmodule
module rainbow_breathing_light
(clk,red,green,blue);
input clk;
output red,green,blue;
reg [15:0] wheel_position;
reg [7:0] wheel_position_buffer;
reg [7:0] red_buffer,green_buffer,blue_buffer;
reg [31:0] divide_buffer;
wire clk;
reg divide_clk;
pwm pwm_red(red,red_buffer,clk);
pwm pwm_green(green,green_buffer,clk);
pwm pwm_blue(blue,blue_buffer,clk);
always @ (posedge clk)
begin
if(divide_buffer < 50000)
begin divide_buffer <= divide_buffer + 1;end
else
begin
divide_clk <= ~divide_clk;
divide_buffer <= 0;
end
end
always @ (posedge divide_clk)
begin
if(wheel_position < 765)
wheel_position <= wheel_position + 1;
else
wheel_position <= 0;
if(wheel_position < 255)
begin
red_buffer <= 255 - wheel_position;
green_buffer <= 0;
blue_buffer <= wheel_position;
end
else if(wheel_position < 510)
begin
red_buffer <= 0;
green_buffer <= wheel_position - 255;
blue_buffer <= 255 - (wheel_position - 255);
end
else
begin
red_buffer <= wheel_position - 510;
green_buffer <= 255 - (wheel_position - 510);
blue_buffer <= 0;
end
end
endmodule
二.管脚分配
三.实验效果
彩虹呼吸灯。
原文地址:https://blog.csdn.net/bc202205/article/details/134735140
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_27054.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。