gesture ws2812
commit
ebda40a5cd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,72 @@
|
||||
module ges_ws2812(
|
||||
input wire sys_clk ,
|
||||
input wire sys_rst_n ,
|
||||
|
||||
output wire scl ,
|
||||
inout wire sda ,
|
||||
output wire [3: 0] led ,
|
||||
output wire dout
|
||||
);
|
||||
wire [2: 0] step ;
|
||||
wire [5: 0] cfg_num ;
|
||||
wire [15: 0] cfg_data ;
|
||||
wire cfg_start ;
|
||||
wire i2c_clk ;
|
||||
wire i2c_start ;
|
||||
wire [7: 0] po_data ;
|
||||
wire [3: 0] ges_data ;
|
||||
wire bit ;
|
||||
wire [4: 0] cnt_bit ;
|
||||
wire [6: 0] cnt_pixel ;
|
||||
assign ges_data = po_data[3: 0];
|
||||
|
||||
paj7620_cfg paj7620_cfg_inst(
|
||||
.i2c_clk (i2c_clk ),
|
||||
.sys_rst_n (sys_rst_n ),
|
||||
.cfg_start (cfg_start ),
|
||||
.step (step ),
|
||||
|
||||
.cfg_num (cfg_num ),
|
||||
.cfg_data (cfg_data ),
|
||||
.i2c_start (i2c_start )
|
||||
);
|
||||
i2c_ctrl i2c_ctrl_inst(
|
||||
.sys_clk (sys_clk ),
|
||||
.sys_rst_n (sys_rst_n ),
|
||||
.i2c_start (i2c_start ),
|
||||
.cfg_num (cfg_num ),
|
||||
.cfg_data (cfg_data ),
|
||||
|
||||
.cfg_start (cfg_start ),
|
||||
.step (step ),
|
||||
.i2c_clk (i2c_clk ),
|
||||
.scl (scl ),
|
||||
.sda (sda ),
|
||||
.po_data (po_data )
|
||||
|
||||
);
|
||||
led_ctrl led_ctrl_inst(
|
||||
.sys_clk (sys_clk ),
|
||||
.sys_rst_n (sys_rst_n ),
|
||||
.ges_data (ges_data ),
|
||||
|
||||
.led (led )
|
||||
);
|
||||
|
||||
ws2812_ctrl ws2812_ctrl_inst(
|
||||
.sys_clk (sys_clk ),
|
||||
.sys_rst_n (sys_rst_n ),
|
||||
.bit (bit ),//01数据
|
||||
|
||||
.cnt_bit (cnt_bit ),
|
||||
.cnt_pixel (cnt_pixel ),
|
||||
.dout (dout )
|
||||
);
|
||||
data_cfg data_cfg_inst(
|
||||
.cnt_bit (cnt_bit ),
|
||||
.cnt_pixel (cnt_pixel ),
|
||||
.ges_data (ges_data ),
|
||||
|
||||
.bit (bit )
|
||||
);
|
||||
endmodule
|
@ -0,0 +1,17 @@
|
||||
module led_ctrl(
|
||||
input wire sys_clk ,
|
||||
input wire sys_rst_n ,
|
||||
input wire [3: 0] ges_data ,
|
||||
|
||||
output reg [3: 0] led
|
||||
);
|
||||
always @(posedge sys_clk or negedge sys_rst_n)begin
|
||||
if(!sys_rst_n)begin
|
||||
led <= 4'b0000;
|
||||
end
|
||||
else begin
|
||||
led <= ges_data;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
@ -0,0 +1,86 @@
|
||||
module paj7620_cfg(
|
||||
input wire i2c_clk ,
|
||||
input wire sys_rst_n ,
|
||||
input wire cfg_start ,
|
||||
input wire [2: 0] step ,
|
||||
|
||||
output reg [5: 0] cfg_num ,
|
||||
output wire [15: 0] cfg_data ,
|
||||
output reg i2c_start
|
||||
);
|
||||
wire [15: 0] cfg_data_reg[50: 0];
|
||||
always @(posedge i2c_clk or negedge sys_rst_n)begin
|
||||
if(!sys_rst_n)begin
|
||||
cfg_num <= 6'd0;
|
||||
end
|
||||
else if((cfg_start == 1'b1) && (step == 3'd4))begin
|
||||
cfg_num <= cfg_num + 1'd1;
|
||||
end
|
||||
else begin
|
||||
cfg_num <= cfg_num;
|
||||
end
|
||||
end
|
||||
always @(posedge i2c_clk or negedge sys_rst_n)begin
|
||||
if(!sys_rst_n)begin
|
||||
i2c_start <= 1'b0;
|
||||
end
|
||||
else if((cfg_data == 1'b1) && (step == 3'd4))begin
|
||||
i2c_start <= 1'b1;
|
||||
end
|
||||
else begin
|
||||
i2c_start <= 1'b0;
|
||||
end
|
||||
end
|
||||
assign cfg_data = (step == 3'd4) ? cfg_data_reg[cfg_num - 1]:16'h0;
|
||||
assign cfg_data_reg[00] = {8'hEF,8'h00};
|
||||
assign cfg_data_reg[01] = {8'h37,8'h07};
|
||||
assign cfg_data_reg[02] = {8'h38,8'h17};
|
||||
assign cfg_data_reg[03] = {8'h39,8'h06};
|
||||
assign cfg_data_reg[04] = {8'h42,8'h01};
|
||||
assign cfg_data_reg[05] = {8'h46,8'h2D};
|
||||
assign cfg_data_reg[06] = {8'h47,8'h0F};
|
||||
assign cfg_data_reg[07] = {8'h48,8'h3C};
|
||||
assign cfg_data_reg[08] = {8'h49,8'h00};
|
||||
assign cfg_data_reg[09] = {8'h4A,8'h1E};
|
||||
assign cfg_data_reg[10] = {8'h4C,8'h20};
|
||||
assign cfg_data_reg[11] = {8'h51,8'h10};
|
||||
assign cfg_data_reg[12] = {8'h5E,8'h10};
|
||||
assign cfg_data_reg[13] = {8'h60,8'h27};
|
||||
assign cfg_data_reg[14] = {8'h80,8'h42};
|
||||
assign cfg_data_reg[15] = {8'h81,8'h44};
|
||||
assign cfg_data_reg[16] = {8'h82,8'h04};
|
||||
assign cfg_data_reg[17] = {8'h8B,8'h01};
|
||||
assign cfg_data_reg[18] = {8'h90,8'h06};
|
||||
assign cfg_data_reg[19] = {8'h95,8'h0A};
|
||||
assign cfg_data_reg[20] = {8'h96,8'h0C};
|
||||
assign cfg_data_reg[21] = {8'h97,8'h05};
|
||||
assign cfg_data_reg[22] = {8'h9A,8'h14};
|
||||
assign cfg_data_reg[23] = {8'h9C,8'h3F};
|
||||
assign cfg_data_reg[24] = {8'hA5,8'h19};
|
||||
assign cfg_data_reg[25] = {8'hCC,8'h19};
|
||||
assign cfg_data_reg[26] = {8'hCD,8'h0B};
|
||||
assign cfg_data_reg[27] = {8'hCE,8'h13};
|
||||
assign cfg_data_reg[28] = {8'hCF,8'h64};
|
||||
assign cfg_data_reg[29] = {8'hD0,8'h21};
|
||||
assign cfg_data_reg[30] = {8'hEF,8'h01};
|
||||
assign cfg_data_reg[31] = {8'h02,8'h0F};
|
||||
assign cfg_data_reg[32] = {8'h03,8'h10};
|
||||
assign cfg_data_reg[33] = {8'h04,8'h02};
|
||||
assign cfg_data_reg[34] = {8'h25,8'h01};
|
||||
assign cfg_data_reg[35] = {8'h27,8'h39};
|
||||
assign cfg_data_reg[36] = {8'h28,8'h7F};
|
||||
assign cfg_data_reg[37] = {8'h29,8'h08};
|
||||
assign cfg_data_reg[38] = {8'h3E,8'hFF};
|
||||
assign cfg_data_reg[39] = {8'h5E,8'h3D};
|
||||
assign cfg_data_reg[40] = {8'h65,8'h96};
|
||||
assign cfg_data_reg[41] = {8'h67,8'h97};
|
||||
assign cfg_data_reg[42] = {8'h69,8'hCD};
|
||||
assign cfg_data_reg[43] = {8'h6A,8'h01};
|
||||
assign cfg_data_reg[44] = {8'h6D,8'h2C};
|
||||
assign cfg_data_reg[45] = {8'h6E,8'h01};
|
||||
assign cfg_data_reg[46] = {8'h72,8'h01};
|
||||
assign cfg_data_reg[47] = {8'h73,8'h35};
|
||||
assign cfg_data_reg[48] = {8'h74,8'h00};
|
||||
assign cfg_data_reg[49] = {8'h77,8'h01};
|
||||
assign cfg_data_reg[50] = {8'hEF,8'h00};
|
||||
endmodule
|
@ -0,0 +1,161 @@
|
||||
module ws2812_ctrl(
|
||||
input wire sys_clk ,
|
||||
input wire sys_rst_n ,
|
||||
input wire bit ,//01数据
|
||||
|
||||
output reg [4: 0] cnt_bit ,
|
||||
output reg [6: 0] cnt_pixel ,
|
||||
output wire dout
|
||||
);
|
||||
parameter T0H = 30 ,
|
||||
T0L = 15 ,
|
||||
T1H = 30 ,
|
||||
T1L = 30 ,
|
||||
RST = 15000 ;
|
||||
reg [5: 0] cnt_0 ;//bit0计数器
|
||||
wire add_cnt_0 ;
|
||||
wire end_cnt_0 ;
|
||||
|
||||
reg [5: 0] cnt_1 ;//bit1计数器
|
||||
wire add_cnt_1 ;
|
||||
wire end_cnt_1 ;
|
||||
|
||||
//RGB计数器
|
||||
wire add_cnt_bit ;
|
||||
wire end_cnt_bit ;
|
||||
|
||||
//64个像素计数器
|
||||
wire add_cnt_pixel;
|
||||
wire end_cnt_pixel;
|
||||
|
||||
reg [13: 0] cnt_rst ;//复位计数器
|
||||
wire add_cnt_rst ;
|
||||
wire end_cnt_rst ;
|
||||
reg flag_0 ;
|
||||
reg flag_1 ;
|
||||
reg flag_rst ;
|
||||
//bit0计数器设计
|
||||
always @(posedge sys_clk or negedge sys_rst_n) begin
|
||||
if(!sys_rst_n)begin
|
||||
cnt_0 <= 0;
|
||||
end
|
||||
else if(add_cnt_0)begin
|
||||
if(end_cnt_0)begin
|
||||
cnt_0 <= 0;
|
||||
end
|
||||
else begin
|
||||
cnt_0 <= cnt_0 + 1;
|
||||
end
|
||||
end
|
||||
else begin
|
||||
cnt_0 <= 0;
|
||||
end
|
||||
end
|
||||
assign add_cnt_0 = flag_0 && flag_rst != 1'b1;
|
||||
assign end_cnt_0 = add_cnt_0 && (cnt_0 == T0H + T0L -1);
|
||||
//bit1计数器设计
|
||||
always @(posedge sys_clk or negedge sys_rst_n) begin
|
||||
if(!sys_rst_n)begin
|
||||
cnt_1 <= 0;
|
||||
end
|
||||
else if(add_cnt_1)begin
|
||||
if(end_cnt_1)begin
|
||||
cnt_1 <= 0;
|
||||
end
|
||||
else begin
|
||||
cnt_1 <= cnt_1 + 1;
|
||||
end
|
||||
end
|
||||
else begin
|
||||
cnt_1 <= 0;
|
||||
end
|
||||
end
|
||||
assign add_cnt_1 = flag_1 && flag_rst != 1'b1;
|
||||
assign end_cnt_1 = add_cnt_1 && (cnt_1 == T1H + T1L -1);
|
||||
//RGB计数器设计
|
||||
always @(posedge sys_clk or negedge sys_rst_n)begin
|
||||
if(!sys_rst_n)begin
|
||||
cnt_bit <= 0;
|
||||
end
|
||||
else if(add_cnt_bit)begin
|
||||
if(end_cnt_bit)begin
|
||||
cnt_bit <= 0;
|
||||
end
|
||||
else begin
|
||||
cnt_bit <= cnt_bit + 1;
|
||||
end
|
||||
end
|
||||
else begin
|
||||
cnt_bit <= cnt_bit;
|
||||
end
|
||||
end
|
||||
assign add_cnt_bit = end_cnt_0 || end_cnt_1;
|
||||
assign end_cnt_bit = add_cnt_bit && (cnt_bit == 5'd23);
|
||||
//64个像素计数器设计
|
||||
always @(posedge sys_clk or negedge sys_rst_n)begin
|
||||
if(!sys_rst_n)begin
|
||||
cnt_pixel <= 0;
|
||||
end
|
||||
else if(add_cnt_pixel)begin
|
||||
if(end_cnt_pixel)begin
|
||||
cnt_pixel <= 0;
|
||||
end
|
||||
else begin
|
||||
cnt_pixel <= cnt_pixel + 1;
|
||||
end
|
||||
end
|
||||
else begin
|
||||
cnt_pixel <= cnt_pixel;
|
||||
end
|
||||
end
|
||||
assign add_cnt_pixel = end_cnt_bit;
|
||||
assign end_cnt_pixel = add_cnt_pixel && (cnt_pixel == 7'd63);
|
||||
//复位计数器设计
|
||||
always @(posedge sys_clk or negedge sys_rst_n)begin
|
||||
if(!sys_rst_n)begin
|
||||
cnt_rst <= 0;
|
||||
end
|
||||
else if(add_cnt_rst)begin
|
||||
if(end_cnt_rst)begin
|
||||
cnt_rst <= 0;
|
||||
end
|
||||
else begin
|
||||
cnt_rst <= cnt_rst + 1;
|
||||
end
|
||||
end
|
||||
else begin
|
||||
cnt_rst <= 0;
|
||||
end
|
||||
end
|
||||
assign add_cnt_rst = flag_rst;
|
||||
assign end_cnt_rst = add_cnt_rst && (cnt_rst == RST - 1);
|
||||
//01判断器
|
||||
always @(*)begin
|
||||
case(bit)
|
||||
0: begin
|
||||
flag_0 = 1;
|
||||
flag_1 = 0;
|
||||
end
|
||||
1: begin
|
||||
flag_0 = 0;
|
||||
flag_1 = 1;
|
||||
end
|
||||
endcase
|
||||
end
|
||||
//flag_rst约束
|
||||
always @(posedge sys_clk or negedge sys_rst_n)begin
|
||||
if(!sys_rst_n)begin
|
||||
flag_rst <= 0;
|
||||
end
|
||||
else if(end_cnt_pixel)begin
|
||||
flag_rst <= 1;
|
||||
end
|
||||
else if(end_cnt_rst)begin
|
||||
flag_rst <= 0;
|
||||
end
|
||||
else begin
|
||||
flag_rst <= flag_rst;
|
||||
end
|
||||
end
|
||||
assign dout = (flag_rst != 1'b1)? (((bit == 0) && (cnt_0 < T0L)) || ((bit == 1) &&(cnt_1 < T1L))): 1'b0;
|
||||
endmodule
|
@ -0,0 +1,29 @@
|
||||
# Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
# Your use of Intel Corporation's design tools, logic functions
|
||||
# and other software and tools, and its AMPP partner logic
|
||||
# functions, and any output files from any of the foregoing
|
||||
# (including device programming or simulation files), and any
|
||||
# associated documentation or information are expressly subject
|
||||
# to the terms and conditions of the Intel Program License
|
||||
# Subscription Agreement, the Intel Quartus Prime License Agreement,
|
||||
# the Intel FPGA IP License Agreement, or other applicable license
|
||||
# agreement, including, without limitation, that your use is for
|
||||
# the sole purpose of programming logic devices manufactured by
|
||||
# Intel and sold by Intel or its authorized distributors. Please
|
||||
# refer to the applicable agreement for further details.
|
||||
|
||||
# Quartus Prime Version 18.1.0 Build 625 09/12/2018 SJ Lite Edition
|
||||
# File: C:\Users\Stark-lin\Desktop\gesture_ws2812\tcl\gesture_ws2812.tcl
|
||||
# Generated on: Thu Apr 18 09:26:34 2024
|
||||
|
||||
package require ::quartus::project
|
||||
|
||||
set_location_assignment PIN_E15 -to sys_rst_n
|
||||
set_location_assignment PIN_E1 -to sys_clk
|
||||
set_location_assignment PIN_D8 -to scl
|
||||
set_location_assignment PIN_E7 -to sda
|
||||
set_location_assignment PIN_K6 -to dout
|
||||
set_location_assignment PIN_G15 -to led[0]
|
||||
set_location_assignment PIN_F16 -to led[1]
|
||||
set_location_assignment PIN_F15 -to led[2]
|
||||
set_location_assignment PIN_D16 -to led[3]
|
Loading…
Reference in New Issue