//assign ledout = 1'b1;
reg ledout;//与上面的语句只能是一个有效
//*************************主程序*****************************
always@(posedge cam_pclk or negedge cpld_rst)
begin
if(!cpld_rst)
begin
sram_add_map <= 19'b0;
vsyn_0 <= 1'b0;
current_state <= 3'b0;//状态机初始化,3位6个状态
cur <= 1'b0;//1位
end
else //复位结束
begin
current_state <= next_state;//状态机状态转换
if(current_state == 0)
cur <= 0;
else
cur <= nex;
always@(cur)
begin
case(cur)
0:
begin
if((vsyn_0 == 1) && (vsyn_1 == 0))
begin //帧同步信号的下降沿表示一帧的开始
temp = 1;
nex = 1;
end
else
begin
temp = 0;
nex = 0;
end
end
1:
begin
if((vsyn_0 == 0) && (vsyn_1 == 1))
begin //上升沿表示一帧的结束
temp = 0;
nex = 0;
end
else
begin
temp = 1;
nex = 1;
end
end
endcase
end
//*****************************SRAM读写控制状态机**************************
always@(current_state)
begin
case(current_state)
0:
begin
if(arm_ctrl == 2'b01)
next_state = 1;
else
next_state = 0;
end
1: //使sram进入写状态
begin
if(temp == 1)
begin
sram_oe_map = 0;
sram_ce_map = 0;
sram_we_map = 1;
next_state = 2;
end
else
next_state = 1;
end
2: //数据采集阶段
begin
sram_we_map = cam_pclk && cam_href;
if(sram_add_map < 17'b110001100000000000)
next_state = 2;
else
next_state = 3;
end
3: //数据采集结束
begin
if(arm_ctrl == 2'b10)
next_state = 0;
else
next_state = 3;
end
default: next_state = 0;
endcase
end
//**************状态标志输出模块********************
always@(current_state or cpld_rst or arm_ctrl)
begin
if(!cpld_rst)
sram_state = 1'b0;
else
if(current_state == 3)
begin
sram_state = 1'b1;
ledout = 1'b1;
end
else
begin
sram_state = 1'b0;
ledout = 1'b0;
end
end
endmodule