Changeset 17030


Ignore:
Timestamp:
08/20/13 08:05:05 (11 years ago)
Author:
tbretz
Message:
Fixed a bug in the R8 service; service calibrated currents also during ramping; fixed Iapd for the faulty patches; avoid to start feedback when bias is in ramping; still some debugging output.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/feedback.cc

    r17027 r17030  
    194194    int HandleCalibration(const EventImp &evt)
    195195    {
     196        if (fDimBias.state()!=BIAS::State::kVoltageOn)
     197            return GetCurrentState();
     198
    196199        const uint16_t dac = 256+512*fCalibStep; // Command value
    197200
     
    312315        }
    313316
    314         vector<float> v(BIAS::kNumChannels*2);
     317        vector<float> v;
     318        v.reserve(BIAS::kNumChannels*2);
    315319        v.insert(v.end(), fCalibDeltaI.begin(), fCalibDeltaI.end());
    316320        v.insert(v.end(), fCalibR8.begin(),     fCalibR8.end());
     
    333337
    334338        if (GetCurrentState()<Feedback::State::kCalibrating)
    335             return GetCurrentState();
    336 
    337         // FIXME? Allow for calibrated currents also during ramping?
    338         if ((GetCurrentState()!=Feedback::State::kWaitingForData || fDimBias.state()!=BIAS::State::kVoltageOff) &&
    339             fDimBias.state()!=BIAS::State::kVoltageOn)
    340339            return GetCurrentState();
    341340
     
    362361        // ---------------------- Calibrated, WaitingForData, InProgress -----------------------
    363362
    364         const vector<float> &Imes = AverageCurrents(evt.Ptr<int16_t>(), 3).first;
     363        const int Navg = fDimBias.state()!=BIAS::State::kVoltageOn ? 1 : 3;
     364
     365        const vector<float> &Imes = AverageCurrents(evt.Ptr<int16_t>(), Navg).first;
    365366        if (Imes.size()==0)
    366367            return GetCurrentState();
     
    408409        vector<float> vec(416);
    409410
    410         cout << setprecision(4) << endl;
    411 
    412411        if (fEnableOldAlgorithm)
    413412        {
     
    458457
    459458                if (i==2)
    460                     cout << dU << endl;;
     459                    cout << setprecision(4)<< dU << endl;;
    461460
    462461                vec[i] = Ubd + overvoltage + dU;
     
    523522
    524523                // Serial resistor of the individual G-APDs
    525                 double R5 = 3900/N;
     524                double R5 = 3900./N;
    526525
    527526                // This is assuming that the broken pixels have a 390 Ohm instead of 3900 Ohm serial resistor
     
    581580                // resistor is large enough that the increase of the overvoltage does not dramatically
    582581                // increase the current flow as compared to the total current flow.
    583                 if (i==66)
    584                     Iapd /= 1.3;
    585                 if (i==191 || i==193)
    586                     Iapd /= 1.4;
     582                if (i==66 || i==191 || i==193)
     583                    Iapd = Iout/(N+9); // Iapd = R5*Iout/3900;
    587584
    588585                // The differential resistance of the G-APD, i.e. the dependence of the
     
    590587                //const double Rapd = Uov/Iapd;
    591588                // This allows us to estimate the current Iov at the overvoltage we want to apply
    592                 //const double Iov = pow(overvoltage, 1)/Rapd;
     589                //const double Iov = overvoltage/Rapd;
    593590
    594591                // Estimate set point for over-voltage (voltage drop at the target point)
    595592                //const double Uset = Ubd + overvoltage + R*Iov*N;
    596                 double Uset = Uov<0.3 ? Ubd + overvoltage + Udrp : Ubd + overvoltage + Udrp*pow(overvoltage/Uov, 1.66);
     593                const double Uset = Uov<0.3 ? Ubd + overvoltage + Udrp : Ubd + overvoltage + Udrp*pow(overvoltage/Uov, 1.66);
    597594
    598595                // Voltage set point
    599596                vec[i] = Uset;
     597
     598                if (fDimBias.state()==BIAS::State::kVoltageOn && GetCurrentState()==Feedback::State::kInProgress &&
     599                    fabs(Uov-overvoltage)>0.033)
     600                    cout << setprecision(4) << setw(3) << i << ": Uov=" << Uov << " Udrp=" << Udrp << " Iapd=" << Iapd*1e6 << endl;
     601
    600602
    601603                // Calculate statistics only for channels with a valid calibration
     
    628630        // ------------------------------- Update voltages ------------------------------------
    629631
    630         if (GetCurrentState()!=Feedback::State::kCalibrated)
    631         {
    632             DimClient::sendCommandNB("BIAS_CONTROL/SET_ALL_CHANNELS_VOLTAGE",
    633                                      vec.data(), BIAS::kNumChannels*sizeof(float));
    634 
    635             ostringstream msg;
    636             msg << setprecision(4) << "Sending new absolute offset: dU(" << fTemp << "degC)=" << fTempOffset << "V, Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0);
    637             Info(msg);
     632        if (GetCurrentState()!=Feedback::State::kCalibrated) // WaitingForData, InProgress
     633        {
     634            if (fDimBias.state()!=BIAS::State::kRamping)
     635            {
     636                DimClient::sendCommandNB("BIAS_CONTROL/SET_ALL_CHANNELS_VOLTAGE",
     637                                         vec.data(), BIAS::kNumChannels*sizeof(float));
     638
     639                ostringstream msg;
     640                msg << setprecision(4) << "Sending new absolute offset: dU(" << fTemp << "degC)=" << fTempOffset << "V, Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0);
     641                Info(msg);
     642            }
    638643        }
    639644        else
    640645        {
    641             ostringstream msg;
    642             msg << setprecision(4) << "Current status: dU(" << fTemp << "degC)=" << fTempOffset << "V, Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0);
    643             Info(msg);
    644 
    645         }
     646            if (fDimBias.state()==BIAS::State::kVoltageOn)
     647            {
     648                ostringstream msg;
     649                msg << setprecision(4) << "Current status: dU(" << fTemp << "degC)=" << fTempOffset << "V, Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0);
     650                Info(msg);
     651            }
     652
     653        }
     654
     655        if (GetCurrentState()==Feedback::State::kInProgress &&
     656            fDimBias.state()==BIAS::State::kRamping)
     657            return GetCurrentState();
    646658
    647659        // --------------------------------- Console out --------------------------------------
    648660
    649         if (num[0]>0 && num[1]>0 && fIsVerbose)
     661        if (num[0]>0 && num[1]>0 && fIsVerbose && !fDimBias.state()==BIAS::State::kRamping)
    650662        {
    651663            sort(med[0].begin(), med[0].begin()+num[0]);
     
    816828        if (!CheckEventSize(evt.GetSize(), "Start", 4))
    817829            return kSM_FatalError;
     830
     831        if (fDimBias.state()==BIAS::State::kRamping)
     832        {
     833            Warn("Feedback can not be started when biasctrl is in state Ramping.");
     834            return GetCurrentState();
     835        }
    818836
    819837        fUserOffset = evt.GetFloat();
Note: See TracChangeset for help on using the changeset viewer.