Talk:10359 in dual sensor setup

From ElphelWiki
Revision as of 08:15, 22 September 2008 by Oleg (talk | contribs)
Jump to: navigation, search

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:

<?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()."
\n"; elphel_reset_sensor(); echo "After reset+initializing: elphel_get_state=".elphel_get_state()."
\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()."
\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"); dcm_reset($width,$bus,$raw=0); send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0); 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(16,0,0x00000001,$init_pars2,$raw=0); 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"; ?>

--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.