Changeset 10070


Ignore:
Timestamp:
12/16/10 08:08:04 (14 years ago)
Author:
ogrimm
Message:
Updates to bias
Location:
fact/BIASctrl
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • fact/BIASctrl/BIASctrl.cc

    r10052 r10070  
    1717
    1818#define LOCKFILE "/tmp/CTX_HV_LOCK"
     19const char READLINE_HIST_FILE[] = "/tmp/.history.BIASctrl";
    1920
    2021//
     
    5152  char str[MAX_COM_SIZE], *Command;
    5253  int Lock;
     54  std::string LastHist;
    5355
    5456  // Assure only one instance runs
     
    7274 
    7375  // Install signal handler and set signal SIGUSR1 to interrupt blocking system calls
    74   //signal(SIGUSR1, &DummyHandler);
    75   //siginterrupt (SIGUSR1, true);
     76  signal(SIGUSR1, &DummyHandler);
     77  siginterrupt (SIGUSR1, true);
    7678
    7779  // Assure lock file is deleted in case of a program crash or call to exit()
     
    9294  signal(SIGTERM, &CrashHandler);
    9395
     96  // Load history buffer
     97  read_history(READLINE_HIST_FILE);
     98
    9499  // Handle command-line input
    95100  while (!M.ExitRequest) {       
     
    98103        // NULL returned if interrupted by signal
    99104    if (Command == NULL) continue;
    100     if (strlen(Command) > 0) add_history(Command);
     105
     106        // Add command to history
     107    if(strlen(Command) > 0 && LastHist != Command) {
     108          add_history(Command);
     109          LastHist = Command;
     110        }
    101111
    102112    // Process command (via DIM gives automatic thread serialisation)
     
    104114    free(Command);
    105115  }
     116 
     117  // Save history buffer 
     118  int Ret = write_history(READLINE_HIST_FILE);
     119  if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE, strerror(Ret));
    106120}
  • fact/BIASctrl/Crate.cc

    r10059 r10070  
    3232          Present[i][j] = false;
    3333          Current[i][j] = 0;
     34          CurrentOffset[i][j] = 0;
    3435        }
    3536  }
     
    4546  NameService = new DimService ((SERVER_NAME"/NAME/ID"+ID.str()).c_str(), Name);
    4647  BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+ID.str()).c_str(), (char *) "D", Volt, MAX_NUM_BOARDS*NUM_CHANNELS*sizeof(double));
     48  BiasDAC = new DimService ((char *) (SERVER_NAME"/DAC/ID"+ID.str()).c_str(), (char *) "I", DAC, MAX_NUM_BOARDS*NUM_CHANNELS*sizeof(int));
     49  BiasCurrent = new DimService ((char *) (SERVER_NAME"/MICROAMP/ID"+ID.str()).c_str(), (char *) "F", Current, MAX_NUM_BOARDS*NUM_CHANNELS*sizeof(float));
    4750
    4851  ClearVoltageArrays();
     
    97100  delete NameService;
    98101  delete BiasVolt;
     102  delete BiasDAC;
     103  delete BiasCurrent;
    99104  delete[] Name;
    100105}
     
    104109//
    105110// Returns: 0 error, 1 success, -1 time-out exceeded
    106 vector<char> Crate::Communicate(string Buf) {
     111vector<unsigned char> Crate::Communicate(string Buf) {
    107112
    108113  int N;
     
    110115  struct timeval WaitTime = {(long) m->fTimeOut, (long) ((m->fTimeOut-(long) m->fTimeOut)*1e6)};
    111116  char Buffer[10000];
    112   vector<char> Data;
     117  vector<unsigned char> Data;
    113118 
    114119  // === Lock device ===
     
    133138        // Time-out expired?
    134139        if (!FD_ISSET(fDescriptor, &SelectDescriptor)) {
    135           Data.push_back(-1);
    136140          goto ExitCommunicate;
    137141        }
     
    177181int Crate::SystemReset() {
    178182 
    179   vector<char> Data = Communicate(string(3, 0));
     183  vector<unsigned char> Data = Communicate(string(3, 0));
    180184
    181185  if (Data.size() == 3) {
     
    183187        return 1;
    184188  }
    185   return Data[0];
     189  return 0;
    186190}
    187191
     
    201205 
    202206  // Execute command
    203   vector<char> Data = Communicate(Buf);
     207  vector<unsigned char> Data = Communicate(Buf);
    204208   
    205   if (Data.size() != Buf.size()) return Data[0];
     209  if (Data.size() != Buf.size()) return 0;
    206210
    207211  // Evaluate data returned from crate
    208212  int Count = 0;
    209213  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
    210         Current[i][j] = Data[Count+1] + (Data[Count]&15)*256;
     214        Current[i][j] = (Data[Count+1] + (Data[Count] & 0x0f)*256) * 1.22;
    211215        OC[i][j] = Data[Count] & 128;
    212216        Present[i][j] = Data[Count+2] & 0x70 ? false : true;
     
    220224
    221225// ***** Global set *****
    222 int Crate::GlobalSet(unsigned int SetPoint) {
    223 
    224   // Check limit
    225   if (SetPoint > 0x0FFF) {
    226     m->PrintMessage("Error: Voltage DAC value above 0x0FFF\n");
    227     return 0;
    228   }
    229 
     226int Crate::GlobalSet(double Voltage) {
     227
     228  unsigned int SetPoint = (unsigned int) (Voltage/90.0*0x0fff);
     229 
    230230  // Execute command
    231231  string Buf;
    232232  Buf = (((Buf + char(1<<6)) + char(SetPoint>>8)) + char(SetPoint));
    233   vector<char> Data = Communicate(Buf);
     233  vector<unsigned char> Data = Communicate(Buf);
    234234
    235235  if (Data.size() == 3) {
    236236        for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
    237237          DAC[i][j] = SetPoint;
    238           Volt[i][j] = (double) SetPoint / 0xfff * 90;
     238          Volt[i][j] = Voltage;
     239          RefVolt[i][j] = Voltage;
    239240        }
    240241        return 1;
    241242  }
    242   return Data[0];
     243  return 0;
    243244}
    244245
    245246
    246247// ***** Set channel voltages *****
    247 int Crate::SetChannels(map<unsigned int, unsigned int> V) {
     248int Crate::SetChannels(map<unsigned int, double> V) {
    248249 
    249250  string Buf;
     
    252253
    253254  // Build and execute commands
    254   for (map<unsigned int, unsigned int>::const_iterator it = V.begin(); it != V.end(); ++it) {
     255  for (map<unsigned int, double>::const_iterator it = V.begin(); it != V.end(); ++it) {
     256    // If DAC value unchanged, do not send command
     257        if (DAC[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] == it->second/90.0*0x0fff) continue;
     258
     259        // Add command to buffer
    255260        Buf += char(3<<5) |  char(it->first/NUM_CHANNELS<<1 & 0x0f) | char((it->first%NUM_CHANNELS&16)>>4 & 1);
    256         Buf += char(it->first%NUM_CHANNELS<<4) | ((it->second>>8) & 0x0f);
    257         Buf += char(it->second);
    258   }
    259   vector<char> Data = Communicate(Buf);
     261        Buf += char(it->first%NUM_CHANNELS<<4) | ((((unsigned int) (it->second/90.0*0x0fff))>>8) & 0x0f);
     262        Buf += char(it->second/90.0*0x0fff);
     263  }
     264  vector<unsigned char> Data = Communicate(Buf);
    260265
    261266  // Store new voltage values of successful
    262267  if (Data.size() == Buf.size()) {
    263         for (map<unsigned int, unsigned int>::const_iterator it = V.begin(); it != V.end(); ++it) {
    264           DAC[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] = it->second;
    265           Volt[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] = 90.0*it->second/0x0fff;
     268        for (map<unsigned int, double>::const_iterator it = V.begin(); it != V.end(); ++it) {
     269          DAC[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] = (unsigned int) (it->second/90.0*0x0fff);
     270          Volt[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] = it->second;
     271          RefVolt[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] = it->second;
    266272        }
    267273        return 1;
    268274  }
    269   return Data[0]
     275  return 0
    270276}
    271277
     
    275281 
    276282  int Trial = 0;
    277   vector<char> Data;
     283  vector<unsigned char> Data;
    278284
    279285  while(++Trial <= 3) {
    280286    Data = Communicate(string(1, 0));
    281287    if (Data.size() == 3) return true;
    282     if (Data[0] == 0) break;
    283288  }
    284289  return false;
     
    306311void Crate::ClearVoltageArrays() {
    307312
    308   for (int i=0; i<MAX_NUM_BOARDS; i++) {
    309     for (int j=0; j<NUM_CHANNELS; j++){
    310       DAC[i][j] = 0;
    311       Volt[i][j] = 0.0;     
    312     }
    313   }
    314   // Update DIM services
     313  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     314        DAC[i][j] = 0;
     315        Volt[i][j] = 0; 
     316        RefVolt[i][j] = 0; 
     317  }
     318
     319  UpdateDIM();
     320}
     321
     322
     323// ***** Return calibrated voltage of given channel *****
     324double Crate::GetVoltage(unsigned int Channel) {
     325
     326  if (Channel >= MAX_NUM_BOARDS*NUM_CHANNELS) return 0;
     327  else return Volt[Channel/NUM_CHANNELS][Channel%NUM_CHANNELS];
     328}
     329
     330
     331// ***** Return DAC value of given channel *****
     332unsigned int Crate::GetDAC(unsigned int Channel) {
     333
     334  if (Channel >= MAX_NUM_BOARDS*NUM_CHANNELS) return 0;
     335  else return DAC[Channel/NUM_CHANNELS][Channel%NUM_CHANNELS];
     336}
     337
     338
     339// ***** Return current of given channel *****
     340float Crate::GetCurrent(unsigned int Channel) {
     341
     342  if (Channel >= MAX_NUM_BOARDS*NUM_CHANNELS) return 0;
     343  else return Current[Channel/NUM_CHANNELS][Channel%NUM_CHANNELS]-CurrentOffset[Channel/NUM_CHANNELS][Channel%NUM_CHANNELS];
     344}
     345
     346
     347// ***** Update DIM services *****
     348void Crate::UpdateDIM() {
     349
    315350  BiasVolt->updateService();
    316 }
     351  BiasDAC->updateService();
     352}
     353
     354
     355// ***** Set reference current for dynamic mode *****
     356void Crate::SetRefCurrent() {
     357
     358  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     359        RefCurrent[i][j] = Current[i][j]; 
     360  }
     361}
     362
     363
     364// ***** Correct voltages according to current *****
     365void Crate::AdaptVoltages() {
     366
     367  static int LastUpdate = 0;
     368   
     369  map<unsigned int, double> Voltages;
     370
     371  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     372    if (RefVolt[i][j] == 0) continue;
     373        Voltages[i*NUM_CHANNELS+j] = RefVolt[i][j] + (RefCurrent[i][j]-Current[i][j])*RESISTOR/1e6; 
     374  } 
     375  SetChannels(Voltages);
     376 
     377  if (time(NULL)-LastUpdate > 5) {
     378    LastUpdate = time(NULL);
     379        UpdateDIM();
     380  }
     381}
  • fact/BIASctrl/Crate.h

    r10059 r10070  
    1717#define NUM_CHANNELS 32         // Channels per bias board
    1818#define BAUDRATE B115200
     19const float RESISTOR = 1000;            // Resistance in Ohm for voltage correction
    1920
    2021class User;
     
    2728        FILE *File;
    2829        DimService *NameService;
     30        DimService *BiasVolt;
     31        DimService *BiasDAC;
     32        DimService *BiasCurrent;
    2933
    30         std::vector<char> Communicate(std::string);
     34        int DAC[MAX_NUM_BOARDS][NUM_CHANNELS];          // Voltage in DAC units
     35        double Volt[MAX_NUM_BOARDS][NUM_CHANNELS];      // Voltage in Volt
     36        float Current[MAX_NUM_BOARDS][NUM_CHANNELS];
     37        float CurrentOffset[MAX_NUM_BOARDS][NUM_CHANNELS]; // Offset for current measurement
     38
     39        std::vector<unsigned char> Communicate(std::string);
    3140        void ClearVoltageArrays();
    3241   
     
    3645
    3746    char *Name;
    38         DimService *BiasVolt;
    3947
    40         int Current[MAX_NUM_BOARDS][NUM_CHANNELS];
    4148        bool OC[MAX_NUM_BOARDS][NUM_CHANNELS];
    4249        bool Present[MAX_NUM_BOARDS][NUM_CHANNELS];
     
    4653        int ErrorCount;
    4754
    48         unsigned int DAC[MAX_NUM_BOARDS][NUM_CHANNELS];      // Voltage in DAC units
    49         double Volt[MAX_NUM_BOARDS][NUM_CHANNELS];  // Voltage in Volt
    50         int CurrentOffset[MAX_NUM_BOARDS][NUM_CHANNELS]; // Offset for current measurement
     55        float RefCurrent[MAX_NUM_BOARDS][NUM_CHANNELS];
     56        double RefVolt[MAX_NUM_BOARDS][NUM_CHANNELS];
    5157
    5258        bool InitOK;
    5359
    54         int SetChannels(std::map<unsigned int, unsigned int>);
     60        int SetChannels(std::map<unsigned int, double>);
    5561        int ReadAll();
    5662        int SystemReset();
    57         int GlobalSet(unsigned int);
     63        int GlobalSet(double);
    5864        bool Synch();
    5965        bool CurrentCalib(double);
     66        double GetVoltage(unsigned int);
     67        unsigned int GetDAC(unsigned int);
     68        float GetCurrent(unsigned int);
     69        void UpdateDIM();
     70        void SetRefCurrent();
     71        void AdaptVoltages();
    6072};
    6173
  • fact/BIASctrl/History.txt

    r10059 r10070  
    4417/11/2010      Added possibility for bulk transfers (ReadAll(), SetChannels())
    5524/11/2010      Ramping for many channels possible with bulk transfers
     67/12/2010       Added dynamic mode.
  • fact/BIASctrl/User.cc

    r10059 r10070  
    2020        {"status", &User::cmd_status, 0, "[dac|current]", "Show status information (DAC values if requested)"},
    2121        {"ccal", &User::cmd_ccal, 1, "<volt>", "Calibrate current measurement at given voltage"},
     22        {"mode", &User::cmd_mode, 1, "<static|dynamic>", "Set voltage stabilization mode"},
    2223        {"load", &User::cmd_load, 1, "<file>", "Load and set bias settings from file"},
    2324        {"save", &User::cmd_save, 1, "<file>", "Save current bias settings to file"},
     
    4344  fTimeOut = atof(GetConfig("TimeOut").c_str());
    4445  fStatusRefreshRate = atof(GetConfig("StatusRefreshRate").c_str());
    45   fMaxDiff = atoi(GetConfig("HVMaxDiff").c_str());
     46  fMaxDiff = atof(GetConfig("HVMaxDiffNew").c_str());
    4647
    4748  if (fStatusRefreshRate < MIN_RATE || fStatusRefreshRate > MAX_RATE)  fStatusRefreshRate = 1;
     
    158159void User::cmd_hv() {
    159160
    160   unsigned int DACValue, Errors=0, B, C;
     161  unsigned int Errors=0;
    161162  double Double;
    162163  struct Range Crt, Chan;
    163   vector< map<unsigned int, unsigned int> > Voltages (Crates.size());
     164  vector< map<unsigned int, double> > Voltages (Crates.size());
    164165
    165166  // Loop over all parameters
     
    178179          Chan.Max = MAX_NUM_BOARDS*NUM_CHANNELS-1;
    179180         
     181          if (Parameter[n] == "-") continue;
     182
    180183          if (T.size() == 2) {
    181184                if(!ConvertToRange(T[0], Crt) || !ConvertToRange(T[1], Chan)) {
     
    201204        // Loop over given crates and channels
    202205        for (int i=Crt.Min; i<=Crt.Max; i++) for (int j=Chan.Min; j<=Chan.Max; j++) {
    203           // Board and channel number
    204           B = j / NUM_CHANNELS;
    205           C = j % NUM_CHANNELS;
    206 
    207206          // Voltage change (number starts with + oder -) ignored if current DAC value is zero
    208           if (isdigit(Parameter[n+1][0])==0 && Crates[i]->DAC[B][C] == 0) continue;
     207          if (isdigit(Parameter[n+1][0])==0 && Crates[i]->GetDAC(j) == 0) continue;
    209208
    210209          // Relative or absolute change?
    211           if (isdigit(Parameter[n+1][0]) == 0) DACValue = Crates[i]->DAC[B][C] + (unsigned int) (Double/90*0x0fff);
    212           else DACValue = (unsigned int) (Double/90*0x0fff);
    213 
    214           Voltages[i][j] = DACValue;
     210          if (isdigit(Parameter[n+1][0]) == 0) Voltages[i][j] = Crates[i]->GetVoltage(j) + Double;
     211          else Voltages[i][j] = Double;
    215212        } // Channels
    216213  } // Loop over command argument
     
    219216  for (unsigned int i=0; i<Voltages.size(); i++) {
    220217        Errors += RampVoltages(i, Voltages[i]);
    221     Crates[i]->BiasVolt->updateService();
     218    Crates[i]->UpdateDIM();
    222219  }
    223220
     
    231228
    232229  char Buffer[MAX_COM_SIZE];
    233   int Errors = 0, Board, Channel;
    234   unsigned int DACValue, NBoards = 0;
     230  int Errors = 0, Channel;
     231  unsigned int NBoards = 0;
     232  double Value;
    235233  FILE *File;
    236   map<unsigned int, unsigned int> Voltages;
     234  map<unsigned int, double> Voltages;
    237235
    238236  // Open file
     
    249247
    250248          Voltages.clear();
    251           Board = 0;  Channel = 0;
    252           while (fscanf(File, "%u", &DACValue)==1 && Board<MAX_NUM_BOARDS) {
    253                 Voltages[Board*NUM_CHANNELS+Channel] = DACValue;
    254 
    255             // Ramp channel to new voltage
    256         /*if (!RampVoltage(DACValue, Crate, Board, Channel)) {
    257               Errors++;
    258               PrintMessage("Error: Could not ramp board %d, channel %d\n", Board, Channel);
    259         }
    260                 else {
    261               PrintMessage("Ramped board %d, channel %d to %u (%.2f V)                         \r",
    262                  Board, Channel, DACValue, (double) DACValue/0x0fff*90);
    263                 }*/
    264 
    265                 if(++Channel == NUM_CHANNELS) {
    266               Board++;
    267               Channel = 0;
    268                 }
     249          Channel = 0;
     250          while (fscanf(File, "%lf", &Value)==1 && Channel<MAX_NUM_BOARDS*NUM_CHANNELS) {
     251                Voltages[Channel++] = Value;
    269252          }
    270253
     
    273256
    274257      // Update DIM service
    275           Crates[Crate]->BiasVolt->updateService();
     258          Crates[Crate]->UpdateDIM();
    276259
    277260          if (ferror(File) != 0) {
     
    342325  if (!ConvertToDouble(Parameter[1], &Voltage)) return;
    343326
    344   if (Crates[0]->GlobalSet((int) (Voltage/90*0xfff)) != 1) {
     327  if (Crates[0]->GlobalSet(Voltage) != 1) {
    345328    PrintMessage("Error: Could not global set board %d\n", 0);
    346329  }   
     
    386369    fprintf(File, "%s\n\n", Crates[i]->Name);
    387370
    388     for (int j=0; j<MAX_NUM_BOARDS; j++) {
    389           for (int k=0; k<NUM_CHANNELS; k++) fprintf(File,"%5d ",Crates[i]->DAC[j][k]);
    390     }
     371    for (int j=0; j<MAX_NUM_BOARDS*NUM_CHANNELS; j++) fprintf(File,"%.3f ",Crates[i]->GetVoltage(j));
    391372    fprintf(File, "\n");
    392373  }
     
    396377  }
    397378}
     379
     380//
     381// Set operation mode
     382//
     383void User::cmd_mode() {
     384
     385  if (Match(Parameter[1], "static")) Mode = mode_static;
     386  else {
     387    Mode = mode_dynamic;
     388        for (unsigned int i=0; i<Crates.size(); i++) {
     389          Crates[i]->SetRefCurrent();
     390        }
     391  }
     392}
    398393
    399394//
     
    419414          if (j%12 == 0) PrintMessage("\n%3.1d:  ", j);
    420415          if (!Crates[i]->Present[j/NUM_CHANNELS][j%NUM_CHANNELS]) PrintMessage("  -   ");
    421       else if (Parameter.size() == 1) PrintMessage("%#5.2f ",Crates[i]->Volt[j/NUM_CHANNELS][j%NUM_CHANNELS]);
    422           else if (Match(Parameter[1], "dac")) PrintMessage("%5d ", Crates[i]->DAC[j/NUM_CHANNELS][j%NUM_CHANNELS]);
    423           else PrintMessage("%#5.2f %s ", (Crates[i]->Current[j/NUM_CHANNELS][j%NUM_CHANNELS]-Crates[i]->CurrentOffset[j/NUM_CHANNELS][j%NUM_CHANNELS])*1.2, Crates[i]->OC[j/NUM_CHANNELS][j%NUM_CHANNELS] ? "OC":"");
     416      else if (Parameter.size() == 1) PrintMessage("%#5.2f ",Crates[i]->GetVoltage(j));
     417          else if (Match(Parameter[1], "dac")) PrintMessage("%5d ", Crates[i]->GetDAC(j));
     418          else PrintMessage("%#5.2f %s ", Crates[i]->GetCurrent(j), Crates[i]->OC[j/NUM_CHANNELS][j%NUM_CHANNELS] ? "OC":"");
    424419    }
    425420        PrintMessage("\n");
     
    449444
    450445  ExitRequest = true;
    451   //pthread_kill(Thread, SIGUSR1);
    452   //pthread_cancel(Thread);
     446  pthread_kill(Thread, SIGUSR1);  // Make tjread return from usleep()
    453447}
    454448 
     
    484478// Ramp to new voltage with maximum step size given in fMaxDiff
    485479// No ramping when decreasing voltage
    486 unsigned int User::RampVoltages(int Crate, map<unsigned int, unsigned int> Voltages) {
    487 
    488   map<unsigned int, unsigned int> Target;
     480unsigned int User::RampVoltages(int Crate, map<unsigned int, double> Voltages) {
     481
     482  map<unsigned int, double> Target;
    489483  unsigned int Errors = 0;
    490484
    491485  // Ramp until all channels at desired value
    492486  while (!Voltages.empty()) {
    493     // Remove channels already at target
    494         for (map<unsigned int, unsigned int>::iterator it = Voltages.begin(); it != Voltages.end(); ++it) {
    495           if (Crates[Crate]->DAC[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] == it->second) Voltages.erase(it);
     487    // Remove channels already at target (check for DAC, not for floating-point voltage)
     488        for (map<unsigned int, double>::iterator it = Voltages.begin(); it != Voltages.end(); ++it) {
     489          //if (Crates[Crate]->GetDAC(it->first) == (unsigned int ) (it->second/90.0*0x0fff)) Voltages.erase(it);
     490          if (fabs(Crates[Crate]->GetVoltage(it->first)-it->second) < 0.001) Voltages.erase(it);
    496491        }
    497492       
    498493        // Limit voltage changes to fMaxDiff
    499494        Target = Voltages;
    500         for (map<unsigned int, unsigned int>::iterator it = Target.begin(); it != Target.end(); ++it) {
    501           if (Crates[Crate]->DAC[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] + fMaxDiff/2 < it->second) {
    502                 it->second = Crates[Crate]->DAC[it->first/NUM_CHANNELS][it->first%NUM_CHANNELS] + fMaxDiff/2;
     495        for (map<unsigned int, double>::iterator it = Target.begin(); it != Target.end(); ++it) {
     496          if (Crates[Crate]->GetVoltage(it->first) + fMaxDiff < it->second) {
     497                it->second = Crates[Crate]->GetVoltage(it->first) + fMaxDiff;
    503498          }
    504499        }       
     
    545540      }
    546541
    547           map<unsigned int, unsigned int> Voltages;
     542          map<unsigned int, double> Voltages;
    548543         
    549544      for (int j=0; j<MAX_NUM_BOARDS*NUM_CHANNELS; j++) {
     
    551546                  Message(WARN, "Overcurrent on crate %d, board %d, channel %d, setting voltage to zero", i, j/NUM_CHANNELS, j%NUM_CHANNELS);
    552547                  Voltages[j] = 0;
    553                   //Crates[i]->ChannelSet(j/NUM_CHANNELS, j%NUM_CHANNELS, 0);
    554548        }
    555549      }
     
    558552                Crates[i]->SystemReset();
    559553          }
     554         
     555          if (Mode == mode_dynamic) Crates[i]->AdaptVoltages();
    560556        } // for
    561557
  • fact/BIASctrl/User.h

    r10059 r10070  
    2424class User: public EvidenceServer {
    2525
     26        enum RunMode {mode_static, mode_dynamic};
     27
    2628        PixelMap *pm;
    2729        DimCommand *DIMCommand;
     
    3032        pthread_t Thread;
    3133        std::vector<std::string> Parameter;
     34        RunMode Mode;
    3235
    3336        std::vector<class Crate *> Crates;
     
    4851        double fTimeOut;
    4952        float fStatusRefreshRate;
    50         unsigned int fMaxDiff;
     53        double fMaxDiff;
    5154
    5255        User();
     
    5457
    5558        void PrintMessage(const char *, ...);
    56         unsigned int RampVoltages(int, std::map<unsigned int, unsigned int>);
     59        unsigned int RampVoltages(int, std::map<unsigned int, double>);
    5760        void Monitor();
    5861        static void LaunchMonitor(User *);
     
    6467        void cmd_timeout();     void cmd_reset();
    6568        void cmd_help();        void cmd_ccal();
     69        void cmd_mode();
    6670};
    6771
Note: See TracChangeset for help on using the changeset viewer.