Added adc command for chiptestboard

This commit is contained in:
bergamaschi 2016-09-05 10:49:47 +02:00
parent f8b62bba64
commit 988426dc96
7 changed files with 194 additions and 77 deletions

View File

@ -1212,6 +1212,7 @@ int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
v64=value>> 32; v64=value>> 32;
vMSB=v64&(0xffffffff); vMSB=v64&(0xffffffff);
bus_w(aMSB,vMSB); bus_w(aMSB,vMSB);
printf("Wreg64(%x,%x) %08x %08x %016llx\n", aLSB>>11, aMSB>>11, vLSB, vMSB, value);
} }
return get64BitReg(aLSB, aMSB); return get64BitReg(aLSB, aMSB);
@ -1295,6 +1296,7 @@ int64_t getDelay(){
} }
int64_t setTrains(int64_t value){ int64_t setTrains(int64_t value){
printf("Set cycles %lld\n",value);
return set64BitReg(value, SET_CYCLES_LSB_REG, SET_CYCLES_MSB_REG); 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); */ /* dma_memcpy(now_ptr,values ,dataBytes); */
/* #else */ /* #else */
a = bus_r(LOOK_AT_ME_REG); a = bus_r(LOOK_AT_ME_REG);
//#ifdef VERBOSE //#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,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++) { */ /* for (i=0; i<32; i++) { */
/* /\* while (((adcDisableMask&(3<<((i)*2)))>>((i)*2))==3) { *\/ */ /* /\* 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); *((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; a=0;
while (*((u_int16_t*)now_ptr)==*((u_int16_t*)(now_ptr)-1) && a++<10) { 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)); // 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; *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG);//*values;
// printf("%d-",i); // printf("%d-",i);
} }
} }
@ -2130,9 +2141,9 @@ u_int16_t* fifo_read_event(int ns)
bus_w16(DUMMY_REG,i+1); 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 //#ifdef VERBOSE
printf("%d %08x\n",i,a);
// } // }
// *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG); // *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG);
} }
@ -2449,6 +2460,95 @@ int writeADC(int addr, int val) {
return OK; 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<<cnv_bit) | (1<<sdi_bit);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
valw=(1<<sdi_bit);
bus_w(ADC_WRITE_REG,(valw));
for (i=0;i<16;i++) {
//cldwn
valw=0;
bus_w(ADC_WRITE_REG,valw);
// usleep(0);
bus_w(ADC_WRITE_REG,valw|(1<<sck_bit));
// usleep(0);
bus_w(ADC_WRITE_REG,valw);
}
}
}
int readSlowADC(int ichan) {
u_int16_t vv=0x3c40;
u_int16_t codata=vv | (ichan<<7);
u_int32_t valw;
int i, obit;
int cnv_bit=16, sdi_bit=17, sck_bit=18;
for (ichan=0; ichan<8; ichan++) {
//convert
valw=(1<<cnv_bit);
bus_w(ADC_WRITE_REG,valw);
usleep(20);
valw=(1<<sdi_bit);
bus_w(ADC_WRITE_REG,(valw));
printf("Channel %d ",ichan);
//read
for (i=0;i<16;i++) {
//cldwn
valw=0;
bus_w(ADC_WRITE_REG,valw);
// usleep(0);
bus_w(ADC_WRITE_REG,valw|(1<<sck_bit));
bus_w(ADC_WRITE_REG,valw);
obit=bus_r16(SLOW_ADC_REG)&0x1;
printf("%d",obit);
//write data (i)
// usleep(0);
}
printf("\n");
}
return OK;
}
int prepareADC(){ int prepareADC(){
@ -3401,8 +3501,8 @@ int setPower(int ind, int val) {
if (pwrindex>=0) { if (pwrindex>=0) {
if (bus_r(POWER_ON_REG)&(1<<(16+pwrindex))){ 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) if (retval1>vmax)
retval1=vmax; retval1=vmax;
if (retval1<vmin) if (retval1<vmin)

View File

@ -156,6 +156,7 @@ int allocateRAM();
int writeADC(int addr, int val); int writeADC(int addr, int val);
int prepareADC(); int prepareADC();
int prepareSlowADC();
int clearRAM(); int clearRAM();

View File

@ -139,7 +139,7 @@
#define FRAMES_FROM_START_PG_LSB_REG 36<<11 #define FRAMES_FROM_START_PG_LSB_REG 36<<11
#define FRAMES_FROM_START_PG_MSB_REG 37<<11 #define FRAMES_FROM_START_PG_MSB_REG 37<<11
#define SLOW_ADC_REG 43<<11

View File

@ -131,6 +131,7 @@ int init_detector(int b, int checkType) {
//bus_w16(CONTROL_REG, SYNC_RESET); // reset registers //bus_w16(CONTROL_REG, SYNC_RESET); // reset registers
#endif #endif
prepareSlowADC();
// testFpga(); // testFpga();
// testRAM(); // testRAM();
// printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG)); // printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG));
@ -1222,10 +1223,11 @@ int get_adc(int file_des) {
idac=TEMP_ADC; idac=TEMP_ADC;
break; break;
default: default:
printf("Unknown DAC index %d\n",ind); readSlowADC(ind);
sprintf(mess,"Unknown DAC index %d\n",ind); printf("Unknown DAC index %d\n",ind);
ret=FAIL; sprintf(mess,"Unknown DAC index %d\n",ind);
break; ret=FAIL;
break;
} }
if (ret==OK) if (ret==OK)
@ -2234,8 +2236,8 @@ int set_timer(int file_des) {
retval=setGates(tns); retval=setGates(tns);
break; break;
case PROBES_NUMBER: case PROBES_NUMBER:
sprintf(mess,"can't set timer for moench\n"); sprintf(mess,"can't set timer for moench\n");
ret=FAIL; ret=FAIL;
break; break;
case CYCLES_NUMBER: case CYCLES_NUMBER:
retval=setTrains(tns); retval=setTrains(tns);

View File

@ -3955,9 +3955,9 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
if (index!=MEASUREMENTS_NUMBER) { if (index!=MEASUREMENTS_NUMBER) {
#ifdef VERBOSE //#ifdef VERBOSE
std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl; std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl;
#endif //#endif
if (thisDetector->onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){ if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -3984,29 +3984,29 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
} else { } else {
//std::cout<< "offline " << std::endl; //std::cout<< "offline " << std::endl;
if (t>=0) if (t>=0)
thisDetector->timerValue[index]=t; thisDetector->timerValue[index]=t;
if((thisDetector->myDetectorType==GOTTHARD)|| if((thisDetector->myDetectorType==GOTTHARD)||
(thisDetector->myDetectorType==PROPIX)|| (thisDetector->myDetectorType==PROPIX)||
(thisDetector->myDetectorType==JUNGFRAU)|| (thisDetector->myDetectorType==JUNGFRAU)||
(thisDetector->myDetectorType==MOENCH)) (thisDetector->myDetectorType==MOENCH))
thisDetector->timerValue[PROBES_NUMBER]=0; thisDetector->timerValue[PROBES_NUMBER]=0;
} }
} else { } else {
if (t>=0) if (t>=0)
thisDetector->timerValue[index]=t; thisDetector->timerValue[index]=t;
} }
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl; std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
#endif #endif
if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) {
setDynamicRange(); setDynamicRange();
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl; //cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
} }
/* set progress */ /* set progress */
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) { if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
setTotalProgress(); setTotalProgress();
} }
double r; double r;
@ -4016,51 +4016,51 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
//send acquisiton period/frame number to receiver //send acquisiton period/frame number to receiver
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){ if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){
if(ret != FAIL){ if(ret != FAIL){
retval = thisDetector->timerValue[index]; retval = thisDetector->timerValue[index];
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
int64_t args[2]; int64_t args[2];
args[1] = retval; args[1] = retval;
if((t == -1) && (ret!= FORCE_UPDATE)) args[1] = -1; if((t == -1) && (ret!= FORCE_UPDATE)) args[1] = -1;
if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){ if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl; std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
#endif #endif
args[0] = FRAME_NUMBER; args[0] = FRAME_NUMBER;
retval = abs(thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]); retval = abs(thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]);
if(args[1] != -1) args[1]=retval; if(args[1] != -1) args[1]=retval;
}else{ }else{
#ifdef VERBOSE #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 #endif
args[0] = FRAME_PERIOD; args[0] = FRAME_PERIOD;
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq 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(!retval) args[1] = timerValue[ACQUISITION_TIME];
} }
if (connectData() == OK)
if (connectData() == OK) ret=thisReceiver->sendIntArray(fnum2,ut,args);
ret=thisReceiver->sendIntArray(fnum2,ut,args); disconnectData();
disconnectData(); if((ut != retval)|| (ret==FAIL)){
if((ut != retval)|| (ret==FAIL)){ ret = FAIL;
ret = FAIL; if(index==FRAME_PERIOD){
if(index==FRAME_PERIOD){ //exptime sent if acq period = 0
//exptime sent if acq period = 0 if(retval){
if(retval){ cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl;
cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl; setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); }
} }else{
}else{ cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl;
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));
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
}
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
} }
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
}
} }
return thisDetector->timerValue[index]; return thisDetector->timerValue[index];
}; };

