diff --git a/slsDetectorSoftware/eigerDetectorServer/EigerRegisterDefs.h b/slsDetectorSoftware/eigerDetectorServer/EigerRegisterDefs.h index b50188e92..11f712716 100644 --- a/slsDetectorSoftware/eigerDetectorServer/EigerRegisterDefs.h +++ b/slsDetectorSoftware/eigerDetectorServer/EigerRegisterDefs.h @@ -101,7 +101,7 @@ #define DAQ_STATUS_TOKEN_OUT 0x20 #define DAQ_STATUS_SERIAL_OUT 0x40 #define DAQ_STATUS_PIXELS_ARE_ENABLED 0x80 - +#define DAQ_STATUS_DAQ_RUN_TOGGLE 0x200 //data delay registers #define CHIP_DATA_OUT_DELAY_REG_CTRL 1 diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index 86ee44999..15206ab28 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -1,4 +1,4 @@ - + /** * @author Ian Johnson * @version 1.0 @@ -70,8 +70,8 @@ void Module_Module(struct Module* mod,unsigned int number, unsigned int address_ mod->high_voltage = -1; mod->top_dac = malloc(Module_ndacs * sizeof(int)); mod->bottom_dac = malloc(Module_ndacs * sizeof(int)); - for(i=0;itop_dac[i] = mod->top_address_valid ? -1:0; - for(i=0;ibottom_dac[i] = mod->bottom_address_valid ? -1:0; + for(i=0;itop_dac[i] = mod->top_address_valid ? -1:0; + for(i=0;ibottom_dac[i] = mod->bottom_address_valid ? -1:0; } @@ -91,8 +91,8 @@ void Module_ModuleBottom(struct Module* mod,unsigned int number, unsigned int ad mod->top_dac = malloc(Module_ndacs * sizeof(int)); mod->bottom_dac = malloc(Module_ndacs * sizeof(int)); - for(i=0;itop_dac[i] = mod->top_address_valid ? -1:0; - for(i=0;ibottom_dac[i] = mod->bottom_address_valid ? -1:0; + for(i=0;itop_dac[i] = mod->top_address_valid ? -1:0; + for(i=0;ibottom_dac[i] = mod->bottom_address_valid ? -1:0; } @@ -109,12 +109,12 @@ void Module_Module1(struct Module* mod,unsigned int number, unsigned int address mod->high_voltage = -1; - for(i=0;i<4;i++) mod->idelay_top[i]=mod->idelay_bottom[i]=0; + for(i=0;i<4;i++) mod->idelay_top[i]=mod->idelay_bottom[i]=0; - mod->top_dac = malloc(Module_ndacs * sizeof(int)); - mod->bottom_dac = malloc(Module_ndacs * sizeof(int)); - for(i=0;itop_dac[i] = mod->top_address_valid ? -1:0; - for(i=0;ibottom_dac[i] = mod->bottom_address_valid ? -1:0; + mod->top_dac = malloc(Module_ndacs * sizeof(int)); + mod->bottom_dac = malloc(Module_ndacs * sizeof(int)); + for(i=0;itop_dac[i] = mod->top_address_valid ? -1:0; + for(i=0;ibottom_dac[i] = mod->bottom_address_valid ? -1:0; } @@ -172,24 +172,24 @@ int Feb_Control_Init(int master, int top){ //global send Feb_Control_AddModule1(0,1,0xff,0,1); - Feb_Control_PrintModuleList(); + Feb_Control_PrintModuleList(); - //get module nummber - int res=0; - char hostname[100]; - if (gethostname(hostname, sizeof hostname) == 0) - puts(hostname); - else - perror("gethostname"); - char *pch; - pch = strtok(hostname,"0"); - pch = strtok(NULL,"0"); - sscanf(pch,"%d",&res); - Feb_Control_module_number = (res & 0xFF); + //get module nummber + int res=0; + char hostname[100]; + if (gethostname(hostname, sizeof hostname) == 0) + puts(hostname); + else + perror("gethostname"); + char *pch; + pch = strtok(hostname,"0"); + pch = strtok(NULL,"0"); + sscanf(pch,"%d",&res); + Feb_Control_module_number = (res & 0xFF); int serial = !top; - /* + /* //for Gemmas modules: if master, serial 0, else 1 int serial = 1; if(master) @@ -211,43 +211,43 @@ int Feb_Control_Init(int master, int top){ case 49: serial = 0; break; // Gemma case 48: serial = 1; break; // Gemma }*/ - printf("serial: %d\n",serial); + printf("serial: %d\n",serial); Feb_Control_current_index = 1; - /*for(i=1;i0) - sprintf(str,"%s",str); /*sprintf(str,"mod%d::%s",module_num,str);*/ - if(!Feb_Control_SetDAC(str,f0,1)) - printf("error in string: %s",str); + if(module_num>0) + sprintf(str,"%s",str); /*sprintf(str,"mod%d::%s",module_num,str);*/ + if(!Feb_Control_SetDAC(str,f0,1)) + printf("error in string: %s",str); - } - } + } + } fclose(fp); -printf("Done reading set up file\n"); - return 1; + printf("Done reading set up file\n"); + return 1; } @@ -542,169 +542,169 @@ int Feb_Control_CheckSetup(){ unsigned int i,j; int ok = 1; - /*for(i=0;i3){ - printf("Error SetIDelay chip_pos %d doesn't exist.\n",chip_pos);; - return 0; - } - - unsigned int module_index=0; - if(!Feb_Control_GetModuleIndex(module_num,&module_index)){ - printf("Error could not set i delay module number %d invalid.\n",module_num); - return 0; - } - - int ok = 1; - if(chip_pos/2==0){ //left fpga - if(Module_TopAddressIsValid(&modules[module_index])){ - if(Feb_Control_SendIDelays(Module_GetTopLeftAddress(&modules[module_index]),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) Module_SetTopIDelay(&modules[module_index],chip_pos,ndelay_units); - else{ - for(i=0;i3){ + printf("Error SetIDelay chip_pos %d doesn't exist.\n",chip_pos);; + return 0; } - }else{ - printf("Error could not set idelay module number %d (top_left).\n",module_num); - ok=0; - } - } - if(Module_BottomAddressIsValid(&modules[module_index])){ - if(Feb_Control_SendIDelays(Module_GetBottomLeftAddress(&modules[module_index]),chip_pos%2==0,0xffffffff,ndelay_units)){ - if(module_index!=0) Module_SetBottomIDelay(&modules[module_index],chip_pos,ndelay_units); - else{ - for(i=0;i0x3ff) ndelay_units=0x3ff; - // this is global - unsigned int delay_data_valid_nclks = 15 - ((ndelay_units&0x3c0)>>6); //data valid delay upto 15 clks - ndelay_units &= 0x3f; + if(ndelay_units>0x3ff) ndelay_units=0x3ff; + // this is global + unsigned int delay_data_valid_nclks = 15 - ((ndelay_units&0x3c0)>>6); //data valid delay upto 15 clks + ndelay_units &= 0x3f; - unsigned int set_left_delay_channels = chip_lr ? channels:0; - unsigned int set_right_delay_channels = chip_lr ? 0:channels; + unsigned int set_left_delay_channels = chip_lr ? channels:0; + unsigned int set_right_delay_channels = chip_lr ? 0:channels; - printf("\tSetting delays of "); - if(set_left_delay_channels!=0) printf("left chips of dst_num %d",dst_num); - else if(set_right_delay_channels!=0) printf("right chips of dst_num %d",dst_num); + printf("\tSetting delays of "); + if(set_left_delay_channels!=0) printf("left chips of dst_num %d",dst_num); + else if(set_right_delay_channels!=0) printf("right chips of dst_num %d",dst_num); - printf(", tracks 0x%x to: %d, %d clks and %d units.\n",channels,(((15-delay_data_valid_nclks)<<6)|ndelay_units),delay_data_valid_nclks,ndelay_units); + printf(", tracks 0x%x to: %d, %d clks and %d units.\n",channels,(((15-delay_data_valid_nclks)<<6)|ndelay_units),delay_data_valid_nclks,ndelay_units); - if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays - !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) || - !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) || - !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){ - printf("Warning: could not SetChipDataInputDelays(...).\n"); - return 0; - } + if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays + !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) || + !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) || + !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){ + printf("Warning: could not SetChipDataInputDelays(...).\n"); + return 0; + } - return 1; + return 1; } int Feb_Control_VoltageToDAC(float value, unsigned int* digital,unsigned int nsteps,float vmin,float vmax){ - if(valuevmax) return 0; - *digital = (int)(((value-vmin)/(vmax-vmin))*(nsteps-1) + 0.5); - return 1; + if(valuevmax) return 0; + *digital = (int)(((value-vmin)/(vmax-vmin))*(nsteps-1) + 0.5); + return 1; } float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax){ - return vmin+(vmax-vmin)*digital/(nsteps-1); + return vmin+(vmax-vmin)*digital/(nsteps-1); } @@ -713,59 +713,59 @@ int Feb_Control_SetHighVoltage(float value){ } int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){ - unsigned int module_index=0; - unsigned int i; + unsigned int module_index=0; + unsigned int i; - if(Module_TopAddressIsValid(&modules[module_index])){ - if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/ - printf("Error could not set high voltage module number %d invalid.\n",module_num); - return 0; - } - }else - return 0; + if(Module_TopAddressIsValid(&modules[module_index])){ + if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/ + printf("Error could not set high voltage module number %d invalid.\n",module_num); + return 0; + } + }else + return 0; - if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0; + if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0; - if(module_index!=0) Module_SetHighVoltage(&modules[module_index],value); - else for(i=0;i4095){ - printf("Warning: SetDac bad value, %d. The range is 0 to 4095.\n",v); - return 0; - } + unsigned int v = value; + if(is_a_voltage_mv&&!Feb_Control_VoltageToDAC(value,&v,4096,0,2048)){ + printf("Warning: SetDac bad value, %d. The range is 0 to 2048 mV.\n",value); + return 0; + } + if(v<0||v>4095){ + printf("Warning: SetDac bad value, %d. The range is 0 to 4095.\n",v); + return 0; + } - if(top&&Module_TopAddressIsValid(&modules[module_index])){ + if(top&&Module_TopAddressIsValid(&modules[module_index])){ - if(!Feb_Control_SendDACValue(Module_GetTopRightAddress(&modules[module_index]),dac_ch,&v)) return 0; + if(!Feb_Control_SendDACValue(Module_GetTopRightAddress(&modules[module_index]),dac_ch,&v)) return 0; - if(module_index!=0) Module_SetTopDACValue(&modules[module_index],dac_ch,v); - else for(i=0;i=Module_ndacs){ - printf("Warning: GetDACName index out of range, %d invalid.\n",dac_num); - return 0; - } - strcpy(s,Module_dac_names[dac_num]); - return 1; + if(dac_num>=Module_ndacs){ + printf("Warning: GetDACName index out of range, %d invalid.\n",dac_num); + return 0; + } + strcpy(s,Module_dac_names[dac_num]); + return 1; } int Feb_Control_GetDACNumber(char* s, unsigned int* n){ unsigned int i; - for(i=0;i15){ - printf("Warning invalid ch for SetDAC.\n"); - return 0; - } + if(ch<0||ch>15){ + printf("Warning invalid ch for SetDAC.\n"); + return 0; + } - //if(voltage<0) return PowerDownDAC(socket_num,ch); + //if(voltage<0) return PowerDownDAC(socket_num,ch); - *value&=0xfff; - unsigned int dac_ic = (ch<8) ? 1:2; - unsigned int dac_ch = ch%8; - unsigned int r = dac_ic<<30 | 3<<16 | dac_ch<<12 | *value; //3 write and power up + *value&=0xfff; + unsigned int dac_ic = (ch<8) ? 1:2; + unsigned int dac_ch = ch%8; + unsigned int r = dac_ic<<30 | 3<<16 | dac_ch<<12 | *value; //3 write and power up - if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){ - printf("Warning: trouble setting dac %d voltage.\n",ch); - return 0; - } + if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){ + printf("Warning: trouble setting dac %d voltage.\n",ch); + return 0; + } - float voltage=Feb_Control_DACToVoltage(*value,4096,0,2048); + float voltage=Feb_Control_DACToVoltage(*value,4096,0,2048); - printf("\tDac number %d (%s) of dst %d set to %d (%f mV).\n",ch,Module_dac_names[ch],dst_num,*value,voltage); - return 1; + printf("\tDac number %d (%s) of dst %d set to %d (%f mV).\n",ch,Module_dac_names[ch],dst_num,*value,voltage); + return 1; } /* @@ -946,7 +946,7 @@ float GetDAC(string s){ return dac[n]; } -*/ + */ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ printf("Setting Trimbits\n"); @@ -1001,7 +1001,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ /* int super_column_start_position_l = 1024*row + l_r *256 + sc*8; //256 per row, 8 per super column int super_column_start_position_r = 1024*row + 512 + l_r *256 + sc*8; //256 per row, 8 per super column -*/ + */ int chip_sc = 31 - sc; trimbits_to_load_l[offset+chip_sc] = 0; trimbits_to_load_r[offset+chip_sc] = 0; @@ -1057,7 +1057,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ unsigned int* Feb_Control_GetTrimbits(){ - return Feb_Control_last_downloaded_trimbits; + return Feb_Control_last_downloaded_trimbits; } @@ -1067,61 +1067,48 @@ unsigned int Feb_Control_AddressToAll(){printf("in Feb_Control_AddressToAll()\n" - if(moduleSize==0) return 0; +if(moduleSize==0) return 0; - if(Module_BottomAddressIsValid(&modules[1])){ - //printf("************* bottom\n"); - //if(Feb_Control_am_i_master) - return Module_GetBottomLeftAddress(&modules[1])|Module_GetBottomRightAddress(&modules[1]); - // else return 0; - } - // printf("************* top\n"); +if(Module_BottomAddressIsValid(&modules[1])){ + //printf("************* bottom\n"); + //if(Feb_Control_am_i_master) + return Module_GetBottomLeftAddress(&modules[1])|Module_GetBottomRightAddress(&modules[1]); + // else return 0; +} +// printf("************* top\n"); - return Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1]); - //return Module_GetTopLeftAddress(&modules[0])|Module_GetTopRightAddress(&modules[0]); +return Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1]); +//return Module_GetTopLeftAddress(&modules[0])|Module_GetTopRightAddress(&modules[0]); } int Feb_Control_SetCommandRegister(unsigned int cmd){ - return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0); + return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0); } int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status){ - if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){ - printf("Error: reading status register.\n"); - return 0; - } + if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){ + printf("Error: reading status register.\n"); + return 0; + } - *ret_status = (0x00FF0000 & *ret_status) >> 16; - return 1; + *ret_status = (0x02FF0000 & *ret_status) >> 16; + return 1; } int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){ - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){ - printf("Warning: could not start.\n"); - return 0; - } - - return Feb_Control_WaitForFinishedFlag(sleep_time_us); + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){ + printf("Warning: could not start.\n"); + return 0; + } + + return Feb_Control_WaitForFinishedFlag(sleep_time_us); } -int Feb_Control_WaitForFinishedFlag(int sleep_time_us){ - int is_running = Feb_Control_AcquisitionInProgress(); - while(is_running){ - usleep(sleep_time_us); - is_running = Feb_Control_AcquisitionInProgress(); - } - if(is_running!=0){ - printf("\n\nWarning WaitForFinishedFlag comunication problem..\n\n"); - return 0; //communication problem - } - - return 1; -} int Feb_Control_AcquisitionInProgress(){ unsigned int status_reg_r=0,status_reg_l=0; @@ -1136,286 +1123,333 @@ int Feb_Control_AcquisitionInProgress(){ }else{ if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r))) - {printf("ERROR: Trouble reading Status register. top right address\n"); - if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[0]),&status_reg_r))) - printf("ERROR: error with normal register\n"); - else - printf("**********NO error reading normal register\n"); - return 0;} + {printf("ERROR: Trouble reading Status register. top right address\n");return 0;} if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l))) {printf("ERROR: Trouble reading Status register. top left address\n");return 0;} } - if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) {/*printf("**runningggg\n");*/return 1;} - /* - if(!(GetDAQStatusRegister(modules[i]->Module_GetTopLeftAddress(),status_reg_r)&&GetDAQStatusRegister(modules[i]->Module_GetTopRightAddress(),status_reg_l))){ - for(int i=0;i<2;i++) printf("Waring trouble reading status register. Returning zero to avoid inifite loops, this could cause trouble!"\n");; - return 0; //to avoid inifite loops - } - if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) return 1; - } - */ - - /*printf("**idle\n");*/ - return 0; //i.e. not running (status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING; + //running + if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) {/*printf("**runningggg\n");*/ + return 1; + } + //idle + return 0; } -int Feb_Control_Reset(){ - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){ - printf("Warning: Could not reset daq, no response.\n"); - return 0; - } - return Feb_Control_WaitForFinishedFlag(5000); +int Feb_Control_AcquisitionStartedBit(){ + unsigned int status_reg_r=0,status_reg_l=0; + + int ind = Feb_Control_current_index; + if(Module_BottomAddressIsValid(&modules[ind])){ + + if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[ind]),&status_reg_r))) + {printf("ERROR: Trouble reading Status register. bottom right address\n");return -1;} + if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l))) + {printf("ERROR: Trouble reading Status register. bottom left address\n");return -1;} + + }else{ + if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r))) + {printf("ERROR: Trouble reading Status register. top right address\n"); return -1;} + if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l))) + {printf("ERROR: Trouble reading Status register. top left address\n");return -1;} + } + + //doesnt mean it started, just the bit + if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUN_TOGGLE) + return 1; + + return 0; +} + + + +int Feb_Control_WaitForFinishedFlag(int sleep_time_us){ + int is_running = Feb_Control_AcquisitionInProgress(); + while(is_running){ + usleep(sleep_time_us); + is_running = Feb_Control_AcquisitionInProgress(); + } + if(is_running!=0){ + printf("\n\nWarning WaitForFinishedFlag comunication problem..\n\n"); + return 0; //communication problem + } + + return 1; +} + + +int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){ + int value = prev_flag; + while(value == prev_flag){ + usleep(sleep_time_us); + value = Feb_Control_AcquisitionStartedBit(); + } + + //did not start + if(value == -1) + return 0; + + return 1; +} + + +int Feb_Control_Reset(){ + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){ + printf("Warning: Could not reset daq, no response.\n"); + return 0; + } + + return Feb_Control_WaitForFinishedFlag(5000); } int Feb_Control_SetStaticBits(){ - //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64 - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - printf("Warning: Could not set static bits\n"); - return 0; - } + //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64 + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + printf("Warning: Could not set static bits\n"); + return 0; + } - return 1; + return 1; } int Feb_Control_SetStaticBits1(unsigned int the_static_bits){ Feb_Control_staticBits = the_static_bits; - return Feb_Control_SetStaticBits(); + return Feb_Control_SetStaticBits(); } int Feb_Control_SetTestModeVariable(int on){ - if(on) Feb_Control_staticBits |= DAQ_STATIC_BIT_CHIP_TEST; //setting test bit to high - else Feb_Control_staticBits &= (~DAQ_STATIC_BIT_CHIP_TEST); //setting test bit to low - return 1; + if(on) Feb_Control_staticBits |= DAQ_STATIC_BIT_CHIP_TEST; //setting test bit to high + else Feb_Control_staticBits &= (~DAQ_STATIC_BIT_CHIP_TEST); //setting test bit to low + return 1; } int Feb_Control_GetTestModeVariable(){ - return Feb_Control_staticBits&DAQ_STATIC_BIT_CHIP_TEST; + return Feb_Control_staticBits&DAQ_STATIC_BIT_CHIP_TEST; } int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo){ - static unsigned int everything_but_bit_mode = DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_CHIP_TEST|DAQ_STATIC_BIT_ROTEST; - if(four_eight_sixteen_or_thirtytwo==4){ - Feb_Control_staticBits = DAQ_STATIC_BIT_M4 | (Feb_Control_staticBits&everything_but_bit_mode); //leave test bits in currernt state - Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - }else if(four_eight_sixteen_or_thirtytwo==8){ - Feb_Control_staticBits = DAQ_STATIC_BIT_M8 | (Feb_Control_staticBits&everything_but_bit_mode); - Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - }else if(four_eight_sixteen_or_thirtytwo==16){ - Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits&everything_but_bit_mode); - Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - }else if(four_eight_sixteen_or_thirtytwo==32){ - Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits&everything_but_bit_mode); - Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; - }else{ - printf("Warning: dynamic range (%d) not valid, not setting bit mode.\n",four_eight_sixteen_or_thirtytwo); - printf("Set dynamic range int must equal 4,8 16, or 32.\n"); - return 0; - } + static unsigned int everything_but_bit_mode = DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_CHIP_TEST|DAQ_STATIC_BIT_ROTEST; + if(four_eight_sixteen_or_thirtytwo==4){ + Feb_Control_staticBits = DAQ_STATIC_BIT_M4 | (Feb_Control_staticBits&everything_but_bit_mode); //leave test bits in currernt state + Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; + }else if(four_eight_sixteen_or_thirtytwo==8){ + Feb_Control_staticBits = DAQ_STATIC_BIT_M8 | (Feb_Control_staticBits&everything_but_bit_mode); + Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; + }else if(four_eight_sixteen_or_thirtytwo==16){ + Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits&everything_but_bit_mode); + Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; + }else if(four_eight_sixteen_or_thirtytwo==32){ + Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits&everything_but_bit_mode); + Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; + }else{ + printf("Warning: dynamic range (%d) not valid, not setting bit mode.\n",four_eight_sixteen_or_thirtytwo); + printf("Set dynamic range int must equal 4,8 16, or 32.\n"); + return 0; + } - printf("Dynamic range set to: %d\n",four_eight_sixteen_or_thirtytwo); - return 1; + printf("Dynamic range set to: %d\n",four_eight_sixteen_or_thirtytwo); + return 1; } unsigned int Feb_Control_GetDynamicRange(){ - if(Feb_Control_subFrameMode&DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) return 32; - else if(DAQ_STATIC_BIT_M4&Feb_Control_staticBits) return 4; - else if(DAQ_STATIC_BIT_M8&Feb_Control_staticBits) return 8; + if(Feb_Control_subFrameMode&DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) return 32; + else if(DAQ_STATIC_BIT_M4&Feb_Control_staticBits) return 4; + else if(DAQ_STATIC_BIT_M8&Feb_Control_staticBits) return 8; - return 16; + return 16; } int Feb_Control_SetReadoutSpeed(unsigned int readout_speed){ //0->full,1->half,2->quarter or 3->super_slow Feb_Control_acquireNReadoutMode &= (~DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED); - if(readout_speed==1){ - Feb_Control_acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_HALF_SPEED; - printf("Everything at half speed, ie. reading with 50 MHz main clk (half speed) ....\n"); - }else if(readout_speed==2){ - Feb_Control_acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_QUARTER_SPEED; - printf("Everything at quarter speed, ie. reading with 25 MHz main clk (quarter speed) ....\n"); - }else if(readout_speed==3){ - Feb_Control_acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED; - printf("Everything at super slow speed, ie. reading with ~0.200 MHz main clk (super slow speed) ....\n"); - }else{ - if(readout_speed){ - printf("Warning readout speed %d unknown, defaulting to full speed.\n",readout_speed); - printf("Everything at full speed, ie. reading with 100 MHz main clk (full speed) ....\n"); - return 0; - } - printf("Everything at full speed, ie. reading with 100 MHz main clk (full speed) ....\n"); - } + if(readout_speed==1){ + Feb_Control_acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_HALF_SPEED; + printf("Everything at half speed, ie. reading with 50 MHz main clk (half speed) ....\n"); + }else if(readout_speed==2){ + Feb_Control_acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_QUARTER_SPEED; + printf("Everything at quarter speed, ie. reading with 25 MHz main clk (quarter speed) ....\n"); + }else if(readout_speed==3){ + Feb_Control_acquireNReadoutMode |= DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED; + printf("Everything at super slow speed, ie. reading with ~0.200 MHz main clk (super slow speed) ....\n"); + }else{ + if(readout_speed){ + printf("Warning readout speed %d unknown, defaulting to full speed.\n",readout_speed); + printf("Everything at full speed, ie. reading with 100 MHz main clk (full speed) ....\n"); + return 0; + } + printf("Everything at full speed, ie. reading with 100 MHz main clk (full speed) ....\n"); + } - return 1; + return 1; } int Feb_Control_SetReadoutMode(unsigned int readout_mode){ //0->parallel,1->non-parallel,2-> safe_mode Feb_Control_acquireNReadoutMode &= (~DAQ_NEXPOSURERS_PARALLEL_MODE); - if(readout_mode==1){ - Feb_Control_acquireNReadoutMode |= DAQ_NEXPOSURERS_NORMAL_NONPARALLEL_MODE; - printf("Readout mode set to normal non-parallel readout mode ... \n");; - }else if(readout_mode==2){ - Feb_Control_acquireNReadoutMode |= DAQ_NEXPOSURERS_SAFEST_MODE_ROW_CLK_BEFORE_MODE; - printf("Readout mode set to safest mode, row clk before main clk readout sequence .... \n");; - }else{ - Feb_Control_acquireNReadoutMode |= DAQ_NEXPOSURERS_PARALLEL_MODE; - if(readout_mode){ - printf("Warning readout mode %d) unknown, defaulting to full speed.\n",readout_mode); - printf("Readout mode set to parrallel acquire/read mode .... \n");; - return 0; - } - printf("Readout mode set to parrallel acquire/read mode .... \n");; - } + if(readout_mode==1){ + Feb_Control_acquireNReadoutMode |= DAQ_NEXPOSURERS_NORMAL_NONPARALLEL_MODE; + printf("Readout mode set to normal non-parallel readout mode ... \n");; + }else if(readout_mode==2){ + Feb_Control_acquireNReadoutMode |= DAQ_NEXPOSURERS_SAFEST_MODE_ROW_CLK_BEFORE_MODE; + printf("Readout mode set to safest mode, row clk before main clk readout sequence .... \n");; + }else{ + Feb_Control_acquireNReadoutMode |= DAQ_NEXPOSURERS_PARALLEL_MODE; + if(readout_mode){ + printf("Warning readout mode %d) unknown, defaulting to full speed.\n",readout_mode); + printf("Readout mode set to parrallel acquire/read mode .... \n");; + return 0; + } + printf("Readout mode set to parrallel acquire/read mode .... \n");; + } - return 1; + return 1; } int Feb_Control_SetTriggerMode(unsigned int trigger_mode,int polarity){ - //"00"-> internal exposure time and period, - //"01"-> external acquistion start and internal exposure time and period, - //"10"-> external start trigger and internal exposure time, - //"11"-> external triggered start and stop of exposures + //"00"-> internal exposure time and period, + //"01"-> external acquistion start and internal exposure time and period, + //"10"-> external start trigger and internal exposure time, + //"11"-> external triggered start and stop of exposures Feb_Control_triggerMode = (~DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP); - if(trigger_mode == 1){ - Feb_Control_triggerMode = DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START; - printf("Trigger mode: external start of acquisition sequence, internal exposure length and period.\n");; - }else if(trigger_mode == 2){ - Feb_Control_triggerMode = DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START; - printf("Trigger mode: external image start, internal exposure time.\n");; - }else if(trigger_mode == 3){ - Feb_Control_triggerMode = DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP; - printf("Trigger mode: externally controlled, external image window (start and stop).\n");; - }else{ - Feb_Control_triggerMode = DAQ_NEXPOSURERS_INTERNAL_ACQUISITION; - if(trigger_mode) printf("Warning trigger %d) unknown, defaulting to internal triggering.\n",trigger_mode);; + if(trigger_mode == 1){ + Feb_Control_triggerMode = DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START; + printf("Trigger mode: external start of acquisition sequence, internal exposure length and period.\n");; + }else if(trigger_mode == 2){ + Feb_Control_triggerMode = DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START; + printf("Trigger mode: external image start, internal exposure time.\n");; + }else if(trigger_mode == 3){ + Feb_Control_triggerMode = DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP; + printf("Trigger mode: externally controlled, external image window (start and stop).\n");; + }else{ + Feb_Control_triggerMode = DAQ_NEXPOSURERS_INTERNAL_ACQUISITION; + if(trigger_mode) printf("Warning trigger %d) unknown, defaulting to internal triggering.\n",trigger_mode);; - printf("Trigger mode: acquisition internally controlled exposure length and period.\n");; - return trigger_mode==0; - } + printf("Trigger mode: acquisition internally controlled exposure length and period.\n");; + return trigger_mode==0; + } - if(polarity){ - Feb_Control_triggerMode |= DAQ_NEXPOSURERS_EXTERNAL_TRIGGER_POLARITY; - printf("External trigger polarity set to positive.\n");; - }else{ - Feb_Control_triggerMode &= (~DAQ_NEXPOSURERS_EXTERNAL_TRIGGER_POLARITY); - printf("External trigger polarity set to negitive.\n");; - } + if(polarity){ + Feb_Control_triggerMode |= DAQ_NEXPOSURERS_EXTERNAL_TRIGGER_POLARITY; + printf("External trigger polarity set to positive.\n");; + }else{ + Feb_Control_triggerMode &= (~DAQ_NEXPOSURERS_EXTERNAL_TRIGGER_POLARITY); + printf("External trigger polarity set to negitive.\n");; + } - return 1; + return 1; } int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity){ - if(use_external_enable){ - Feb_Control_externalEnableMode |= DAQ_NEXPOSURERS_EXTERNAL_ENABLING; - printf("External enabling enabled, "); - if(polarity){ - Feb_Control_externalEnableMode |= DAQ_NEXPOSURERS_EXTERNAL_ENABLING_POLARITY; - printf(", polarity set to positive.\n");; - }else{ - Feb_Control_externalEnableMode &= (~DAQ_NEXPOSURERS_EXTERNAL_ENABLING_POLARITY); - printf(", polarity set to negative.\n");; - } - }else{ - Feb_Control_externalEnableMode &= (~DAQ_NEXPOSURERS_EXTERNAL_ENABLING); - printf("External enabling disabled.\n");; - } + if(use_external_enable){ + Feb_Control_externalEnableMode |= DAQ_NEXPOSURERS_EXTERNAL_ENABLING; + printf("External enabling enabled, "); + if(polarity){ + Feb_Control_externalEnableMode |= DAQ_NEXPOSURERS_EXTERNAL_ENABLING_POLARITY; + printf(", polarity set to positive.\n");; + }else{ + Feb_Control_externalEnableMode &= (~DAQ_NEXPOSURERS_EXTERNAL_ENABLING_POLARITY); + printf(", polarity set to negative.\n");; + } + }else{ + Feb_Control_externalEnableMode &= (~DAQ_NEXPOSURERS_EXTERNAL_ENABLING); + printf("External enabling disabled.\n");; + } - return 1; + return 1; } int Feb_Control_SetNExposures(unsigned int n_images){ - if(!n_images){ - printf("Warning nimages must be greater than zero.%d\n",n_images); - return 0; - } + if(!n_images){ + printf("Warning nimages must be greater than zero.%d\n",n_images); + return 0; + } - Feb_Control_nimages = n_images; - printf("Number of images set to: %d\n",Feb_Control_nimages); - return 1; + Feb_Control_nimages = n_images; + printf("Number of images set to: %d\n",Feb_Control_nimages); + return 1; } unsigned int Feb_Control_GetNExposures(){return Feb_Control_nimages;} int Feb_Control_SetExposureTime(double the_exposure_time_in_sec){ Feb_Control_exposure_time_in_sec = the_exposure_time_in_sec; - printf("Exposure time set to: %f\n",Feb_Control_exposure_time_in_sec); - return 1; + printf("Exposure time set to: %f\n",Feb_Control_exposure_time_in_sec); + return 1; } double Feb_Control_GetExposureTime(){return Feb_Control_exposure_time_in_sec;} int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec){ Feb_Control_exposure_period_in_sec = the_exposure_period_in_sec; - printf("Exposure period set to: %f\n",Feb_Control_exposure_period_in_sec); - return 1; + printf("Exposure period set to: %f\n",Feb_Control_exposure_period_in_sec); + return 1; } double Feb_Control_GetExposurePeriod(){return Feb_Control_exposure_period_in_sec;} unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec){ - float n_clk_cycles = round(time_in_sec/10e-9); //200 MHz ctb clk or 100 MHz feb clk + float n_clk_cycles = round(time_in_sec/10e-9); //200 MHz ctb clk or 100 MHz feb clk - unsigned int decoded_time; - if(n_clk_cycles>(pow(2,29)-1)*pow(10,7)){ - float max_time = 10e-9*(pow(2,28)-1)*pow(10,7); - printf("Warning: time exceeds (%f) maximum exposure time of %f sec.\n",time_in_sec,max_time); - printf("\t Setting to maximum %f us.\n",max_time); - decoded_time = 0xffffffff; - }else{ - int power_of_ten = 0; - while(n_clk_cycles>pow(2,29)-1){ power_of_ten++; n_clk_cycles = round(n_clk_cycles/10.0);} - decoded_time = (int)(n_clk_cycles)<<3 | (int)(power_of_ten); - } + unsigned int decoded_time; + if(n_clk_cycles>(pow(2,29)-1)*pow(10,7)){ + float max_time = 10e-9*(pow(2,28)-1)*pow(10,7); + printf("Warning: time exceeds (%f) maximum exposure time of %f sec.\n",time_in_sec,max_time); + printf("\t Setting to maximum %f us.\n",max_time); + decoded_time = 0xffffffff; + }else{ + int power_of_ten = 0; + while(n_clk_cycles>pow(2,29)-1){ power_of_ten++; n_clk_cycles = round(n_clk_cycles/10.0);} + decoded_time = (int)(n_clk_cycles)<<3 | (int)(power_of_ten); + } - return decoded_time; + return decoded_time; } int Feb_Control_ResetChipCompletely(){ - if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - printf("Warning: could not ResetChipCompletely().\n");; - return 0; - } + if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + printf("Warning: could not ResetChipCompletely().\n");; + return 0; + } - return 1; + return 1; } void Feb_Control_PrintAcquisitionSetup(){ - time_t rawtime; - time(&rawtime); - struct tm *timeinfo = localtime(&rawtime); + time_t rawtime; + time(&rawtime); + struct tm *timeinfo = localtime(&rawtime); - printf("\nStarting an exposure: %s",asctime(timeinfo)); - printf("\t Dynamic range nbits: %d\n",Feb_Control_GetDynamicRange()); - printf("\t Trigger mode: 0x%x\n",Feb_Control_triggerMode); - printf("\t Number of exposures: %d\n",Feb_Control_GetNExposures()); - printf("\t Exsposure time (if used): %f seconds.\n",Feb_Control_exposure_time_in_sec); - printf("\t Exsposure period (if used): %f seconds.\n\n\n",Feb_Control_exposure_period_in_sec); + printf("\nStarting an exposure: %s",asctime(timeinfo)); + printf("\t Dynamic range nbits: %d\n",Feb_Control_GetDynamicRange()); + printf("\t Trigger mode: 0x%x\n",Feb_Control_triggerMode); + printf("\t Number of exposures: %d\n",Feb_Control_GetNExposures()); + printf("\t Exsposure time (if used): %f seconds.\n",Feb_Control_exposure_time_in_sec); + printf("\t Exsposure period (if used): %f seconds.\n\n\n",Feb_Control_exposure_period_in_sec); } int Feb_Control_SendBitModeToBebServer(){ -/* + /* static int first_pass = 1; static char buffer[1024]; if(first_pass&&!Feb_Control_SetupSendToSocket("localhost",43212)) return 0; else first_pass=0; -*/ - unsigned int just_bit_mode = (DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8) & Feb_Control_staticBits; - unsigned int bit_mode = 16; //default - if(just_bit_mode == DAQ_STATIC_BIT_M4) bit_mode = 4; - else if(just_bit_mode == DAQ_STATIC_BIT_M8) bit_mode = 8; - else if(Feb_Control_subFrameMode&DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) bit_mode = 32; + */ + unsigned int just_bit_mode = (DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8) & Feb_Control_staticBits; + unsigned int bit_mode = 16; //default + if(just_bit_mode == DAQ_STATIC_BIT_M4) bit_mode = 4; + else if(just_bit_mode == DAQ_STATIC_BIT_M8) bit_mode = 8; + else if(Feb_Control_subFrameMode&DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) bit_mode = 32; - if(!Beb_SetUpTransferParameters(bit_mode)){ - printf("Error: sending bit mode ...\n"); - return 0; - } + if(!Beb_SetUpTransferParameters(bit_mode)){ + printf("Error: sending bit mode ...\n"); + return 0; + } - /* + /* bzero(buffer,1024); sprintf(buffer,"setbitmode %d",bit_mode); @@ -1423,8 +1457,8 @@ int Feb_Control_SendBitModeToBebServer(){ printf("Error: sending bit mode ...\n"); return 0; } -*/ - return 1; + */ + return 1; } /* @@ -1460,7 +1494,7 @@ int Feb_Control_WriteNRead(char* message, int length, int max_length){ int n = write(sockfd,message,length); if(n<0) printf("ERROR writing to socket"); - + length = read(sockfd,message,max_length); if(length<0) printf("ERROR reading to socket"); @@ -1468,65 +1502,65 @@ int Feb_Control_WriteNRead(char* message, int length, int max_length){ return length; } -*/ + */ int Feb_Control_PrepareForAcquisition(){//return 1; - static unsigned int reg_nums[20]; - static unsigned int reg_vals[20]; + static unsigned int reg_nums[20]; + static unsigned int reg_vals[20]; - Feb_Control_PrintAcquisitionSetup(); + Feb_Control_PrintAcquisitionSetup(); - // if(!Reset()||!ResetDataStream()){ - if(!Feb_Control_Reset()){ - printf("Trouble reseting daq or data stream...\n");; - return 0; - } + // if(!Reset()||!ResetDataStream()){ + if(!Feb_Control_Reset()){ + printf("Trouble reseting daq or data stream...\n");; + return 0; + } - if(!Feb_Control_SetStaticBits1(Feb_Control_staticBits&(DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8))){ - printf("Trouble setting static bits ...\n");; - return 0; - } + if(!Feb_Control_SetStaticBits1(Feb_Control_staticBits&(DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8))){ + printf("Trouble setting static bits ...\n");; + return 0; + } - if(!Feb_Control_SendBitModeToBebServer()){ - printf("Trouble sending static bits to server ...\n");; - return 0; - } + if(!Feb_Control_SendBitModeToBebServer()){ + printf("Trouble sending static bits to server ...\n");; + return 0; + } - if(!Feb_Control_ResetChipCompletely()){ - printf("Trouble resetting chips ...\n");; - return 0; - } + if(!Feb_Control_ResetChipCompletely()){ + printf("Trouble resetting chips ...\n");; + return 0; + } - reg_nums[0]=DAQ_REG_CTRL; - reg_vals[0]=0; - reg_nums[1]=DAQ_REG_NEXPOSURES; - reg_vals[1]=Feb_Control_nimages; - reg_nums[2]=DAQ_REG_EXPOSURE_TIMER; - reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec); - reg_nums[3]=DAQ_REG_EXPOSURE_REPEAT_TIMER; - reg_vals[3]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec); - reg_nums[4]=DAQ_REG_CHIP_CMDS; - reg_vals[4]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode); + reg_nums[0]=DAQ_REG_CTRL; + reg_vals[0]=0; + reg_nums[1]=DAQ_REG_NEXPOSURES; + reg_vals[1]=Feb_Control_nimages; + reg_nums[2]=DAQ_REG_EXPOSURE_TIMER; + reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec); + reg_nums[3]=DAQ_REG_EXPOSURE_REPEAT_TIMER; + reg_vals[3]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec); + reg_nums[4]=DAQ_REG_CHIP_CMDS; + reg_vals[4]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode); - // if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){ - if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),5,reg_nums,reg_vals,0,0)){ - printf("Trouble starting acquisition....\n");; - return 0; - } - //*/ + // if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){ + if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),5,reg_nums,reg_vals,0,0)){ + printf("Trouble starting acquisition....\n");; + return 0; + } + //*/ - /* if(!Feb_Control_am_i_master) + /* if(!Feb_Control_am_i_master) Feb_Control_StartAcquisition();*/ - return 1; + return 1; } int Feb_Control_StartAcquisition(){printf("****** starting acquisition********* \n"); - static unsigned int reg_nums[20]; - static unsigned int reg_vals[20]; +static unsigned int reg_nums[20]; +static unsigned int reg_vals[20]; /* Feb_Control_PrintAcquisitionSetup(); @@ -1540,7 +1574,7 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition********* printf("Trouble setting static bits ...\n");; return 0; } - + if(!Feb_Control_SendBitModeToBebServer()){ printf("Trouble sending static bits to server ...\n");; return 0; @@ -1560,12 +1594,12 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition********* reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec); reg_nums[3]=DAQ_REG_EXPOSURE_REPEAT_TIMER; reg_vals[3]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec); - */ + */ - /* +/* reg_nums[4]=DAQ_REG_CHIP_CMDS; reg_vals[4]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode); - */ + */ /* if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),4,reg_nums,reg_vals,0,0)){ @@ -1599,22 +1633,22 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition********* printf("Trouble starting acquisition....\n");; return 0; } -*/ - ///* - int i; - for(i=0;i<14;i++){ - reg_nums[i]=DAQ_REG_CTRL; - reg_vals[i]=0; - } - reg_nums[14]=DAQ_REG_CTRL; - reg_vals[14]=ACQ_CTRL_START; + */ +///* +int i; +for(i=0;i<14;i++){ + reg_nums[i]=DAQ_REG_CTRL; + reg_vals[i]=0; +} +reg_nums[14]=DAQ_REG_CTRL; +reg_vals[14]=ACQ_CTRL_START; - if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){ - printf("Trouble starting acquisition....\n");; - return 0; - } - //*/ - /* +if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){ + printf("Trouble starting acquisition....\n");; + return 0; +} +//*/ +/* int i; for(i=5;i<19;i++){ reg_nums[i]=DAQ_REG_CTRL; @@ -1622,19 +1656,19 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition********* } reg_nums[19]=DAQ_REG_CTRL; reg_vals[19]=ACQ_CTRL_START; - + if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),20,reg_nums,reg_vals,0,0)){ printf("Trouble starting acquisition....\n");; return 0; } -*/ + */ //*/ - return 1; +return 1; } int Feb_Control_StopAcquisition(){ - return Feb_Control_Reset(); + return Feb_Control_Reset(); } @@ -1644,5 +1678,5 @@ int Feb_Control_SaveAllTrimbitsTo(int value){ int i; for(i=0;i