OV5640 有上电时序的要求,FPGA 上电后需要等待一段时间再使能配置 OV5640 寄存器,那么怎么满足其上电时序的要求呢?且看下图:
此图描述了OV5640上电时序中对各信号的要求,归纳如下:
t0>=0ms:DOVDD要比AVDD提前稳定的时间
t1>=0ms:AVDD要比DVDD提前稳定的时间
t2>=5ms:DVDD要比PWDN(传感器上电)提前稳定的时间
t3>=1ms:PWDN(传感器上电)要比RESETB提前稳定的时间
t4>=20ms:RESETB要比SCCB提前稳定的时间
t5>=0ms:AVDD要比DOVDD延后关断的时间
t6>=0ms:RESETB要比DVDD延后关断的时间
t7>=0ms:XVCLK要比DVDD延后关断的时间
能等于0的我们都不关注,所以要设置的值就只剩3个:
t2>=5ms:DVDD要比PWDN(传感器上电)提前稳定的时间
t3>=1ms:PWDN(传感器上电)要比RESETB提前稳定的时间
t4>=20ms:RESETB要比SCCB提前稳定的时间
我们这里分别设置成6ms,2ms,21ms
三个标志信号
camera_pwnd_reg___|~~|____
camera_rstn_reg_______|~~|_____
initial_en ________________ |~~|_____
当前一个信号有效时,下一个信号清零做准备
//6ms, delay from sensor power up stable to Pwdn pull down
always@(posedge clk_50M)//20ns
begin
if(reset_n==1'b0) begin
cnt1<=0;
camera_pwnd_reg<=1'b1;
end
else if(cnt1<19'h493e0) begin
cnt1<=cnt1+1'b1;
camera_pwnd_reg<=1'b1;
end
else
camera_pwnd_reg<=1'b0;
end
同理,2ms,21ms的延时如下:
2ms:
//2ms, delay from pwdn low to resetb pull up
always@(posedge clk_50M)//20ns
begin
if(camera_pwnd_reg==1) begin
cnt2<=0;
camera_rstn_reg<=1'b0;
end
else if(cnt2<17'h186A0) begin
cnt2<=cnt2+1'b1;
camera_rstn_reg<=1'b0;
end
else
camera_rstn_reg<=1'b1;
end
21ms:
//21ms, delay from resetb pul high to SCCB initialization
always@(posedge clk_50M)
begin
if(camera_rstn_reg==0) begin
cnt3<=0;
initial_en<=1'b0;
end
else if(cnt3<21'h100590) begin
cnt3<=cnt3+1'b1;
initial_en<=1'b0;
end
else
initial_en<=1'b1;
end
总的上电程序如下:
//camera power on timing requirement
module power_on_delay(clk_50M,reset_n,camera_rstn,camera_pwnd,initial_en);
input clk_50M;
input reset_n;
output camera_rstn;
output camera_pwnd;
output initial_en;
reg [18:0]cnt1;
reg [15:0]cnt2;
reg [19:0]cnt3;
reg initial_en;
reg camera_rstn_reg;
reg camera_pwnd_reg;
assign camera_rstn=camera_rstn_reg;
assign camera_pwnd=camera_pwnd_reg;
//6ms, delay from sensor power up stable to Pwdn pull down
always@(posedge clk_50M)//20ns
begin
if(reset_n==1'b0) begin
cnt1<=0;
camera_pwnd_reg<=1'b1;
end
else if(cnt1<19'h493e0) begin
cnt1<=cnt1+1'b1;
camera_pwnd_reg<=1'b1;
end
else
camera_pwnd_reg<=1'b0;
end
//2ms, delay from pwdn low to resetb pull up
always@(posedge clk_50M)//20ns
begin
if(camera_pwnd_reg==1) begin
cnt2<=0;
camera_rstn_reg<=1'b0;
end
else if(cnt2<17'h186A0) begin
cnt2<=cnt2+1'b1;
camera_rstn_reg<=1'b0;
end
else
camera_rstn_reg<=1'b1;
end
//21ms, delay from resetb pul high to SCCB initialization
always@(posedge clk_50M)
begin
if(camera_rstn_reg==0) begin
cnt3<=0;
initial_en<=1'b0;
end
else if(cnt3<21'h100590) begin
cnt3<=cnt3+1'b1;
initial_en<=1'b0;
end
else
initial_en<=1'b1;
end
endmodule
完成!