View File

@ -791,6 +791,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++; i++;
descrToFuncMap[i].m_pFuncName="adc"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++;
/* r/w timers */ /* r/w timers */
descrToFuncMap[i].m_pFuncName="timing"; // 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) { string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
dacIndex adc; dacIndex adc;
int idac;
// double val=-1; // double val=-1;
char answer[1000]; char answer[1000];
@ -3866,8 +3872,11 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
return helpADC(narg, args, action); return helpADC(narg, args, action);
else if (action==PUT_ACTION) else if (action==PUT_ACTION)
return string("cannot set ")+cmd; 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; adc=TEMPERATURE_ADC;
else if (cmd=="temp_fpga") else if (cmd=="temp_fpga")
adc=TEMPERATURE_FPGA; adc=TEMPERATURE_FPGA;
@ -3893,7 +3902,11 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
sprintf(answer,"%f",myDet->getADC(adc)); sprintf(answer,"%f",myDet->getADC(adc));
#endif #endif
//if ((adc == TEMPERATURE_ADC) || (adc == TEMPERATURE_FPGA)) //if ((adc == TEMPERATURE_ADC) || (adc == TEMPERATURE_FPGA))
strcat(answer,"°C"); if (adc<1000)
strcat(answer,"°C");
else
strcat(answer,"mV");
return string(answer); return string(answer);
} }
@ -4001,12 +4014,13 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) {
rval=(double)ret*1E-9; rval=(double)ret*1E-9;
else rval=ret; else rval=ret;
// cout << "here!"<< endl;
//set frame index //set frame index
if (index==FRAME_NUMBER || index==CYCLES_NUMBER ){ if (index==FRAME_NUMBER || index==CYCLES_NUMBER ){
if ((myDet->setTimer(FRAME_NUMBER,-1)*myDet->setTimer(CYCLES_NUMBER,-1))>1) if ((myDet->setTimer(FRAME_NUMBER,-1)*myDet->setTimer(CYCLES_NUMBER,-1))>1) {
myDet->setFrameIndex(0); myDet->setFrameIndex(0);
else } else
myDet->setFrameIndex(-1); myDet->setFrameIndex(-1);
} }