如何在阿里云云服务器上搭建网站,网站建设工作室有几个部门,收费用的网站怎么做,自做网站好做吗一#xff0c;系统架构 二#xff0c;芯片介绍
1.管脚说明 2.数据传输时间 3.时序波形 4.数据传输方法 5.常用电路连接 三#xff0c;代码展示及说明
驱动模块 在驱动模块首先选择使用状态机#xff0c;其中包括#xff0c;空闲状态#xff0c;复位清空状态#xff0c…一系统架构 二芯片介绍
1.管脚说明 2.数据传输时间 3.时序波形 4.数据传输方法 5.常用电路连接 三代码展示及说明
驱动模块 在驱动模块首先选择使用状态机其中包括空闲状态复位清空状态和读数据状态其中空闲状态是向fifo中写入数据复位清空状态是清空ws2812b中的数据读数据状态是讲fifo中存的数据依次读到ws2812b中以这样的流程来达到对ws2812b的控制以下是我的驱动代码
/**************************************功能介绍***********************************
Date :
Author : WZY.
Version :
Description: 这是项目的逻辑状态机模块
*********************************************************************************///---------模块及端口声名------------------------------------------------------
module state( input wire clk ,input wire rst_n ,input wire [23:0] data_in ,input wire fifo_wr_vld,output reg ws2812b_io ,output wire ready
);
//---------参数定义--------------------------------------------------------- //状态机参数定义parameter IDLE 3b001,//空闲状态RST 3b010,//复位状态DATA 3b100;//数据传输状态 //---------内部信号定义-----------------------------------------------------reg [2:0] cstate ;//现态
reg [2:0] nstate ;//次态
wire idle2rst ;
wire rst2data ;
wire data2idle ;//fifoIP核参数定义
wire [23:0] fifo_wr_data;
wire [23:0] fifo_rd_data;
wire empty ;
wire full ;
wire fifo_rd_req ;
wire fifo_wr_req ;//复位参数定义
reg [14:0] cnt_rst ;
wire add_cnt_rst ;
wire end_cnt_rst ;//数据传输参数定义
reg [5:0] cnt_cyc ;
wire add_cnt_cyc ;
wire end_cnt_cyc ;reg [4:0] cnt_bit ;
wire add_cnt_bit ;
wire end_cnt_bit ;reg [5:0] cnt_num ;
wire add_cnt_num ;
wire end_cnt_num ;//****************************************************************
// 状态机
//****************************************************************//第一段时序逻辑描述状态转移
always (posedge clk or negedge rst_n)begin if(!rst_n)begincstate IDLE;end else begin cstate nstate;end
end//第二段组合逻辑描述状态转移规律和状态转移条件
always (*) begincase(cstate)IDLE : beginif (idle2rst) beginnstate RST;endelse beginnstate cstate;endendRST : beginif (rst2data) beginnstate DATA;endelse beginnstate cstate;endendDATA : beginif (data2idle) beginnstate IDLE;endelse beginnstate cstate;endenddefault : nstate IDLE;endcase
end
assign idle2rst cstate IDLE fifo_wr_vld;//当检测到读使能时由空闲状态转换到复位状态
assign rst2data cstate RST end_cnt_rst;//当复位完成后转到数据输入状态
assign data2idle cstate DATA end_cnt_num;//当数据输入完成后返回空闲状态
//第三段描述输出时序逻辑或组合逻辑皆可//****************************************************************
// IP核FIFO读取
//****************************************************************
fifo_test fifo_test_inst (.aclr ( ~rst_n ),.clock ( clk ),.data ( fifo_wr_data ),.rdreq ( fifo_rd_req ),.wrreq ( fifo_wr_req),.empty ( empty ),.full ( full ),.q ( fifo_rd_data ),.usedw ( )); assign fifo_wr_data {data_in[15:8],data_in[23:16],data_in[7:0]} ;//RGB-GRB
assign fifo_wr_req fifo_wr_vld~full;//当检测到写使能并且不为满时拉高
assign fifo_rd_req end_cnt_bit ~empty;//每次读取计时到一个数据后并且不为空时读出一个数据//****************************************************************
// 复位计时
//**************************************************************** always (posedge clk or negedge rst_n)begin if(!rst_n)begincnt_rst 15d0;end else if(add_cnt_rst)begin if(end_cnt_rst)begin cnt_rst 15d0;endelse begin cnt_rst cnt_rst 1b1;end end
end assign add_cnt_rst cstate RST;
assign end_cnt_rst add_cnt_rst cnt_rst 400_000/20 - 1;//****************************************************************
// 数据传输计时
//****************************************************************always (posedge clk or negedge rst_n)begin if(!rst_n)begincnt_cyc 6d0;end else if(add_cnt_cyc)begin if(end_cnt_cyc)begin cnt_cyc 6d0;endelse begin cnt_cyc cnt_cyc 1b1;end end
end assign add_cnt_cyc cstate DATA;
assign end_cnt_cyc add_cnt_cyc cnt_cyc 1200/20 - 1;always (posedge clk or negedge rst_n)begin if(!rst_n)begincnt_bit 5d0;end else if(add_cnt_bit)begin if(end_cnt_bit)begin cnt_bit 5d0;endelse begin cnt_bit cnt_bit 1b1;end end
end assign add_cnt_bit end_cnt_cyc;
assign end_cnt_bit add_cnt_bit cnt_bit 24-1;always (posedge clk or negedge rst_n)begin if(!rst_n)begincnt_num 6d0;end else if(add_cnt_num)begin if(end_cnt_num)begin cnt_num 6d0;endelse begin cnt_num cnt_num 1b1;end end
end assign add_cnt_num end_cnt_bit;
assign end_cnt_num add_cnt_num cnt_num 64-1;
//****************************************************************
// 用户接口
//****************************************************************always (posedge clk or negedge rst_n) begincase (cstate)IDLE : ws2812b_io 0;RST : ws2812b_io 0;DATA : beginif (fifo_rd_data[23-cnt_bit] 1) beginws2812b_io (cnt_cyc 30)?1:0;endelse beginws2812b_io (cnt_cyc15)?1:0;endenddefault: ws2812b_io 0;endcase
end//****************************************************************
// ready控制
//****************************************************************
assign ready cstate IDLE;
endmodule数据传输 接下来是数据选择传输模块这个模块同样使用到了ip核以及状态机通过三个状态空闲状态读数据状态以及延迟状态其中空闲状态下等待驱动模块准备完成跳转到读数据状态在读数据状态下根据三个计数器即横坐标纵坐标还有偏移坐标来作为ROM的地址依次向外读出数据同时驱动模块向fifo中写入数据当读取完64个数据后跳转到等待状态延迟500ms后再次回到IDLE状态并且偏移坐标1以此循环就可以达到动态显示下面是代码展示
/**************************************************************
File : ws2812_control2.v
Time : 2023/08/14 10:04:56
Author : WangHaodong
EditTool: VS Code
Font : UTF-8
Function: 显示一张图片
**************************************************************/
module ws2812_control(input clk ,input rst_n ,output [23:0] pix_data ,output pix_data_vld ,input ready //可以接收图像数据了
);parameter IDLE 0,DATA 1,DELAY 2;reg [2:0] state ;reg [5:0] cnt_x;wire add_x_cnt,end_x_cnt; reg [4:0] cnt_y;wire add_y_cnt,end_y_cnt; reg [24:0] cnt_delay ;wire add_cnt_delay ;wire end_cnt_delay ;reg [5:0] cnt_offset ;wire add_cnt_offset ;wire end_cnt_offset ;localparam RED 24hFF0000, //红色ORANGE 24hFF8000, //橙色YELLOW 24hFFFF00, //黄色GREEN 24h00FF00, //绿色CYAN 24h00FFFF, //青色BLUE 24h0000FF, //蓝色PURPPLE 24h8000FF, //紫色BLACK 24h000000, //黑色WHITE 24hFFFFFF, //白色GRAY 24hC0C0C0; //灰色
parameter MAX_500S 24_999_999;wire rom_rd_req ;wire rom_rd_data_vld ;reg rom_rd_req_r1 ;reg rom_rd_req_r2 ;/**************************************************************状态机
**************************************************************/always(posedge clk or negedge rst_n)if(!rst_n)state IDLE;else case(state)IDLE : if(ready)state DATA;DATA : if(end_y_cnt)state DELAY;DELAY : if (end_cnt_delay) state IDLE;default : state IDLE;endcase
//****************************************************************
// 延时计数器
//****************************************************************always (posedge clk or negedge rst_n)begin if(!rst_n)begincnt_delay d0;end else if(add_cnt_delay)begin if(end_cnt_delay)begin cnt_delay d0;endelse begin cnt_delay cnt_delay 1b1;end endelse begincnt_delay 0;end
end assign add_cnt_delay state DELAY;
assign end_cnt_delay add_cnt_delay cnt_delay MAX_500S;/**************************************************************图像数据个数计数器
**************************************************************/
//横坐标always(posedge clk or negedge rst_n) if(!rst_n) cnt_x d0; else if(add_x_cnt) begin if(end_x_cnt) cnt_x d0; else cnt_x cnt_x 1b1; end assign add_x_cnt state DATA;assign end_x_cnt add_x_cnt cnt_x 8 - 1;//纵坐标always(posedge clk or negedge rst_n) if(!rst_n) cnt_y d0; else if(add_y_cnt) begin if(end_y_cnt) cnt_y d0; else cnt_y cnt_y 1b1; end assign add_y_cnt end_x_cnt;assign end_y_cnt add_y_cnt cnt_y 8 - 1;//偏移量 always (posedge clk or negedge rst_n)begin if(!rst_n)begincnt_offset d0;end else if(add_cnt_offset)begin if(end_cnt_offset)begin cnt_offset d0;endelse begin cnt_offset cnt_offset 1b1;end endend assign add_cnt_offset end_cnt_delay;assign end_cnt_offset add_cnt_offset cnt_offset 31;wire[4:0] num_x;assign num_x (cnt_xcnt_offset)%32;//避免超出32的坐标限制//存放了一张图片rom rom_inst (.aclr ( ~rst_n ),.address ( cnt_y*32num_x ),.clock ( clk ),.rden (rom_rd_req),.q (pix_data));assign rom_rd_req state DATA;always(posedge clk or negedge rst_n)if(!rst_n) beginrom_rd_req_r1 0;rom_rd_req_r2 0;endelse beginrom_rd_req_r1 rom_rd_req;rom_rd_req_r2 rom_rd_req_r1;endassign rom_rd_data_vld rom_rd_req_r2;assign pix_data_vld rom_rd_data_vld;//打两拍使得读出数据和fifo中写入数据同步endmodule
3.仿真演示
仿真代码
timescale 1ns/1nsmodule state_tb();//激励信号定义 reg clk ;reg rst_n ;
//输出信号定义 wire ws2812b_io ;//时钟周期参数定义 parameter CYCLE 20; defparam top_inst.ws2812_control_inst.MAX_500S 10*CYCLE; //模块例化top top_inst(.clk (clk),.rst_n (rst_n),.ws2812b_io (ws2812b_io)
); //产生时钟initial clk 1b1;always #(CYCLE/2) clk ~ clk;//产生激励initial begin rst_n 1b1;#(CYCLE*2);rst_n 1b0;#(CYCLE*20);rst_n 1b1;#(CYCLE*1000000);$stop;endendmodule 仿真结果展示
4.结果演示