Changeset 10226
- Timestamp:
- 03/04/11 14:33:00 (14 years ago)
- Location:
- fact/FADctrl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/FADctrl/FAD.cc
r10224 r10226 542 542 while (fread(&Data, sizeof(Data), 1, File) == 1) { 543 543 for (unsigned int i=0; i<Boards.size(); i++) if (Data.DNA == Boards[i]->GetStatus().DNA) { 544 PrintMessage("Found calibration data for board %d (%s)\n", i, ctime(&Data.Time));544 PrintMessage("Found calibration for board %d - %s", i, ctime(&Data.Time)); 545 545 Boards[i]->ACalib = Data; 546 546 } … … 566 566 // 567 567 void FAD::cmd_status() { 568 569 int MinCount = std::numeric_limits<int>::max(); 570 unsigned int SlowestBoard = 0; 568 571 569 572 // ==== Print board overview ==== … … 575 578 if (Boards[i]->Active) Count++; 576 579 if (!Boards[i]->CommOK) Error++; 580 if (Boards[i]->Active && Boards[i]->Count < MinCount) { 581 MinCount = Boards[i]->Count; 582 SlowestBoard = i; 583 } 577 584 } 578 585 579 PrintMessage("\rTotal boards: %d (%d communication errors)\n", Boards.size(), Error);586 PrintMessage("\rTotal boards: %d (%d with communication errors)\n", Boards.size(), Error); 580 587 581 588 // Print list of active boards 582 589 PrintMessage("Active are %d boards(s) ", Count); 583 590 for (unsigned int i=0; i<Boards.size(); i++) { 584 if (Boards[i]->Active) PrintMessage(" %d", i); 585 if (!Boards[i]->Active) PrintMessage("!"); 591 if (Boards[i]->Active) PrintMessage(" %d%s", i, Boards[i]->CommOK ? "":"!"); 586 592 } 587 593 PrintMessage("\n"); … … 589 595 // Current mode 590 596 if (Mode == idle) PrintMessage("Current mode is IDLE\n"); 591 else if (Mode == acalib) PrintMessage("Current mode is ACALIB (3x%d events )\n", NumEventsRequested);597 else if (Mode == acalib) PrintMessage("Current mode is ACALIB (3x%d events, slowest board %d has %d events)\n", NumEventsRequested, SlowestBoard, MinCount); 592 598 else if (Mode == datarun) PrintMessage("Current mode is DATARUN (%d events requested, %d events taken)\n", NumEventsRequested, NumEvents); 593 599 … … 623 629 // Board identification 624 630 PrintMessage("Board ID %.4x Firmware revision %.4x Serial %llx\n", S.BoardID, S.FirmwareRevision, S.DNA); 625 PrintMessage("Board time %g s Event counter %d\n", S.BoardTime/1.0e4 , S.EventCounter);626 627 // Slowdata631 PrintMessage("Board time %g s Event counter %d\n", S.BoardTime/1.0e4 , S.EventCounter); 632 633 // Other data 628 634 PrintMessage("Frequency %.2f GHz Phase shift %d PLL lock %d %d %d %d\n", S.Frequency, S.PhaseShift, S.Lock[0], S.Lock[1], S.Lock[2], S.Lock[3]); 629 PrintMessage("DENABLE %d DWRITE %d SPI_clk %d DCM_lock: %dDCM_ready %d\n", S.denable, S.dwrite, S.spi_clk, S.DCM_lock, S.DCM_ready);635 PrintMessage("DENABLE %d DWRITE %d SPI_clk %d DCM_lock %d DCM_ready %d\n", S.denable, S.dwrite, S.spi_clk, S.DCM_lock, S.DCM_ready); 630 636 PrintMessage("DAC %d %d %d %d %d %d %d %d\n", S.DAC[0], S.DAC[1], S.DAC[2], S.DAC[3], S.DAC[4], S.DAC[5], S.DAC[6], S.DAC[7] ); 631 637 PrintMessage("Temperature %.2f %.2f %.2f %.2f", S.Temp[0], S.Temp[1], S.Temp[2], S.Temp[3]); … … 636 642 } 637 643 PrintMessage("\n"); 638 /*639 if (GetBoard(i)->GetStatusReg() & BIT_RUNNING)640 PrintMessage(" Domino wave running\n");641 642 if (GetBoard(i)->GetCtrlReg() & BIT_DMODE)643 PrintMessage(" DMODE circular\n");644 else645 PrintMessage(" DMODE single shot\n");646 647 }*/648 644 } // for() 649 645 } … … 811 807 void FAD::SaveAmplitudeCalibration() { 812 808 813 PrintMessage("Amplitude calibration of all active boards finished, original ROI and DAC set\n");814 815 809 // Open calibration data file 816 810 string Filename = string(getenv("HOME"))+"/FAD_ACal"; … … 822 816 } 823 817 824 // Write calibration information 825 for (unsigned int i=0; i<Boards.size(); i++) { 818 // Write valid calibration information for active boards 819 for (unsigned int i=0; i<Boards.size(); i++) { 820 if (!Boards[i]->Active || Boards[i]->ACalib.Time == -1) continue; 821 826 822 if (fwrite(&Boards[i]->ACalib, sizeof(Boards[i]->ACalib), 1, File) != 1) { 827 823 PrintMessage("Could not write to calibration file '%s'\n", Filename.c_str()); … … 833 829 if (fclose(File) != 0) PrintMessage("Could not close calibration file '%s'\n", Filename.c_str()); 834 830 835 PrintMessage("Appended amplitude calibration informationto file '%s'\n", Filename.c_str());831 PrintMessage("Appended amplitude calibration to file '%s'\n", Filename.c_str()); 836 832 } 837 833 … … 985 981 986 982 // Write channel data (12 bit signed two's complement with out-of-range-bit and leading zeroes) 987 int Count = 0;988 memset(Data , 0, Boards.size()*NChips*NChannels*NBins*sizeof(short));983 int Count = Brd*NChips*NChannels*NBins; 984 memset(Data+Count, 0, NChips*NChannels*NBins*sizeof(short)); 989 985 990 986 Boards[Brd]->Lock(); … … 1022 1018 if (Mode != datarun) continue; 1023 1019 1024 // Check if all event numbers are the same1020 // Check if all event numbers of active boards are the same 1025 1021 bool Same = true; 1026 1022 for (unsigned int i=0; i<Boards.size(); i++) { -
fact/FADctrl/FADBoard.cc
r10224 r10226 146 146 // Perform amplitude calibration in steps 147 147 // 148 // The steps are intended to assure that up to date data is available 148 149 void FADBoard::AmplitudeCalibration() { 149 150 150 enum StateType {wait, init, baseline, gain, secondary}; 151 152 static struct BoardStatus InitialStatus; 153 static vector<unsigned short> ROICmd; 154 static unsigned short DACCmd[] = {htons(CMD_Write | (BADDR_DAC + 1)), 0, htons(CMD_Write | (BADDR_DAC + 2)), 0, htons(CMD_Write | (BADDR_DAC + 3)), 0}; 155 static StateType State = wait; 156 static int Count = 0; 157 158 // Check if mode is amplitude calibration 159 if (m->Mode != m->acalib) { 160 State = init; 161 return; 162 } 151 vector<unsigned short> ROICmd; 152 unsigned short DACCmd[] = {htons(CMD_Write | (BADDR_DAC + 1)), 0, htons(CMD_Write | (BADDR_DAC + 2)), 0, htons(CMD_Write | (BADDR_DAC + 3)), 0}; 153 string Message = string("ACALIBDONE")+Name; 163 154 164 155 switch (State) { 165 // ====== Part A: Initialization ===== 166 case init: 156 // ====== Part A: Check if amplitude calibration should start and initialise ===== 157 case standbye: 158 if (m->Mode != m->acalib) break; 159 167 160 // Invalidate current calibration 168 161 ACalib.Time = -1; 162 Count = 0; 169 163 170 164 // Save initial board status, set all ROIs to 1024 and set DAC values … … 189 183 // ====== Part B: Baseline calibration ===== 190 184 case baseline: 185 // Check for stopping 186 if (m->Mode != m->acalib) { 187 State = cleanup; 188 break; 189 } 190 191 // Average 191 192 for (unsigned int Chip=0; Chip<NChips; Chip++) { 192 193 for (unsigned int Chan=0; Chan<NChannels; Chan++) { … … 199 200 200 201 // Determine baseline if integration finished 201 if (Count == m->NumEventsRequested) {202 for (unsigned int i=0; i<NChips; i++) { 203 for (unsigned int j=0; j<NChannels; j++) {204 for (unsigned int k=0; k<NBins; k++) {205 ACalib.Baseline[i][j][k] = Sum[i][j][k] / m->NumEventsRequested;206 }207 } 208 } 209 210 // Set new DAC values and start accumulation 211 DACCmd[1] = htons(50000);212 DACCmd[3] = htons(50000);213 DACCmd[5] = htons(50000);214 Send(DACCmd, sizeof(DACCmd));215 216 // Clear sum vector and set state to accumulate 217 memset(Sum, 0, sizeof(Sum));218 Count = 0;219 State = gain;220 }202 if (Count < m->NumEventsRequested) break; 203 204 for (unsigned int i=0; i<NChips; i++) { 205 for (unsigned int j=0; j<NChannels; j++) { 206 for (unsigned int k=0; k<NBins; k++) { 207 ACalib.Baseline[i][j][k] = Sum[i][j][k] / m->NumEventsRequested; 208 } 209 } 210 } 211 212 // Set new DAC values and start accumulation 213 DACCmd[1] = htons(50000); 214 DACCmd[3] = htons(50000); 215 DACCmd[5] = htons(50000); 216 Send(DACCmd, sizeof(DACCmd)); 217 218 // Clear sum vector and set state to accumulate 219 memset(Sum, 0, sizeof(Sum)); 220 Count = 0; 221 State = gain; 221 222 break; 222 223 223 224 // ====== Part C: Gain calibration ===== 224 225 case gain: 226 // Check for stopping 227 if (m->Mode != m->acalib) { 228 State = cleanup; 229 break; 230 } 231 232 // Average 225 233 for (unsigned int Chip=0; Chip<NChips; Chip++) { 226 234 for (unsigned int Chan=0; Chan<NChannels; Chan++) { … … 233 241 234 242 // Determine gain if integration finished 235 if (Count == m->NumEventsRequested) {236 for (unsigned int i=0; i<NChips; i++) {237 for (unsigned int j=0; j<NChannels; j++) {238 for (unsigned int k=0; k<NBins; k++) {239 ACalib.Gain[i][j][k] = (Sum[i][j][k] / m->NumEventsRequested) - ACalib.Baseline[i][j][k];240 }241 } 242 } 243 244 // Set new DAC values and start accumulation 245 DACCmd[1] = htons(0);246 DACCmd[3] = htons(0);247 DACCmd[5] = htons(0);248 Send(DACCmd, sizeof(DACCmd));249 250 // Clear sum vector and set state to accumulate 251 memset(Sum, 0, sizeof(Sum));252 Count = 0;253 State = secondary;254 }243 if (Count < m->NumEventsRequested) break; 244 245 for (unsigned int i=0; i<NChips; i++) { 246 for (unsigned int j=0; j<NChannels; j++) { 247 for (unsigned int k=0; k<NBins; k++) { 248 ACalib.Gain[i][j][k] = (Sum[i][j][k] / m->NumEventsRequested) - ACalib.Baseline[i][j][k]; 249 } 250 } 251 } 252 253 // Set new DAC values and start accumulation 254 DACCmd[1] = htons(0); 255 DACCmd[3] = htons(0); 256 DACCmd[5] = htons(0); 257 Send(DACCmd, sizeof(DACCmd)); 258 259 // Clear sum vector and set state to accumulate 260 memset(Sum, 0, sizeof(Sum)); 261 Count = 0; 262 State = secondary; 255 263 break; 256 264 257 265 // ====== Part D: Secondary calibration ===== 258 266 case secondary: 267 // Check for stopping 268 if (m->Mode != m->acalib) { 269 State = cleanup; 270 break; 271 } 272 273 // Average 259 274 for (unsigned int Chip=0; Chip<NChips; Chip++) { 260 275 for (unsigned int Chan=0; Chan<NChannels; Chan++) { … … 267 282 268 283 // Determine secondary baseline if integration finished 269 if (Count == m->NumEventsRequested) { 270 for (unsigned int i=0; i<NChips; i++) { 271 for (unsigned int j=0; j<NChannels; j++) { 272 for (unsigned int k=0; k<NBins; k++) { 273 ACalib.Secondary[i][j][k] = Sum[i][j][k] / (double) m->NumEventsRequested; 274 } 275 } 276 } 277 278 // Write back original ROI and DAC settings 279 ROICmd.clear(); 280 for (unsigned int i=0; i<NChips*NChannels; i++) { 281 ROICmd.push_back(htons(CMD_Write | (BADDR_ROI + i))); 282 ROICmd.push_back(htons(InitialStatus.ROI[i/NChannels][i%NChannels])); 283 } 284 Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short)); 285 286 DACCmd[1] = htons(InitialStatus.DAC[1]); 287 DACCmd[3] = htons(InitialStatus.DAC[2]); 288 DACCmd[5] = htons(InitialStatus.DAC[3]); 289 Send(DACCmd, sizeof(DACCmd)); 290 291 // Store calibration time and temperature 292 ACalib.DNA = Status.DNA; 293 ACalib.Frequency = Status.Frequency; 294 ACalib.Time = time(NULL); 295 ACalib.Temp = 0; 296 for (unsigned int i=0; i<NTemp; i++) ACalib.Temp += Status.Temp[i] / NTemp; 297 298 // Inform event thread that calibration is finished 299 string Message = string("ACALIBDONE")+Name; 300 if (write(m->Pipe[1], Message.data(), Message.size()) == -1) { 301 m->Message(m->ERROR, "write() to Pipe[1] failed in class FADBoard::AmplitudeCalibration (%s)", strerror(errno)); 302 } 303 304 State = wait; 305 } 284 if (Count < m->NumEventsRequested) break; 285 286 for (unsigned int i=0; i<NChips; i++) { 287 for (unsigned int j=0; j<NChannels; j++) { 288 for (unsigned int k=0; k<NBins; k++) { 289 ACalib.Secondary[i][j][k] = Sum[i][j][k] / (double) m->NumEventsRequested; 290 } 291 } 292 } 293 294 // Store calibration time and temperature 295 ACalib.DNA = Status.DNA; 296 ACalib.Frequency = Status.Frequency; 297 ACalib.Time = time(NULL); 298 ACalib.Temp = 0; 299 for (unsigned int i=0; i<NTemp; i++) ACalib.Temp += Status.Temp[i] / NTemp; 300 301 // Inform event thread that calibration is finished for this board 302 if (write(m->Pipe[1], Message.data(), Message.size()) == -1) { 303 m->Message(m->ERROR, "write() to Pipe[1] failed in class FADBoard::AmplitudeCalibration (%s)", strerror(errno)); 304 } 305 306 State = cleanup; 306 307 break; 307 308 308 // ====== Wait for Mode not being acalib ===== 309 // ====== Part E: Write back original ROI and DAC settings ===== 310 case cleanup: 311 // ROI values 312 ROICmd.clear(); 313 for (unsigned int i=0; i<NChips*NChannels; i++) { 314 ROICmd.push_back(htons(CMD_Write | (BADDR_ROI + i))); 315 ROICmd.push_back(htons(InitialStatus.ROI[i/NChannels][i%NChannels])); 316 } 317 Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short)); 318 319 // DAC values 320 DACCmd[1] = htons(InitialStatus.DAC[1]); 321 DACCmd[3] = htons(InitialStatus.DAC[2]); 322 DACCmd[5] = htons(InitialStatus.DAC[3]); 323 Send(DACCmd, sizeof(DACCmd)); 324 325 State = wait; 326 break; 327 328 // ====== Wait for Mode not being idle ===== 309 329 case wait: 310 if (m->Mode != m->acalib) State = init;330 if (m->Mode == m->idle) State = standbye; 311 331 break; 312 332 } … … 435 455 } 436 456 437 // Extract Firmware status info 438 Status.denable = (bool) ( ntohs(Header->PLLLCK) & (1<<11) ); 439 Status.dwrite = (bool) ( ntohs(Header->PLLLCK) & (1<<10) ); 440 Status.DCM_lock = (bool) ( ntohs(Header->PLLLCK) & (1<<9) ); 441 Status.DCM_ready = (bool) ( ntohs(Header->PLLLCK) & (1<<8) ); 442 Status.spi_clk = (bool) ( ntohs(Header->PLLLCK) & (1<<7) ); 443 457 // Extract Firmware status info 458 Status.denable = (bool) ( ntohs(Header->PLLLCK) & (1<<11) ); 459 Status.dwrite = (bool) ( ntohs(Header->PLLLCK) & (1<<10) ); 460 Status.DCM_lock = (bool) ( ntohs(Header->PLLLCK) & (1<<9) ); 461 Status.DCM_ready = (bool) ( ntohs(Header->PLLLCK) & (1<<8) ); 462 Status.spi_clk = (bool) ( ntohs(Header->PLLLCK) & (1<<7) ); 444 463 445 464 // Extract temperatures (MSB indicates if temperature is positive or negative) -
fact/FADctrl/FADBoard.h
r10224 r10226 43 43 uint32_t BoardTime; 44 44 uint32_t EventCounter; 45 struct timeval Update; 46 45 47 uint32_t TriggerID; 46 48 uint16_t TriggerType; 47 49 uint16_t TriggerCRC; 48 50 uint16_t TriggerCell[NChips]; 51 49 52 float Frequency; 50 53 bool Lock[NChips]; 51 bool denable;52 bool dwrite;53 bool DCM_lock;54 bool DCM_ready;55 bool spi_clk;56 54 int8_t PhaseShift; 55 56 bool denable; 57 bool dwrite; 58 bool DCM_lock; 59 bool DCM_ready; 60 bool spi_clk; 61 57 62 uint16_t ROI[NChips][NChannels]; 58 63 uint16_t DAC[NDAC]; 59 64 float Temp[NTemp]; 60 struct timeval Update;61 65 } Status; 62 66 … … 88 92 pthread_t Thread; 89 93 pthread_cond_t CondVar; 94 95 // Amplitude calibration 96 int Count; 97 98 private: 99 enum StateType {standbye, baseline, gain, secondary, cleanup, wait}; 100 struct BoardStatus InitialStatus; 101 StateType State; 90 102 }; 91 103
Note:
See TracChangeset
for help on using the changeset viewer.