x393
1.0
FPGAcodeforElphelNC393camera
simul_sensor12bits.v
Go to the documentation of this file.
1
39
40
module
simul_sensor12bits
# (
41
parameter
SENSOR_IMAGE_TYPE
=
"NORM"
,
// "RUN1",
42
parameter
lline
=
192
,
// 1664;// line duration in clocks
43
parameter
ncols
=
66
,
//58; //56; // 129; //128; //1288;
44
parameter
nrows
=
18
,
// 16; // 1032;
45
parameter
nrowb
=
1
,
// number of "blank rows" from vact to 1-st hact
46
parameter
nrowa
=
1
,
// number of "blank rows" from last hact to end of vact
47
// parameter nAV = 24, //240; // clocks from ARO to VACT (actually from en_dclkd)
48
parameter
nbpf
=
20
,
//16; // bpf length
49
parameter
ngp1
=
8
,
// bpf to hact
50
parameter
nVLO
=
1
,
// VACT=0 in video mode (clocks)
51
//parameter tMD = 14; //
52
//parameter tDDO = 10; // some confusion here - let's assume that it is from DCLK to Data out
53
parameter
tMD
=
4
,
//
54
parameter
tDDO
=
2
,
// some confusion here - let's assume that it is from DCLK to Data out
55
parameter
tDDO1
=
5
,
//
56
parameter
trigdly
=
8
,
// delay between trigger input and start of output (VACT) in lines
57
parameter
ramp
=
1
,
// 1 - ramp, 0 - random (now - sensor.dat)
58
parameter
new_bayer
=
0
// 0 - old (16x16), 1 - new (18x18)
59
) (
60
input
MCLK
,
// Master clock
61
input
MRST
,
// Master Reset - active low
62
input
ARO
,
// Array read Out.
63
input
ARST
,
// Array Reset. Active low
64
input
OE
,
// output Elphel, Inc.ock
65
input
SCL
,
// I2C data // SuppressThisWarning VEditor - not used
66
inout
SDA
,
// I2C data// SuppressThisWarning VEditor - not used/assigned
67
input
OFST
,
// I2C address ofset by 2: for simulation 0 - still mode, 1 - video mode.
68
output
[
11
:
0
]
D
,
// [11:0] data output
69
output
DCLK
,
// Data output clock
70
output
BPF
,
// Black Pixel Flag
71
output
HACT
,
// Horizontal Active
72
output
VACT
,
// Vertical Active
73
output
VACT1
);
74
75
76
localparam
s_stop
=
0
;
77
localparam
s_preVACT
=
1
;
78
localparam
s_firstline
=
2
;
79
localparam
s_BPF
=
3
;
80
localparam
s_preHACT
=
4
;
81
localparam
s_HACT
=
5
;
82
localparam
s_afterHACT
=
6
;
83
localparam
s_lastline
=
7
;
84
localparam
s_frame_done
=
8
;
85
86
localparam
t_preVACT
=
lline
*
trigdly
;
87
localparam
t_firstline
=
nrowb
*
lline
+
1
;
// 1664
88
localparam
t_BPF
=
nbpf
;
// 16
89
localparam
t_preHACT
=
ngp1
;
// 8
90
localparam
t_HACT
=
ncols
;
// 1288
91
localparam
t_afterHACT
=
lline
-
nbpf
-
ngp1
-
ncols
;
// 352
92
localparam
t_lastline
=
nrowa
*
lline
+
1
;
// 1664
93
94
reg
[
15
:
0
]
sensor_data
[
0
:
4095
];
// up to 64 x 64 pixels // SuppressThisWarning VEditor - Will be assigned by $readmem
95
// $readmemh("sensor.dat",sensor_data);
96
97
98
99
reg
c
;
// internal data out clock
100
//reg [9:0] id; // internal pixel data (sync do DCLK)
101
//wire [9:0] nxt_d; // will be calculated later - next pixel data
102
reg
stopped
;
103
wire
#
1
stoppedd
=
stopped
;
104
reg
ibpf
,
ihact
,
ivact
,
ivact1
;
105
reg
arst1
;
//
106
reg
[
11
:
0
]
col
;
// current row
107
reg
[
11
:
0
]
row
;
// current column;
108
reg
[
3
:
0
]
state
;
109
reg
[
15
:
0
]
cntr
;
110
wire
[
11
:
0
]
cold
;
111
wire
[
11
:
0
]
rowd
;
112
wire
[
3
:
0
]
stated
;
113
wire
[
15
:
0
]
cntrd
;
114
wire
NMRST
=!
MRST
;
115
116
117
wire
[
5
:
0
]
row_index
=
row
[
5
:
0
]-
new_bayer
;
118
wire
[
5
:
0
]
col_index
=
col
[
5
:
0
]-
new_bayer
;
119
120
121
// random
122
integer
seed
;
123
integer
r
;
124
reg
c_rand
;
125
reg
[
11
:
0
]
d_rand
;
126
127
128
129
assign
#
1
cold
=
col
;
130
assign
#
1
rowd
=
row
;
131
assign
#
1
stated
=
state
;
132
assign
#
1
cntrd
=
cntr
;
133
134
135
136
//assign #tDDO D = OE? {10{1'bz}}: ((ihact || ibpf)? ((ramp)?(col[9:0] + row[9:0]):(d_rand)): 10'b0); // just test pattern
137
//assign #tDDO D = OE? {10{1'bz}}: ((ihact || ibpf)? ((ramp)?(col[9:0] + row[9:0]):(sensor_data[{row_index[5:0],col_index[5:0]}])): 10'b0); // just test pattern
138
//assign #tDDO D = OE? {12{1'bz}}: ((ihact || ibpf)? ((ramp)?(col[11:0] + row[11:0]):(sensor_data[{row_index[5:0],col_index[5:0]}])): 12'b0); // just test pattern
139
assign
#
tDDO
D
=
OE
? {
12
{
1'bz
}}: ((
ihact
||
ibpf
)? ((
ramp
)?({
row
[
11
:
8
],
8'h0
} +
col
[
11
:
0
]):(
sensor_data
[{
row_index
[
5
:
0
],
col_index
[
5
:
0
]}])):
12'b0
);
// just test pattern
140
//assign #tDDO BPF = ibpf;
141
//assign #tDDO HACT= ihact;
142
//assign #tDDO VACT= ivact;
143
assign
#
tDDO1
BPF
=
ibpf
;
144
assign
#
tDDO1
HACT
=
ihact
;
145
assign
#
tDDO1
VACT
=
ivact
;
146
assign
#
tDDO1
VACT1
=
ivact
&& !
ivact1
;
147
assign
DCLK
=
c
;
148
`ifndef
ROOTPATH
149
`include
"IVERILOG_INCLUDE.v"// SuppressThisWarning VEditor - maybe not used
150
`ifndef
ROOTPATH
151
`define
ROOTPATH "."
`endif
152
`endif
153
154
initial
begin
155
//parameter ramp = 1; // 0 - ramp, 1 - random
156
//parameter lline = 192; // 1664;// line duration in clocks
157
//parameter ncols = 58; //56; // 129; //128; //1288;
158
//parameter nrows = 16; // 1032;
159
160
$display
(
"sensor parameters"
);
161
$display
(
" -- image type = %s"
,
SENSOR_IMAGE_TYPE
);
162
$display
(
" -- ramp = %d (0 - random, 1 - ramp)"
,
ramp
);
163
$display
(
" -- lline = %d (line duration in clocks)"
,
lline
);
164
$display
(
" -- ncols = %d (numer of clocks in HACT)"
,
ncols
);
165
$display
(
" -- nrows = %d (number of rows)"
,
nrows
);
166
$display
(
" -- t_afterHACT = %d "
,
t_afterHACT
);
167
$display
(
" -- t_preHACT = %d "
,
t_preHACT
);
168
$display
(
" -- new_bayer = %d "
,
new_bayer
);
169
170
171
// reg [15:0] sensor_data[0:4095]; // up to 64 x 64 pixels
172
if
(
SENSOR_IMAGE_TYPE
==
"NORM"
)
$readmemh
({
"/home/eyesis/git/x393-neon"
,
"/input_data/sensor.dat"
},
sensor_data
);
173
else
if
(
SENSOR_IMAGE_TYPE
==
"RUN1"
)
$readmemh
({
"/home/eyesis/git/x393-neon"
,
"/input_data/sensor_run1.dat"
},
sensor_data
);
174
else
begin
175
$display
(
"WARNING: Unrecognized sensor image :'%s', using default 'NORM': input_data/sensor.dat"
,
SENSOR_IMAGE_TYPE
);
176
$readmemh
({
"/home/eyesis/git/x393-neon"
,
"/input_data/sensor.dat"
},
sensor_data
);
177
end
178
c
=
0
;
179
// {ibpf,ihact,ivact}=0;
180
stopped
=
1
;
181
arst1
=
0
;
182
seed
=
1
;
183
d_rand
=
0
;
184
// row=0;
185
// col=0;
186
187
end
188
always
@ (
NMRST
)
begin
189
c
=
0
;
190
// {ibpf,ihact,ivact}=0;
191
stopped
=
1
;
192
arst1
=
0
;
193
// row=0;
194
// col=0;
195
end
196
197
always
begin
198
@ (
posedge
MCLK
)
begin
199
#
tMD
c
= !
stoppedd
;
200
end
201
@ (
negedge
MCLK
)
begin
202
#
tMD
c
=
1'b0
;
203
end
204
end
205
206
always
@ (
posedge
MCLK
)
begin
207
// #1 stopped= !arst1 || (stoppedd && !ARO) ;
208
#
1
stopped
= !
arst1
|| ((
stoppedd
|| (
state
==
s_frame_done
)) &&
ARO
) ;
/// ARO tow TRIGGER, active low
209
#
1
arst1
=
ARST
;
210
end
211
212
always
@ (
posedge
c
)
ivact1
=
ivact
;
213
always
@ (
posedge
stoppedd
or
posedge
c
)
begin
214
if
(
stoppedd
)
begin
215
{
ibpf
,
ihact
,
ivact
}=
0
;
216
row
=
0
;
217
col
=
0
;
218
// id=0;
219
state
=
0
;
220
cntr
=
0
;
221
end
else
if
(|
cntrd
!=
0
)
begin
222
#
1
cntr
=
cntrd
-
1
;
223
if
(
BPF
||
HACT
)
col
=
cold
+
1
;
224
end
else
begin
225
case
(
stated
)
226
s_stop
:
begin
227
cntr
=
t_preVACT
-
1
;
228
state
=
s_preVACT
;
229
end
230
s_preVACT
:
begin
231
ivact
=
1'b1
;
232
cntr
=
t_firstline
-
1
;
233
state
=
s_firstline
;
234
end
235
s_firstline
:
begin
236
col
=
0
;
237
row
=
0
;
238
if
(
t_BPF
>=
1
)
begin
239
ibpf
=
1'b1
;
240
cntr
=
t_BPF
-
1
;
241
state
=
s_BPF
;
242
end
else
begin
243
ihact
=
1'b1
;
244
cntr
=
t_HACT
-
1
;
245
state
=
s_HACT
;
246
end
247
end
248
s_BPF
:
begin
249
ibpf
=
1'b0
;
250
cntr
=
t_preHACT
-
1
;
251
state
=
s_preHACT
;
252
end
253
s_preHACT
:
begin
254
ihact
=
1'b1
;
255
col
=
0
;
256
cntr
=
t_HACT
-
1
;
257
state
=
s_HACT
;
258
end
259
s_HACT
:
begin
260
ihact
=
1'b0
;
261
row
=
rowd
+
1
;
262
cntr
=
t_afterHACT
-
1
;
263
state
=
s_afterHACT
;
264
end
265
s_afterHACT
:
266
if
(
rowd
==
nrows
)
begin
267
cntr
=
t_lastline
-
1
;
268
state
=
s_lastline
;
269
end
else
begin
270
col
=
0
;
271
if
(
t_BPF
>=
1
)
begin
272
ibpf
=
1'b1
;
273
cntr
=
t_BPF
-
1
;
274
state
=
s_BPF
;
275
end
else
begin
276
ihact
=
1'b1
;
277
cntr
=
t_HACT
-
1
;
278
state
=
s_HACT
;
279
end
280
end
281
s_lastline
:
begin
282
ivact
=
1'b0
;
283
state
=
s_frame_done
;
284
cntr
=
nVLO
;
285
end
286
s_frame_done
:
if
(
OFST
)
begin
287
ivact
=
1'b1
;
288
cntr
=
t_firstline
-
1
;
289
state
=
s_firstline
;
290
end
291
endcase
292
293
end
294
// random data
295
seed
=
$random
(
seed
);
296
r
= (
seed
&
'h7fff
);
297
r
= (
r
*
r
) >>
20
;
// 10 bits
298
c_rand
=
seed
[
16
];
// >>16; // sign
299
d_rand
=
c_rand
?(
D
+(((
1023
-
d_rand
)*
r
)>>
10
)):(
d_rand
-((
d_rand
*
r
)>>
10
));
300
end
301
302
303
304
endmodule
305
simul_sensor12bits.9319new_bayer
9319new_bayer0
Definition:
simul_sensor12bits.v:58
simul_sensor12bits.9350sensor_data
[0:4095] 9350sensor_datareg[15:0]
Definition:
simul_sensor12bits.v:94
simul_sensor12bits.9373d_rand
9373d_randreg[11:0]
Definition:
simul_sensor12bits.v:125
simul_sensor12bits.9343t_preVACT
9343t_preVACTlline* trigdly
Definition:
simul_sensor12bits.v:86
simul_sensor12bits.9365stated
9365statedwire[3:0]
Definition:
simul_sensor12bits.v:112
simul_sensor12bits.9329DCLK
9329DCLK
Definition:
simul_sensor12bits.v:69
simul_sensor12bits.9353#1stoppedd
9353#1stoppeddwire
Definition:
simul_sensor12bits.v:103
simul_sensor12bits.9358arst1
9358arst1reg
Definition:
simul_sensor12bits.v:105
simul_sensor12bits.9331HACT
9331HACT
Definition:
simul_sensor12bits.v:71
simul_sensor12bits.9334s_stop
9334s_stop0
Definition:
simul_sensor12bits.v:76
simul_sensor12bits.9370seed
9370seedinteger
Definition:
simul_sensor12bits.v:122
simul_sensor12bits.9369col_index
9369col_indexwire[5:0]
Definition:
simul_sensor12bits.v:118
simul_sensor12bits.9347t_HACT
9347t_HACTncols
Definition:
simul_sensor12bits.v:90
simul_sensor12bits.9366cntrd
9366cntrdwire[15:0]
Definition:
simul_sensor12bits.v:113
simul_sensor12bits.9307ncols
9307ncols66
Definition:
simul_sensor12bits.v:43
simul_sensor12bits.9372c_rand
9372c_randreg
Definition:
simul_sensor12bits.v:124
simul_sensor12bits.9324OE
9324OE
Definition:
simul_sensor12bits.v:64
simul_sensor12bits.9330BPF
9330BPF
Definition:
simul_sensor12bits.v:70
simul_sensor12bits.9362cntr
9362cntrreg[15:0]
Definition:
simul_sensor12bits.v:109
simul_sensor12bits.9349t_lastline
9349t_lastlinenrowa*lline+1
Definition:
simul_sensor12bits.v:92
simul_sensor12bits.9352stopped
9352stoppedreg
Definition:
simul_sensor12bits.v:102
simul_sensor12bits.9305SENSOR_IMAGE_TYPE
9305SENSOR_IMAGE_TYPE"NORM"
Definition:
simul_sensor12bits.v:41
simul_sensor12bits.9351c
9351creg
Definition:
simul_sensor12bits.v:99
simul_sensor12bits.9363cold
9363coldwire[11:0]
Definition:
simul_sensor12bits.v:110
simul_sensor12bits.9341s_lastline
9341s_lastline7
Definition:
simul_sensor12bits.v:83
simul_sensor12bits.9315tDDO
9315tDDO2
Definition:
simul_sensor12bits.v:54
simul_sensor12bits.9323ARST
9323ARST
Definition:
simul_sensor12bits.v:63
simul_sensor12bits.9342s_frame_done
9342s_frame_done8
Definition:
simul_sensor12bits.v:84
simul_sensor12bits.9337s_BPF
9337s_BPF3
Definition:
simul_sensor12bits.v:79
simul_sensor12bits.9328D
[11:0] 9328D
Definition:
simul_sensor12bits.v:68
simul_sensor12bits.9325SCL
9325SCL
Definition:
simul_sensor12bits.v:65
simul_sensor12bits.9318ramp
9318ramp1
Definition:
simul_sensor12bits.v:57
simul_sensor12bits.9354ibpf
9354ibpfreg
Definition:
simul_sensor12bits.v:104
simul_sensor12bits.9346t_preHACT
9346t_preHACTngp1
Definition:
simul_sensor12bits.v:89
simul_sensor12bits.9367NMRST
9367NMRSTwire
Definition:
simul_sensor12bits.v:114
simul_sensor12bits.9314tMD
9314tMD4
Definition:
simul_sensor12bits.v:53
simul_sensor12bits.9316tDDO1
9316tDDO15
Definition:
simul_sensor12bits.v:55
simul_sensor12bits.9361state
9361statereg[3:0]
Definition:
simul_sensor12bits.v:108
simul_sensor12bits.9313nVLO
9313nVLO1
Definition:
simul_sensor12bits.v:50
simul_sensor12bits
Definition:
simul_sensor12bits.v:40
simul_sensor12bits.9344t_firstline
9344t_firstlinenrowb*lline+1
Definition:
simul_sensor12bits.v:87
simul_sensor12bits.9340s_afterHACT
9340s_afterHACT6
Definition:
simul_sensor12bits.v:82
simul_sensor12bits.9357ivact1
9357ivact1reg
Definition:
simul_sensor12bits.v:104
simul_sensor12bits.9339s_HACT
9339s_HACT5
Definition:
simul_sensor12bits.v:81
simul_sensor12bits.9321MRST
9321MRST
Definition:
simul_sensor12bits.v:61
simul_sensor12bits.9310nrowa
9310nrowa1
Definition:
simul_sensor12bits.v:46
simul_sensor12bits.9306lline
9306lline192
Definition:
simul_sensor12bits.v:42
simul_sensor12bits.9333VACT1
9333VACT1
Definition:
simul_sensor12bits.v:73
simul_sensor12bits.9335s_preVACT
9335s_preVACT1
Definition:
simul_sensor12bits.v:77
simul_sensor12bits.9308nrows
9308nrows18
Definition:
simul_sensor12bits.v:44
simul_sensor12bits.9338s_preHACT
9338s_preHACT4
Definition:
simul_sensor12bits.v:80
simul_sensor12bits.9364rowd
9364rowdwire[11:0]
Definition:
simul_sensor12bits.v:111
simul_sensor12bits.9336s_firstline
9336s_firstline2
Definition:
simul_sensor12bits.v:78
simul_sensor12bits.9345t_BPF
9345t_BPFnbpf
Definition:
simul_sensor12bits.v:88
simul_sensor12bits.9322ARO
9322ARO
Definition:
simul_sensor12bits.v:62
simul_sensor12bits.9368row_index
9368row_indexwire[5:0]
Definition:
simul_sensor12bits.v:117
simul_sensor12bits.9311nbpf
9311nbpf20
Definition:
simul_sensor12bits.v:48
simul_sensor12bits.9360row
9360rowreg[11:0]
Definition:
simul_sensor12bits.v:107
simul_sensor12bits.9326SDA
9326SDA
Definition:
simul_sensor12bits.v:66
simul_sensor12bits.9348t_afterHACT
9348t_afterHACTlline-nbpf-ngp1-ncols
Definition:
simul_sensor12bits.v:91
simul_sensor12bits.9309nrowb
9309nrowb1
Definition:
simul_sensor12bits.v:45
simul_sensor12bits.9317trigdly
9317trigdly8
Definition:
simul_sensor12bits.v:56
simul_sensor12bits.9327OFST
9327OFST
Definition:
simul_sensor12bits.v:67
simul_sensor12bits.9356ivact
9356ivactreg
Definition:
simul_sensor12bits.v:104
simul_sensor12bits.9371r
9371rinteger
Definition:
simul_sensor12bits.v:123
simul_sensor12bits.9355ihact
9355ihactreg
Definition:
simul_sensor12bits.v:104
simul_sensor12bits.9312ngp1
9312ngp18
Definition:
simul_sensor12bits.v:49
simul_sensor12bits.9359col
9359colreg[11:0]
Definition:
simul_sensor12bits.v:106
simul_sensor12bits.9320MCLK
9320MCLK
Definition:
simul_sensor12bits.v:60
simul_sensor12bits.9332VACT
9332VACT
Definition:
simul_sensor12bits.v:72
simulation_modules
simul_sensor12bits.v
Generated by
1.8.12