-
Notifications
You must be signed in to change notification settings - Fork 0
/
OV7670_config.v
88 lines (74 loc) · 2.71 KB
/
OV7670_config.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
module OV7670_config
#(
parameter CLK_FREQ = 25000000
)
(
input wire clk,
input wire SCCB_interface_ready,
input wire [15:0] rom_data,
input wire start,
output reg [7:0] rom_addr,
output reg done,
output reg [7:0] SCCB_interface_addr,
output reg [7:0] SCCB_interface_data,
output reg SCCB_interface_start
);
initial begin
rom_addr = 0;
done = 0;
SCCB_interface_addr = 0;
SCCB_interface_data = 0;
SCCB_interface_start = 0;
end
localparam FSM_IDLE = 0;
localparam FSM_SEND_CMD = 1;
localparam FSM_DONE = 2;
localparam FSM_TIMER = 3;
reg [2:0] FSM_state = FSM_IDLE;
reg [2:0] FSM_return_state;
reg [31:0] timer = 0;
always@(posedge clk) begin
case(FSM_state)
FSM_IDLE: begin
FSM_state <= start ? FSM_SEND_CMD : FSM_IDLE;
rom_addr <= 0;
done <= start ? 0 : done;
end
FSM_SEND_CMD: begin
case(rom_data)
16'hFFFF: begin //end of ROM
FSM_state <= FSM_DONE;
end
16'hFFF0: begin //delay state
timer <= (CLK_FREQ/100); //10 ms delay
FSM_state <= FSM_TIMER;
FSM_return_state <= FSM_SEND_CMD;
rom_addr <= rom_addr + 1;
end
default: begin //normal rom commands
if (SCCB_interface_ready) begin
FSM_state <= FSM_TIMER;
FSM_return_state <= FSM_SEND_CMD;
timer <= 0; //one cycle delay gives ready chance to deassert
rom_addr <= rom_addr + 1;
SCCB_interface_addr <= rom_data[15:8];
SCCB_interface_data <= rom_data[7:0];
SCCB_interface_start <= 1;
end
end
endcase
end
FSM_DONE: begin //signal done
FSM_state <= FSM_IDLE;
done <= 1;
end
FSM_TIMER: begin //count down and jump to next state
FSM_state <= (timer == 0) ? FSM_return_state : FSM_TIMER;
timer <= (timer==0) ? 0 : timer - 1;
SCCB_interface_start <= 0;
end
endcase
end
endmodule