Difference between revisions of "Talk:10359 in dual sensor setup"

From ElphelWiki
Jump to: navigation, search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
==2008/09/25==
 +
'''c.''' Make clear with scripts. "standard camera_demo.php+sensors_init.php" work a bit different (not correct performance) than camera_demo.php with added sensor initialization. Time delay between elphel_reset_sensor() and dcm_reset()? --[[User:Oleg|Oleg]] 15:25, 25 September 2008 (CDT)
 +
==2008/09/24==
 +
'''a.''' Verification shown it was my mistake in switching between frames. Corrected.
 +
 +
'''b.''' Separating i2c bus mux and channel mux was a right idea. To keep old scripts work, I modified i2c to switch immediately and the channels to wait till the frame ends. MUX register is one.
 +
 +
'''c.''' With a "light"(no ddr, only 2 channels) x359.bit, configuration and switching work. There's an unclear moment with a need for soft reset in scripts. this needs testing a little.
 +
 +
====TODO====
 +
'''a.''' Make "light" x359.bit for 3 channels, verify and test.
 +
 +
'''b.''' Make standard x359.bit with correct switching.
 +
 +
'''c.''' Make clear with scripts.
 +
 +
====Conclusion====
 +
I think all that broken frames came from channel switching only.
 +
E.g., the 1st channel is configured and starts giving out a frame and I switch to configure the 2nd channel in the middle of the frame. But in most experiments I was lucky in this case. Frames were broken after back-switching to the 1st channel.
 +
 +
--[[User:Oleg|Oleg]] 06:28, 24 September 2008 (CDT)
 +
 +
==2008/09/23==
 +
a. Separated i2c bus mux and channel mux.
 +
 +
b. Made mux to switch between frames.
 +
 +
Not stable, next step - verify by simulation.
 +
--[[User:Oleg|Oleg]] 13:41, 23 September 2008 (CDT)
 +
 
==2008/09/22==
 
==2008/09/22==
 +
No, it's not stable. --[[User:Oleg|Oleg]] 10:14, 22 September 2008 (CDT)
 +
 
Latest switching test with the script was ok. The only change is the position of the boards on the table.--[[User:Oleg|Oleg]] 10:01, 22 September 2008 (CDT)
 
Latest switching test with the script was ok. The only change is the position of the boards on the table.--[[User:Oleg|Oleg]] 10:01, 22 September 2008 (CDT)
  
Line 14: Line 46:
 
  ...
 
  ...
  
Current "camera_demo" script:
+
Current "camera_demo" script (sources: camera_demo.php, sensors_init.php):
<?php
 
function send_i2c($width,$bus,$a,$d,$raw=0) { //$a<0 - use raw read/write
 
$w=($width==16)?2:1;
 
$i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
 
$i2c  = fopen($i2c_fn, 'w');
 
fseek ($i2c, $w*$a) ;
 
if ($w==1)    $res=fwrite($i2c, chr ($d));
 
else          $res=fwrite($i2c, chr (floor($d/256)).chr ($d-256*floor($d/256)));
 
fclose($i2c);
 
return $res;
 
} // end of send_i2c()
 
 
function receive_i2c($width,$bus,$a,$raw=0) {
 
$w=($width==16)?2:1;
 
$i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
 
$i2c  = fopen($i2c_fn, 'r');
 
fseek ($i2c, $w*$a);
 
$data = fread($i2c, $w);
 
fclose($i2c);
 
if (strlen($data)<$w) return -1;
 
$v=unpack(($w==1)?'C':'n1',$data);
 
return $v[1];
 
} // end of receive_i2c()
 
 
function sensor_init($width,$bus,$channel,$init_pars,$raw=0){
 
 
for ($i=0;$i<256;$i++){
 
send_i2c($width,$bus,0x4800+$i,$init_pars[$i],$raw=0);
 
 
//printf("%04x ",$init_pars[$i]);
 
 
$readout=receive_i2c($width,$bus,0x4800+$i,$raw=0);
 
printf("%04x ",$readout);
 
 
if($j==15){
 
$j=0; printf("\n");
 
}else{
 
$j++;
 
}
 
}
 
}
 
 
function dcm_reset($width,$bus,$raw=0){
 
 
printf("sent 0x%04x \n",0x0810); send_i2c_4($width,$bus,0x0810,0xffffffff,$raw=0);
 
printf("sent 0x%04x \n",0x0810); send_i2c_4($width,$bus,0x0810,0x00000000,$raw=0);
 
 
}
 
 
function send_i2c_4($width,$bus,$a,$d,$raw=0) { //$a<0 - use raw read/write
 
$w=2;
 
$i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
 
$i2c  = fopen($i2c_fn, 'w');
 
fseek ($i2c, $w*$a) ;
 
if ($w==1)    $res=fwrite($i2c, chr ($d));
 
else          $res=fwrite($i2c, chr (floor($d/(256*256*256))).chr (($d - 256*256*256*floor($d/(256*256*256)))/(256*256)).chr (($d - 256*256*floor($d/(256*256)))/256).chr ($d - 256*floor($d/(256))) );
 
 
fclose($i2c);
 
return $res;
 
} // end of send_i2c()
 
 
$width=16;
 
