x393  1.0
FPGAcodeforElphelNC393camera
simul_sensor12bits.v
Go to the documentation of this file.
1 
39 
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
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
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;
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;
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;
284  cntr=nVLO;
285  end
286  s_frame_done: if (OFST) begin
287  ivact= 1'b1;
288  cntr= t_firstline-1;
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 
[0:4095] 9350sensor_datareg[15:0]
9343t_preVACTlline* trigdly
9349t_lastlinenrowa*lline+1
9344t_firstlinenrowb*lline+1
9348t_afterHACTlline-nbpf-ngp1-ncols