Browse Source

update readme

main
wonderfullook 2 years ago
parent
commit
c1f246d75b
  1. 59
      litex/readme.md
  2. 50
      ws2812/src/ws2812.v

59
litex/readme.md

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
# Litex
## What is this firmware
This firmware is generate on litex.
[The LiteX framework provides a convenient and efficient infrastructure to create FPGA Cores/SoCs, to explore various digital design architectures and create full FPGA based systems.](https://github.com/enjoy-digital/litex)
## How to use this firmware
Flash this firmware into Tang Nano 20K, both GOWIN programmer or openFPGALoader works fine.
Then open the serial port of Tang Nano 20K with 115200 baudrate, you can test the litex terminal
## How to compile this firmware by myself
Here we use ubuntu 20.04 as the system to compile this firmware.
1. Get litex
2. Install litex
3. Get Gowin toolchain
4. Compile the firmware
### Get litex
```bash
mkdir ~/litex
cd ~/litex
wget https://raw.githubusercontent.com/enjoy-digital/litex/master/litex_setup.py
```
### Install litex
```bash
cd ~/litex
chmod +x litex_setup.py
python ./litex_setup.py --init --install --user `whoami` --config=full
```
### Get Gowin toolchain
Get GOWIN IDE ([Chinese](http://www.gowinsemi.com.cn/faq.aspx) | [English](https://www.gowinsemi.com/en/support/download_eda/)).
Here we use Education edition IDE as the example, make sure that your IDE is V1.9.8.11 version or newer. Otherwise you need license or your IDE does not support Tang Nano 20K FPGA Chip GW2AR-QN88C6I5
```bash
mkdir ~/gowin
cd ~/gowin
wget http://cdn.gowinsemi.com.cn/Gowin_V1.9.8.11_Education_linux.tar.gz
tar zxvf Gowin_V1.9.8.11_Education_linux.tar.gz
export PATH=~/gowin/IDE/bin:$PATH # Add gowin toolchain PATH
```
### Compile the firmware
```bash
cd ~/litex
python3 -m litex_boards.targets.sipeed_tang_nano_20k --build
```

50
ws2812/src/ws2812.v

@ -1,46 +1,52 @@ @@ -1,46 +1,52 @@
module top (
input clk, //输入 时钟源
input clk, // input clock source
output reg WS2812 //输出到WS2812的接口
output reg WS2812 // output to the interface of WS2812
);
parameter WS2812_NUM = 1 - 1 ; // WS2812的LED数量(1从0开始)
parameter WS2812_WIDTH = 24 ; // WS2812的数据位宽
parameter CLK_FRE = 27_000_000 ; // CLK的频率(mHZ)
parameter DELAY_1_HIGH = (CLK_FRE / 1_000_000 * 0.85 ) - 1; //850ns±150ns 1 高电平时间
parameter DELAY_1_LOW = (CLK_FRE / 1_000_000 * 0.40 ) - 1; //400ns±150ns 1 低电平时间
parameter DELAY_0_HIGH = (CLK_FRE / 1_000_000 * 0.40 ) - 1; //400ns±150ns 0 高电平时间
parameter DELAY_0_LOW = (CLK_FRE / 1_000_000 * 0.85 ) - 1; //850ns±150ns 0 低电平时间
parameter DELAY_RESET = (CLK_FRE / 10 ) - 1; //0.1s 复位时间 50us
parameter WS2812_NUM = 0 ; // LED number of WS2812 (starts from 0)
parameter WS2812_WIDTH = 24 ; // WS2812 data bit width
parameter CLK_FRE = 27_000_000 ; // CLK frequency (mHZ)
parameter RESET = 0; //状态机声明
parameter DELAY_1_HIGH = (CLK_FRE / 1_000_000 * 0.85 ) - 1; //850ns±150ns 1 high level time
parameter DELAY_1_LOW = (CLK_FRE / 1_000_000 * 0.40 ) - 1; //400ns±150ns 1 low level time
parameter DELAY_0_HIGH = (CLK_FRE / 1_000_000 * 0.40 ) - 1; //400ns±150ns 0 high level time
parameter DELAY_0_LOW = (CLK_FRE / 1_000_000 * 0.85 ) - 1; //850ns±150ns 0 low level time
parameter DELAY_RESET = (CLK_FRE / 10 ) - 1; //0.1s reset time 50us
parameter RESET = 0; //state machine statement
parameter DATA_SEND = 1;
parameter BIT_SEND_HIGH = 2;
parameter BIT_SEND_LOW = 3;
reg [ 1:0] state = 0; // synthesis preserve //主状态机控制
reg [ 8:0] bit_send = 0; // amount of bit sent // increase it for larger led strips/matrix
reg [ 8:0] data_send = 0; // amount of data sent // increase it for larger led strips/matrix
reg [31:0] clk_count = 0; // 延时控制
reg [23:0] WS2812_data = 24'd1; // WS2812的颜色数据
parameter INIT_DATA = 24'b1111; // initial pattern
reg [ 1:0] state = 0; // synthesis preserve - main state machine control
reg [ 8:0] bit_send = 0; // number of bits sent - increase for larger led strips/matrix
reg [ 8:0] data_send = 0; // number of data sent - increase for larger led strips/matrix
reg [31:0] clk_count = 0; // delay control
reg [23:0] WS2812_data = 0; // WS2812 color data
always@(posedge clk)
case (state)
RESET:begin
WS2812 <= 0;
if (clk_count < DELAY_RESET)
if (clk_count < DELAY_RESET) begin
clk_count <= clk_count + 1;
end
else begin
clk_count <= 0;
WS2812_data <= {WS2812_data[22:0],WS2812_data[23]};//颜色移位循环显示
if (WS2812_data == 0)
WS2812_data <= INIT_DATA;
else
WS2812_data <= {WS2812_data[22:0],WS2812_data[23]}; //color shift cycle display
state <= DATA_SEND;
end
end
DATA_SEND:
if (data_send == WS2812_NUM && bit_send == WS2812_WIDTH)begin
if (data_send > WS2812_NUM && bit_send == WS2812_WIDTH)begin
clk_count <= 0;
data_send <= 0;
bit_send <= 0;
state <= RESET;
@ -48,7 +54,7 @@ always@(posedge clk) @@ -48,7 +54,7 @@ always@(posedge clk)
else if (bit_send < WS2812_WIDTH) begin
state <= BIT_SEND_HIGH;
end
else begin// if (bit_send == WS2812_WIDTH)
else begin
data_send <= data_send + 1;
bit_send <= 0;
state <= BIT_SEND_HIGH;

Loading…
Cancel
Save