$bus=0;
 
 
$init_pars=array(
 
"FLIP"=>3,  //!xy, +1 - flip-X, +2 - flipY
 
"COLOR"=>1, //! mono - 0, color mode - 1, 2- jp4, +256 - sensor test, 512 - FPGA test
 
"DCM_HOR"  => 1,  //! Decimation horizontal
 
"DCM_VERT" => 1,  //! Decimation vertical
 
"BIN_HOR"  => 1,  //! Binning horizontal
 
"BIN_VERT" => 1,  //! Binning vertical
 
"QUALITY"  => 90, //! JPEG quality (%)
 
"COLOR_SATURATION_BLUE" => 200 , //! color saturation blue 200% (100% - only for gamma=1.0)
 
"COLOR_SATURATION_RED" => 200 ,  //! color saturation blue 200% (100% - only for gamma=1.0)
 
"BITS" => 8,                    //! 8-bit image mode (may be 16)
 
"GAMMA" => 57,                  //! Gamma=57%
 
"PIXEL_LOW" => 10,              //! Balck level - 10 (sensor default "fat zero")
 
"PIXEL_HIGH" => 254,            //! white level
 
"EXPOS" =>    100,              //! whatever? (in 100usec steps)
 
"WOI_LEFT" =>  0,                //! window left
 
"WOI_TOP" =>  0,                //! window top
 
"WOI_WIDTH" =>  10000,            //! window width  (more than needed, will be truncated)
 
"WOI_HEIGHT" => 10000,            //! window height (more than needed, will be truncated)
 
"RSCALE" =>      256,            //! red/green*256 (no auto - it is inside ccam.cgi)
 
"BSCALE" =>      256,            //! blue/green*256 (no auto - it is inside ccam.cgi)
 
"GAINR" =>        512,            //! Red analog gain 2.0*256
 
"GAING" =>        512,            //! Green1 (red row) analog gain 2.0*256
 
"GAINB" =>        512,            //! Red analog gain 2.0*256
 
"GAINGB" =>      512,            //! Green2 (blue row) analog gain 2.0*256
 
"BAYER" =>          4            //! 0..3 - set, 4- use calcualted
 
);
 
 
$init_pars2=array(
 
0x1801, 0x0032, 0x000c, 0x0793, 0x0a23, 0x01c2, 0x0284, 0x0002, 0x0000, 0x0095, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
 
0x0050, 0x6404, 0x0000, 0x0000, 0x0036, 0x0010, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4006, 0x0000,
 
0x0040, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x000b, 0x0000, 0x0480, 0x1086, 0x0008, 0x0008, 0x0008, 0x0008, 0x0000,
 
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1413, 0x0005, 0x8041, 0x0004,
 
0x0007, 0x0000, 0x0003, 0x0003, 0x0203, 0x1010, 0x1010, 0x1010, 0x0010, 0x00a8, 0x0010, 0x0028, 0x0010, 0x100f, 0x1010, 0x0014,
 
0x8000, 0x0007, 0x8000, 0x0007, 0x0016, 0x0000, 0x0020, 0x0004, 0x8000, 0x0007, 0x0004, 0x0001, 0x005a, 0x2d13, 0x41ff, 0x231d,
 
0x0012, 0x0013, 0x0000, 0x0033, 0x0034, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030, 0x0016, 0x00fd, 0x00fe, 0x0015, 0x0000, 0x0000,
 
0x00ac, 0xa700, 0xa700, 0x0c00, 0x0600, 0x5617, 0x6b57, 0x6b57, 0xa500, 0xab00, 0xa904, 0xa700, 0xa700, 0xff00, 0xa900, 0x0000,
 
0x0022, 0x1f04, 0x0000, 0x1b06, 0x1d08, 0x0000, 0x1806, 0x1a08, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
 
0x07d0, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
 
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0794, 0x0a24, 0x5e9f, 0x00f5, 0x8fff,
 
0x9afa, 0xaeda, 0xeeee, 0xfe6e, 0xd2ca, 0xd2fe, 0x7ebe, 0x0bff, 0x0d4c, 0x03d7, 0x0ed1, 0x0bfe, 0x0dec, 0x0eb7, 0x0b99, 0x0e75,
 
0x0ff3, 0x0fef, 0x0dff, 0x0bcf, 0x0cff, 0x0de2, 0x0d7f, 0x29fd, 0xe6ff, 0xf366, 0xffad, 0xdc5d, 0x77ff, 0xf7ef, 0xbf71, 0xfef6,
 
0xfa7b, 0x8fe6, 0xffd5, 0x9ec5, 0xf7df, 0xfffb, 0x0de2, 0xff7f, 0x7b6f, 0xcf97, 0xff5f, 0xfabf, 0x7fff, 0xff79, 0xed67, 0xd9be,
 
0xefb5, 0xef77, 0xfe5f, 0x7ff6, 0xb3df, 0x9fff, 0xfbbf, 0xf765, 0xfbfa, 0x5ad9, 0x7ff9, 0x5ffb, 0xc2fe, 0xff58, 0x27e5, 0x0c97,
 
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0xe0b0, 0x2b4f, 0x8130, 0xa118, 0x0000, 0x1801);
 
