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);
} }
@ -2077,9 +2079,18 @@ u_int16_t* fifo_read_event(int ns)
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); 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;// // i=0;//
/* for (i=0; i<32; i++) { */ /* for (i=0; i<32; 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,6 +1223,7 @@ int get_adc(int file_des) {
idac=TEMP_ADC; idac=TEMP_ADC;
break; break;
default: default:
readSlowADC(ind);
printf("Unknown DAC index %d\n",ind); printf("Unknown DAC index %d\n",ind);
sprintf(mess,"Unknown DAC index %d\n",ind); sprintf(mess,"Unknown DAC index %d\n",ind);
ret=FAIL; ret=FAIL;

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));

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];
@ -3867,7 +3873,10 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int 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))
if (adc<1000)
strcat(answer,"°C"); strcat(answer,"°C");
else
strcat(answer,"mV");
return string(answer); return string(answer);
} }
@ -4001,11 +4014,12 @@ 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);
} }