You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.4 KiB
Coq

7 months ago
module ws2812_ctrl(
7 months ago
input wire sys_clk ,
input wire sys_rst_n ,
input wire bit ,
7 months ago
7 months ago
output wire dout ,
output reg [4: 0] cnt_bit ,
output reg [6: 0] cnt_led
7 months ago
);
parameter T0H = 4'd15 ,//bit0
T0L = 6'd40 ,//bit0
T1H = 6'd40 ,//bit1
T1L = 6'd40 ,//bit1
RST = 14'd15000 ;//64led0
reg [5: 0] cnt_0;//bit0
wire add_cnt0;//bit0
wire end_cnt0;//bit0
reg [6: 0] cnt_1;//bit1
wire add_cnt1;//bit1
wire end_cnt1;//bit1
7 months ago
// reg [4: 0] cnt_bit;//24bit
7 months ago
wire add_cnt_bit;//24bit
wire end_cnt_bit;//24bit
7 months ago
// reg [6: 0] cnt_led;//64led
7 months ago
wire add_cnt_led;//64led
wire end_cnt_led;//64led
reg [13: 0] cnt_rst;//
wire add_cnt_rst;//
wire end_cnt_rst;//
reg flag_rst;//
//bit0
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
cnt_0 <= 6'd0;
end
else if(add_cnt0)begin
if(end_cnt0)begin
cnt_0 <= 6'd0;
end
else begin
cnt_0 <= cnt_0 + 1'd1;
end
end
else begin
cnt_0 <= 6'd0;
end
end
assign add_cnt0 = ~bit && flag_rst == 0;//bit0
assign end_cnt0 = add_cnt0 && (cnt_0 == T0H + T0L-1);
//cnt_1
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_1 <= 7'd0;
end
else if(add_cnt1)begin
if(end_cnt1)begin
cnt_1 <= 7'd0;
end
else begin
cnt_1 <= cnt_1 + 1'd1;
end
end
else begin
cnt_1 <= 7'd0;
end
end
assign add_cnt1 = bit && flag_rst == 0;//bit1
assign end_cnt1 = add_cnt1 && (cnt_1 == T1H + T1L-1);
//cnt_bit
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_bit <= 5'd0;
end
else if(add_cnt_bit)begin
if(end_cnt_bit)begin
cnt_bit <= 5'd0;
end
else begin
cnt_bit <= cnt_bit + 1'd1;
end
end
else begin
cnt_bit <= cnt_bit;//cnt_bit
end
end
assign add_cnt_bit = end_cnt0 || end_cnt1;//bit0bit1
assign end_cnt_bit = add_cnt_bit && (cnt_bit == 5'd23);//24bit
//cnt_led
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_led <= 7'd0;
end
else if(add_cnt_led)begin
if(end_cnt_led)begin
cnt_led <= 7'd0;
end
else begin
cnt_led <= cnt_led + 1'd1;
end
end
else begin
cnt_led <= cnt_led;
end
end
assign add_cnt_led = end_cnt_bit;
assign end_cnt_led = add_cnt_led && (cnt_led == 7'd63);
//cnt_rst
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_rst <= 14'd0;
end
else if(add_cnt_rst)begin
if(end_cnt_rst)begin
cnt_rst <= 14'd0;
end
else begin
cnt_rst <= cnt_rst + 1'd1;
end
end
else begin
cnt_rst <= cnt_rst;
end
end
assign add_cnt_rst = flag_rst;
assign end_cnt_rst = add_cnt_rst && (cnt_rst == RST - 1);
//flag_rst
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
flag_rst <= 1'b0;//0
end
else if(end_cnt_led)begin//64led
flag_rst <= 1'b1;
end
else if(end_cnt_rst)begin//
flag_rst <= 1'b0;
end
else begin
flag_rst <= flag_rst;//flag_rst
end
end
//dout
7 months ago
assign dout = (flag_rst == 0) ? (((bit == 0 && cnt_0 < T0H) ? 1'b1 : 1'b0) | ((bit == 1 && cnt_1 < T1H) ? 1'b1 : 1'b0)): 1'b0;
7 months ago
endmodule