//! Start with reset (normally not needed, just to make sure we have a clean start, not relying on previous programming)
 
echo "Original state was=".elphel_get_state()."<br/>\n";
 
 
 
  elphel_reset_sensor();
 
  elphel_reset_sensor();
   
+
  ...  
echo "After reset+initializing: elphel_get_state=".elphel_get_state()."<br/>\n";
 
printf ("Written %d parameters to the camera\n",elphel_set_P_arr($init_pars));
 
//! Program sensor (with restart)
 
 
elphel_program_sensor (0);
 
 
echo "After programming sensor parameters - elphel_get_state=".elphel_get_state()."<br/>\n";
 
//! Image qulaity is copied only when the compressor is started
 
echo "Parameters after programmimg:\n";
 
print_r(elphel_get_P_arr($init_pars));
 
 
 
  printf("Reset DCM\n");
 
  printf("Reset DCM\n");
  dcm_reset($width,$bus,$raw=0);
+
  dcm_reset();
 
    
 
    
  send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0); printf("\nInitializing sensor <font size=\"6\">1</font>\n");
+
  send_i2c_4(0x0835,0x00000001); printf("\nInitializing sensor 1\n");
 
  printf("Soft reset to sensor 1\n");
 
  printf("Soft reset to sensor 1\n");
 
  system("fpcf -i2cw16 480d 0001");
 
  system("fpcf -i2cw16 480d 0001");
Line 149: Line 58:
 
   
 
   
 
  printf("Reprogram sensor 1\n");
 
  printf("Reprogram sensor 1\n");
  sensor_init(16,0,0x00000001,$init_pars2,$raw=0);
