// 定义period和pulse_width寄存器的内容
always @(posedge clk or negedge clr_n)
begin
if (clr_n==0)
begin
period<=32'h 00000000;
pulse_width<=32'h 00000000;
end
else
begin
if (period_en)
period<=write_data[31:0];
else
period<=period;
if (pulse_width_en)
pulse_width<=write_data[31:0];
else
pulse_width<=pulse_width;
end
end
// period和pulse_width寄存器的读访问
always @(addr or period or pulse_width)
if (addr == 0)
read_data=period;
else
read_data=pulse_width;
always @(posedge clk or negedge clr_n)
begin
if (clr_n==0)
counter<=0;
else
if (counter>=period-1)
counter<=0;
else
counter<=counter+1;
end
always @(posedge clk or negedge clr_n)
begin
if (clr_n==0)
off<=0;
else
if (counter>=pulse_width)
off <= 1;
else
if (counter==0)
off<=0;
else
off<=off;
end