视频教程
波形测试
波形为1,高800ns,低400ns
波形为0,低800ns,高400ns
使用50Mhz的clk输出,单边沿触发,则为25Mhz
//ws2812b测试
integer ns400cnt;
integer cnt;
integer period;
integer duty;
initial begin
cnt = 0;
ns400cnt = 0;
period = 3;
duty = 2;
end
always@(posedge c0) begin
cnt = cnt + 1;
//20cnt = 400ns
if(cnt >= 20) begin
//pinout[0] = ~pinout[0];
ns400cnt = ns400cnt + 1;
cnt = 0;
if(ns400cnt <= duty) begin
pinout[0] = 1;
end
else if(ns400cnt <= period) begin
pinout[0] = 0;
end
if(ns400cnt == period) begin
ns400cnt = 0;
end
end
end
点亮测试
always@(posedge c0) begin
//延时一会等待,内部RC振荡器稳定
if(start_flag == 0) begin
delay_cnt = delay_cnt + 1;
pinout[0] <= 0;
if(delay_cnt > 200000000) begin
start_flag = 1;
delay_cnt = 0;
end
end
if(start_flag == 1) begin
//状态控制
//cnt2代表bit的数量
if(cnt2 < 8) begin
inverse = 0;
end
else if(cnt2 >= 8 && cnt2 < 16) begin
inverse = 1;
end
else if(cnt2 >= 16 && cnt2 < 24) begin
inverse = 1;
end
//led2
else if(cnt2 >= 24 && cnt2 < 32) begin
inverse = 1;
end
else if(cnt2 >= 32 && cnt2 < 40) begin
inverse = 0;
end
else if(cnt2 >= 40 && cnt2 < 48) begin
inverse = 1;
end
//led3
else if(cnt2 >= 48 && cnt2 < 56) begin
inverse = 1;
end
else if(cnt2 >= 56 && cnt2 < 64) begin
inverse = 1;
end
else if(cnt2 >= 64 && cnt2 < 72) begin
inverse = 0;
end
//led4
else if(cnt2 >= 72 && cnt2 < 80) begin
inverse = 0;
end
else if(cnt2 >= 80 && cnt2 < 86) begin
inverse = 1;
end
else if(cnt2 >= 86 && cnt2 < 94) begin
inverse = 1;
end
//rst
else inverse = 2;
//单个bit控制
//20cnt = 400ns
cnt = cnt + 1;
if(cnt >= 20) begin
//pinout[0] = ~pinout[0];
ns400cnt = ns400cnt + 1;
cnt = 0;
if(ns400cnt <= duty) begin
if(inverse == 0) pinout[0] <= 1;
else if(inverse == 1) pinout[0] <= 0;
else pinout[0] <= 0;
end
else if(ns400cnt <= period) begin
if(inverse == 0) pinout[0] <= 0;
else if(inverse == 1) pinout[0] <= 1;
else pinout[0] <= 0;
end
if(ns400cnt == period) begin
ns400cnt = 0;
cnt2 = cnt2 + 1;
end
end
end
end
4个led灯,94bits
第一个led灯绿色
8个H,16个L