+
  sensor_init($init_pars);
   
+
  ...
send_i2c_4($width,$bus,0x0835,0x00000002,$raw=0); printf("\nInitializing sensor 2\n");
+
 
printf("Soft reset to sensor 2\n");
 
system("fpcf -i2cw16 480d 0001");
 
system("fpcf -i2cw16 480d 0000");
 
 
printf("Reprogram sensor 2\n");
 
sensor_init(16,0,0x00000002,$init_pars2,$raw=0);
 
 
send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0); printf("\nSet back to sensor 1\n");
 
 
//!start compressor:
 
//  elphel_compressor_run();
 
//! or just acquire a single frame
 
elphel_compressor_frame();
 
echo "After starting compressor - elphel_get_state=".elphel_get_state()."\n";
 
?>
 
 
--[[User:Oleg|Oleg]] 09:35, 22 September 2008 (CDT)
 
--[[User:Oleg|Oleg]] 09:35, 22 September 2008 (CDT)
  

Latest revision as of 13:25, 25 September 2008

2008/09/25

c. Make clear with scripts. "standard camera_demo.php+sensors_init.php" work a bit different (not correct performance) than camera_demo.php with added sensor initialization. Time delay between elphel_reset_sensor() and dcm_reset()? --Oleg 15:25, 25 September 2008 (CDT)

2008/09/24

a. Verification shown it was my mistake in switching between frames. Corrected.

b. Separating i2c bus mux and channel mux was a right idea. To keep old scripts work, I modified i2c to switch immediately and the channels to wait till the frame ends. MUX register is one.

c. With a "light"(no ddr, only 2 channels) x359.bit, configuration and switching work. There's an unclear moment with a need for soft reset in scripts. this needs testing a little.

TODO

a. Make "light" x359.bit for 3 channels, verify and test.

b. Make standard x359.bit with correct switching.

c. Make clear with scripts.

Conclusion

I think all that broken frames came from channel switching only. E.g., the 1st channel is configured and starts giving out a frame and I switch to configure the 2nd channel in the middle of the frame. But in most experiments I was lucky in this case. Frames were broken after back-switching to the 1st channel.

--Oleg 06:28, 24 September 2008 (CDT)

2008/09/23

a. Separated i2c bus mux and channel mux.

b. Made mux to switch between frames.

Not stable, next step - verify by simulation. --Oleg 13:41, 23 September 2008 (CDT)

2008/09/22

No, it's not stable. --Oleg 10:14, 22 September 2008 (CDT)

Latest switching test with the script was ok. The only change is the position of the boards on the table.--Oleg 10:01, 22 September 2008 (CDT)

Sequence(no need in sensros_init):

1) camera_demo.php
2) (telnet) switch on test pattern
3) "get frame" 
4) "switch to channel 2"
5) (telnet) switch on test pattern
5) adjust phase
5) "get frame"
6) "switch to channel 1"
7) "switch to channel 2"
...

Current "camera_demo" script (sources: camera_demo.php, sensors_init.php):

elphel_reset_sensor();
... 
printf("Reset DCM\n");
dcm_reset();
 
send_i2c_4(0x0835,0x00000001); printf("\nInitializing sensor 1\n");
printf("Soft reset to sensor 1\n");
system("fpcf -i2cw16 480d 0001");
system("fpcf -i2cw16 480d 0000");

printf("Reprogram sensor 1\n");
sensor_init($init_pars);
... 

--Oleg 09:35, 22 September 2008 (CDT)

2008/09/xx

Are the frames become broken after:

1) camera_demo.php
2) sensors_init.php
3) "get frame" 
4) "switch to channel 2"
5) "get frame"
6) "switch to channel 1"

If yes, does turning off the compressor help? I mean:

change channel -> compressor start -> get frame -> compressor stop -> change channel

If you don't use sensors_init.php after camera_demo.php you can try to move function dcm_reset() from sensors_init.php to camera_demo.php before getting a frame.