本文介绍: 【代码北邮22级信通院数电:Verilog-FPGA(12)第十二周实验(2)彩虹呼吸灯

北邮22信通一枚~

跟随课程进度更新北邮信通数字系统设计笔记代码文章

持续关注作者 迎接数电实验学习~

获取更多文章,请访问专栏

北邮22级信通院数电实验_青山如墨雨如画的博客-CSDN博客

目录

一.代码部分

 二.管脚分配

三.实验效果


一.代码部分

rainbow_breathing_light.v

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进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注