diff --git a/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c b/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c index 0b623c757..1a59ba186 100755 --- a/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c @@ -1212,6 +1212,7 @@ int64_t set64BitReg(int64_t value, int aLSB, int aMSB){ v64=value>> 32; vMSB=v64&(0xffffffff); bus_w(aMSB,vMSB); + printf("Wreg64(%x,%x) %08x %08x %016llx\n", aLSB>>11, aMSB>>11, vLSB, vMSB, value); } return get64BitReg(aLSB, aMSB); @@ -1295,6 +1296,7 @@ int64_t getDelay(){ } int64_t setTrains(int64_t value){ + printf("Set cycles %lld\n",value); return set64BitReg(value, SET_CYCLES_LSB_REG, SET_CYCLES_MSB_REG); } @@ -2075,12 +2077,21 @@ u_int16_t* fifo_read_event(int ns) /* dma_memcpy(now_ptr,values ,dataBytes); */ /* #else */ - a = bus_r(LOOK_AT_ME_REG); + a = bus_r(LOOK_AT_ME_REG); //#ifdef VERBOSE - printf("%08x\n",a); + // printf("%d %08x\n",ns,a); bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos - bus_w16(DUMMY_REG,0); - // i=0;// + + bus_w16(DUMMY_REG,0); + + /* for (i=0; i<32; i++) { */ + /* bus_w16(DUMMY_REG,i); */ + /* printf("%04x ",bus_r16(FIFO_STATUS_REG)); */ + /* // a = bus_r(LOOK_AT_ME_REG); */ + /* // printf("%d %08x\n",i,a); */ + /* } */ + /* printf("\n"); */ + // i=0;// /* for (i=0; i<32; i++) { */ /* /\* while (((adcDisableMask&(3<<((i)*2)))>>((i)*2))==3) { *\/ */ @@ -2110,13 +2121,13 @@ u_int16_t* fifo_read_event(int ns) *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG);//*values;//bus_r(FIFO_DATA_REG); - if (i!=0 || ns!=0) { + if (i!=0 || ns!=0) { a=0; while (*((u_int16_t*)now_ptr)==*((u_int16_t*)(now_ptr)-1) && a++<10) { - // printf("******************** %d: fifo %d: new %08x old %08x\n ",ns, i, *((u_int32_t*)now_ptr),*((u_int32_t*)(now_ptr)-1)); - *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG);//*values; - // printf("%d-",i); + // printf("******************** %d: fifo %d: new %08x old %08x\n ",ns, i, *((u_int32_t*)now_ptr),*((u_int32_t*)(now_ptr)-1)); + *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG);//*values; + // printf("%d-",i); } } @@ -2130,9 +2141,9 @@ u_int16_t* fifo_read_event(int ns) bus_w16(DUMMY_REG,i+1); - a = bus_r(LOOK_AT_ME_REG); + // a = bus_r(LOOK_AT_ME_REG); + // printf("%d %08x\n",i,a); //#ifdef VERBOSE - printf("%d %08x\n",i,a); // } // *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG); } @@ -2449,6 +2460,95 @@ int writeADC(int addr, int val) { return OK; } +int prepareSlowADC() { + + + + u_int16_t vv; + u_int16_t codata; + + u_int32_t valw; + int i, j; + + int cnv_bit=16, sdi_bit=17, sck_bit=18; + + for (j=0; j<2; j++) { + + + valw=(1<=0) { if (bus_r(POWER_ON_REG)&(1<<(16+pwrindex))){ - retval1=vmax-(retval*1900)/4095; - vmax=2700-(getDacRegister(19)*1000)/4095-200; + vmax=2700-(getDacRegister(19)*1000)/4095-200; + retval1=vmax-(retval*(vmax-vmin))/4095; if (retval1>vmax) retval1=vmax; if (retval1onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -3984,29 +3984,29 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ } else { //std::cout<< "offline " << std::endl; if (t>=0) - thisDetector->timerValue[index]=t; + thisDetector->timerValue[index]=t; if((thisDetector->myDetectorType==GOTTHARD)|| - (thisDetector->myDetectorType==PROPIX)|| - (thisDetector->myDetectorType==JUNGFRAU)|| - (thisDetector->myDetectorType==MOENCH)) - thisDetector->timerValue[PROBES_NUMBER]=0; + (thisDetector->myDetectorType==PROPIX)|| + (thisDetector->myDetectorType==JUNGFRAU)|| + (thisDetector->myDetectorType==MOENCH)) + thisDetector->timerValue[PROBES_NUMBER]=0; } } else { - if (t>=0) - thisDetector->timerValue[index]=t; + if (t>=0) + thisDetector->timerValue[index]=t; } #ifdef VERBOSE std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl; #endif if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { - setDynamicRange(); - //cout << "Changing probes: data size = " << thisDetector->dataBytes <timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]); - if(args[1] != -1) args[1]=retval; - }else{ + args[0] = FRAME_NUMBER; + retval = abs(thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]); + if(args[1] != -1) args[1]=retval; + }else{ #ifdef VERBOSE - std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl; + std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl; #endif - args[0] = FRAME_PERIOD; - //if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period - if(!retval) args[1] = timerValue[ACQUISITION_TIME]; - } + args[0] = FRAME_PERIOD; + //if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period + if(!retval) args[1] = timerValue[ACQUISITION_TIME]; + } + - - if (connectData() == OK) - ret=thisReceiver->sendIntArray(fnum2,ut,args); - disconnectData(); - if((ut != retval)|| (ret==FAIL)){ - ret = FAIL; - if(index==FRAME_PERIOD){ - //exptime sent if acq period = 0 - if(retval){ - cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl; - setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); - } - }else{ - cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl; - setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); - } - } - - if(ret==FORCE_UPDATE) - updateReceiver(); - } + if (connectData() == OK) + ret=thisReceiver->sendIntArray(fnum2,ut,args); + disconnectData(); + if((ut != retval)|| (ret==FAIL)){ + ret = FAIL; + if(index==FRAME_PERIOD){ + //exptime sent if acq period = 0 + if(retval){ + cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl; + setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); + } + }else{ + cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl; + setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); } + } + + if(ret==FORCE_UPDATE) + updateReceiver(); + } + } } return thisDetector->timerValue[index]; }; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index f26f99011..8407e9aca 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -791,6 +791,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC; i++; + descrToFuncMap[i].m_pFuncName="adc"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC; + i++; + + /* r/w timers */ descrToFuncMap[i].m_pFuncName="timing"; // @@ -3859,6 +3864,7 @@ string slsDetectorCommand::helpDAC(int narg, char *args[], int action) { string slsDetectorCommand::cmdADC(int narg, char *args[], int action) { dacIndex adc; + int idac; // double val=-1; char answer[1000]; @@ -3866,8 +3872,11 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) { return helpADC(narg, args, action); else if (action==PUT_ACTION) return string("cannot set ")+cmd; - - if (cmd=="temp_adc") + + if (sscanf(args[0],"adc:%d",&idac)==1) { + printf("chiptestboard!\n"); + adc=(dacIndex)(idac+1000); + } else if (cmd=="temp_adc") adc=TEMPERATURE_ADC; else if (cmd=="temp_fpga") adc=TEMPERATURE_FPGA; @@ -3893,7 +3902,11 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) { sprintf(answer,"%f",myDet->getADC(adc)); #endif //if ((adc == TEMPERATURE_ADC) || (adc == TEMPERATURE_FPGA)) - strcat(answer,"°C"); + if (adc<1000) + strcat(answer,"°C"); + else + strcat(answer,"mV"); + return string(answer); } @@ -4001,12 +4014,13 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) { rval=(double)ret*1E-9; else rval=ret; + // cout << "here!"<< endl; //set frame index if (index==FRAME_NUMBER || index==CYCLES_NUMBER ){ - if ((myDet->setTimer(FRAME_NUMBER,-1)*myDet->setTimer(CYCLES_NUMBER,-1))>1) - myDet->setFrameIndex(0); - else - myDet->setFrameIndex(-1); + if ((myDet->setTimer(FRAME_NUMBER,-1)*myDet->setTimer(CYCLES_NUMBER,-1))>1) { + myDet->setFrameIndex(0); + } else + myDet->setFrameIndex(-1); }