Ignore:
Timestamp:
08/19/13 16:33:21 (11 years ago)
Author:
tbretz
Message:
Changed the calibration from juts an offset to an offset and a slope. Removed all the relative ramping stuff to get the biasctrl simplified. Allow to load a calibration file for testing purpose in expert mode.
File:
1 edited

Legend:

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

    r16965 r17024  
    6969    vector<int16_t>  fCurrent;     // Current in ADC units (12bit = 5mA)
    7070
    71     virtual void UpdateAV()
     71    virtual void UpdateVA()
    7272    {
    7373    }
     
    8484
    8585    vector<float> fBreakdownVoltage;      // Breakdown voltage of GAPDs
    86     vector<float> fOvervoltage;           // Requested overvoltage of GAPDs
    87     vector<float> fChannelOffset;         // User defined channel offset
     86    //vector<float> fChannelOffset;         // User defined channel offset
    8887
    8988    vector<float> fCalibrationOffset;     // Bias crate channel offset
     
    375374        // Check if new values have been received
    376375        if (cmd==kCmdRead || cmd==kCmdChannelSet || cmd==kExpertChannelSet)
    377             UpdateAV();
     376            UpdateVA();
    378377
    379378        // ----- Take action depending on what is going on -----
     
    658657        {
    659658            const int id = c+kNumChannelsPerBoard*b;
    660             Out() << " " << setw(4) << int32_t(dac[id])<<"/"<<fDacActual[id] << ":" << setw(5) << fDacTarget[id]*90./4096;
     659            Out() << " " << setw(4) << int32_t(dac[id])<<"/"<<fDacActual[id] << ":" << setw(5) << ConvertDacToVolt(id, fDacTarget[id]);
    661660        }
    662661        Out() << endl;
     
    841840        fCurrent(kNumChannels),
    842841        fBreakdownVoltage(kNumChannels, 0),
    843         fOvervoltage(kNumChannels),
    844         fChannelOffset(kNumChannels),
     842        //fChannelOffset(kNumChannels),
    845843        fCalibrationOffset(kNumChannels),
    846         fCalibrationSlope(kNumChannels, 90./4096),
     844        fCalibrationSlope(kNumChannels, 90000),
    847845        fVoltageMaxAbs(75),
    848846        fVoltageMaxRel(2),
     
    945943    uint16_t ConvertVoltToDac(uint16_t ch, double volt)
    946944    {
    947         volt -= fCalibrationOffset[ch];
    948         volt /= fCalibrationSlope[ch];
    949         if (volt<0)
    950             volt = 0;
    951 
    952         return nearbyint(volt);
     945        if (fCalibrationSlope[ch]<=0)
     946            return 0;
     947
     948        const double current = (volt-fCalibrationOffset[ch])/fCalibrationSlope[ch];
     949        return current<0 ? 0 : nearbyint(current*4096000); // Current [A] to dac [ /= 1mA/4096]
    953950    }
    954951
    955952    double ConvertDacToVolt(uint16_t ch, uint16_t dac)
    956953    {
    957         return dac*fCalibrationSlope[ch] + fCalibrationOffset[ch];
     954        if (fCalibrationSlope[ch]<=0)
     955            return 0;
     956
     957        const double current = dac/4096000.;  // Convert dac to current [A] [ *= 1mA/4096]
     958        return current*fCalibrationSlope[ch] + fCalibrationOffset[ch];
    958959    }
    959960
     
    993994    // --------------------------------------------------------------------
    994995
     996    /*
    995997    bool RampSingleChannelOffset(uint16_t ch, float offset, bool relative)
    996998    {
     
    9981000            return false;
    9991001
    1000         if (relative)
    1001             offset += fDacActual[ch]*90./4096 - fBreakdownVoltage[ch] - fOvervoltage[ch];
    1002 
    1003         const float volt = fBreakdownVoltage[ch]>0 ? fBreakdownVoltage[ch] + fOvervoltage[ch] + offset : 0;
     1002//        if (relative)
     1003//            offset += fDacActual[ch]*90./4096 - fBreakdownVoltage[ch];
     1004
     1005        const float volt = fBreakdownVoltage[ch]>0 ? fBreakdownVoltage[ch] + offset : 0;
    10041006
    10051007        if (!RampSingleChannelVoltage(ch, volt))
     
    10151017        vector<float> volt(kNumChannels);
    10161018
    1017         if (relative)
    1018             for (size_t ch=0; ch<kNumChannels; ch++)
    1019                 offset[ch] += fDacActual[ch]*90./4096 - fBreakdownVoltage[ch] - fOvervoltage[ch];
     1019//        if (relative)
     1020//            for (size_t ch=0; ch<kNumChannels; ch++)
     1021//                offset[ch] += fDacActual[ch]*90./4096 - fBreakdownVoltage[ch];
    10201022
    10211023        for (size_t ch=0; ch<kNumChannels; ch++)
    1022             volt[ch] = fBreakdownVoltage[ch]>0 ? fBreakdownVoltage[ch] + fOvervoltage[ch] + offset[ch] : 0;
     1024            volt[ch] = fBreakdownVoltage[ch]>0 ? fBreakdownVoltage[ch] + offset[ch] : 0;
    10231025
    10241026        if (!RampAllChannelsVoltage(volt))
     
    10341036        return RampAllChannelsOffset(vector<float>(kNumChannels, offset), relative);
    10351037    }
     1038    */
    10361039
    10371040    /*
     
    11411144        fCalibrationOffset = offset;
    11421145        fCalibrationSlope  = slope;
    1143         fOvervoltage.assign(kNumChannels, 0);
    11441146
    11451147        UpdateVgapd();
     
    13471349            Out() << " ";
    13481350            Out() << (fDacActual[id]==fDacTarget[id]?kGreen:kRed);
    1349             Out() << setw(5) << fDacActual[id]*90/4096. << '/';
    1350             Out() << setw(5) << fDacTarget[id]*90/4096.;
     1351            //Out() << setw(5) << fDacActual[id]*90/4096. << '/';
     1352            //Out() << setw(5) << fDacTarget[id]*90/4096.;
     1353
     1354            Out() << setw(5) << ConvertDacToVolt(id, fDacActual[id]) << '/';
     1355            Out() << setw(5) << ConvertDacToVolt(id, fDacTarget[id]);
    13511356        }
    13521357        Out() << endl;
     
    13821387        {
    13831388            const int id = c+kNumChannelsPerBoard*b;
    1384             Out() << " " << setw(5) << fBreakdownVoltage[id]+fOvervoltage[id];
     1389            Out() << " " << setw(5) << fBreakdownVoltage[id];
    13851390        }
    13861391        Out() << endl;
     
    15061511    DimDescribedService fDimGapd;
    15071512
    1508     void UpdateAV()
     1513    void UpdateVA()
    15091514    {
    15101515        const Time now;
     1516
     1517        UpdateV(now);
     1518
    15111519        fDimCurrent.setTime(now);
    15121520        fDimCurrent.Update(fCurrent);
    1513 
    1514         UpdateV(now);
    15151521    }
    15161522
     
    15391545        volt.reserve(3*kNumChannels);
    15401546        volt.insert(volt.end(), fBreakdownVoltage.begin(),   fBreakdownVoltage.end());
    1541         volt.insert(volt.end(), fOvervoltage.begin(),        fOvervoltage.end());
    15421547        volt.insert(volt.end(), fCalibrationOffset.begin(),  fCalibrationOffset.end());
    15431548        volt.insert(volt.end(), fCalibrationSlope.begin(),   fCalibrationSlope.end());
     
    15571562        fDimGapd("BIAS_CONTROL/NOMINAL", "F:416;F:416;F:416;F:416",
    15581563                 "|Ubr[V]:Nominal breakdown voltage at 25deg C"
    1559                  "|Uov[V]:Nominal overvoltage"
    15601564                 "|Uoff[V]:Bias crate channel calibration offsets"
    1561                  "|Uslope[V/dac]:Bias crate channel calibration slope")
     1565                 "|Rcal[Ohm]:Bias crate channel calibration slope")
    15621566    {
    15631567    }
     
    16601664    // --------------------------------------------------------------------
    16611665
    1662     // SET_GLOBAL_OFFSET
    1663     int SetGlobalOffset(const EventImp &evt)
    1664     {
    1665         if (!CheckEventSize(evt.GetSize(), "SetGlobalOffset", 4))
    1666             return false;
    1667 
    1668         fBias.RampAllOffsets(evt.GetFloat(), false);
    1669 
    1670         return T::GetCurrentState();
    1671     }
    1672 
    1673     // SET_SINGLE_CHANNEL_OFFSET
    1674     int SetChannelOffset(const EventImp &evt)
    1675     {
    1676         if (!CheckEventSize(evt.GetSize(), "SetSingleChannelOffset", 6))
    1677             return false;
    1678 
    1679         fBias.RampSingleChannelOffset(evt.Get<uint16_t>(), evt.Get<float>(2), false);
    1680 
    1681         return T::GetCurrentState();
    1682     }
    1683 
    1684     // SET_ALL_CHANNELS_OFFSET
    1685     int SetAllChannelsOffset(const EventImp &evt)
    1686     {
    1687         if (!CheckEventSize(evt.GetSize(), "SetAllChannelsOffset", 4*kNumChannels))
    1688             return false;
    1689 
    1690         const float *ptr = evt.Ptr<float>();
    1691         fBias.RampAllChannelsOffset(vector<float>(ptr, ptr+kNumChannels), false);
    1692 
    1693         return T::GetCurrentState();
    1694     }
    1695 
    1696     // --------------------------------------------------------------------
    1697 
    1698     // INCREASE_GLOBAL_VOLTAGE
     1666/*    // INCREASE_GLOBAL_VOLTAGE
    16991667    int IncGlobalVolt(const EventImp &evt)
    17001668    {
     
    17291697        return T::GetCurrentState();
    17301698    }
    1731 
     1699*/
    17321700    // --------------------------------------------------------------------
    17331701
    1734     // SET_CHANNEL_OFFSET_TO_ZERO
    1735     int SetChannelOffsetToZero(const EventImp &evt)
    1736     {
    1737         if (!CheckEventSize(evt.GetSize(), "SetChannelOffsetToZero", 2))
    1738             return false;
    1739 
    1740         fBias.RampSingleChannelOffset(evt.GetUShort(), 0, false);
     1702    int ExpertSetGlobalVolt(const EventImp &evt)
     1703    {
     1704        if (!CheckEventSize(evt.GetSize(), "ExpertSetGlobalVolt", 4))
     1705            return false;
     1706
     1707        fBias.ExpertGlobalSetVolt(evt.GetFloat());
    17411708
    17421709        return T::GetCurrentState();
    17431710    }
    17441711
    1745     // --------------------------------------------------------------------
    1746 
    1747     int ExpertSetGlobalVolt(const EventImp &evt)
    1748     {
    1749         if (!CheckEventSize(evt.GetSize(), "ExpertSetGlobalVolt", 4))
    1750             return false;
    1751 
    1752         fBias.ExpertGlobalSetVolt(evt.GetFloat());
     1712    int ExpertSetGlobalDac(const EventImp &evt)
     1713    {
     1714        if (!CheckEventSize(evt.GetSize(), "ExpertSetGlobalDac", 2))
     1715            return false;
     1716
     1717        fBias.ExpertGlobalSetDac(evt.GetUShort());
    17531718
    17541719        return T::GetCurrentState();
    17551720    }
    17561721
    1757     int ExpertSetGlobalDac(const EventImp &evt)
    1758     {
    1759         if (!CheckEventSize(evt.GetSize(), "ExpertSetGlobalDac", 2))
    1760             return false;
    1761 
    1762         fBias.ExpertGlobalSetDac(evt.GetUShort());
     1722    int ExpertSetChannelVolt(const EventImp &evt)
     1723    {
     1724        if (!CheckEventSize(evt.GetSize(), "ExpertSetChannelVolt", 6))
     1725            return false;
     1726
     1727        fBias.ExpertChannelSetVolt(evt.GetUShort(), evt.Get<float>(2));
    17631728
    17641729        return T::GetCurrentState();
    17651730    }
    17661731
    1767     int ExpertSetChannelVolt(const EventImp &evt)
    1768     {
    1769         if (!CheckEventSize(evt.GetSize(), "ExpertSetChannelVolt", 6))
    1770             return false;
    1771 
    1772         fBias.ExpertChannelSetVolt(evt.GetUShort(), evt.Get<float>(2));
     1732    int ExpertSetChannelDac(const EventImp &evt)
     1733    {
     1734        if (!CheckEventSize(evt.GetSize(), "ExpertSetChannelDac", 4))
     1735            return false;
     1736
     1737        fBias.ExpertChannelSetDac(evt.Get<uint16_t>(), evt.Get<uint16_t>(2));
    17731738
    17741739        return T::GetCurrentState();
    17751740    }
    17761741
    1777     int ExpertSetChannelDac(const EventImp &evt)
    1778     {
    1779         if (!CheckEventSize(evt.GetSize(), "ExpertSetChannelDac", 4))
    1780             return false;
    1781 
    1782         fBias.ExpertChannelSetDac(evt.Get<uint16_t>(), evt.Get<uint16_t>(2));
     1742    int ExpertLoadMapFile(const EventImp &evt)
     1743    {
     1744        if (evt.GetSize()==0)
     1745        {
     1746            T::Warn("ExpertLoadMapFile - No file name given.");
     1747            return T::GetCurrentState();
     1748        }
     1749
     1750        if (fBias.GetStatus()!=State::kVoltageOff)
     1751        {
     1752            T::Warn("ExpertLoadMapFile - Voltage must have been turned off.");
     1753            return T::GetCurrentState();
     1754        }
     1755
     1756        BiasMap map;
     1757
     1758        try
     1759        {
     1760            map.Read(evt.GetText());
     1761        }
     1762        catch (const runtime_error &e)
     1763        {
     1764            T::Warn("Getting reference voltages failed: "+string(e.what()));
     1765            return T::GetCurrentState();
     1766        }
     1767
     1768        if (!fBias.SetReferences(map.Vgapd(), map.Voffset(), map.Vslope()))
     1769        {
     1770            T::Warn("Setting reference voltages failed.");
     1771            return T::GetCurrentState();
     1772        }
    17831773
    17841774        return T::GetCurrentState();
     
    19641954            (bind(&StateMachineBias::SetAllChannelsVolt, this, placeholders::_1))
    19651955            ("Set all channels to the given new reference voltage. Starts ramping if necessary."
    1966              "voltage[V]:New reference voltage for all channels");
    1967 
    1968 
     1956             "|voltage[V]:New reference voltage for all channels");
     1957
     1958/*
    19691959        T::AddEvent("INCREASE_CHANNEL_VOLTAGE", "S:1;F:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
    19701960            (bind(&StateMachineBias::IncChannelVolt, this, placeholders::_1))
     
    19801970            ("Add the given voltages to the current reference voltages. Starts ramping if necessary."
    19811971             "offset[V]:Offsets to be added to the reference voltage of all channels in volts");
    1982 
    1983 
    1984         // SET_SINGLE_CHANNEL_OFFSET
    1985         T::AddEvent("SET_CHANNEL_OFFSET", "S:1;F:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
    1986             (bind(&StateMachineBias::SetChannelOffset, this, placeholders::_1))
    1987             ("Set single channels to its G-APD breakdown voltage plus overvoltage plus the given offset. Starts ramping if necessary."
    1988              "|channel[short]:Channel for which to set the target voltage [0-415]"
    1989              "|offset[V]:Offset to be added to the G-APD reference voltage of the given channel");
    1990         T::AddEvent("SET_GLOBAL_OFFSET", "F:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
    1991             (bind(&StateMachineBias::SetGlobalOffset, this, placeholders::_1))
    1992             ("Set all channels to their G-APD breakdown voltage plus overvoltage plus the given offset. Starts ramping if necessary."
    1993              "|offset[V]:Offset to be added to the G-APD reference voltage globally");
    1994         T::AddEvent("SET_ALL_CHANNELS_OFFSET", "F:416", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
    1995             (bind(&StateMachineBias::SetAllChannelsOffset, this, placeholders::_1))
    1996             ("Set all channels to their G-APD reference voltage plus the given offset. Starts ramping if necessary."
    1997              "|offset[V]:Offset to be added to the G-APD reference voltage globally");
    1998 
    1999 
    2000         T::AddEvent("SET_GLOBAL_OFFSET_TO_ZERO", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
    2001             (Wrapper(bind(&ConnectionBias::RampAllOffsets, &fBias, 0., false)))
    2002             ("Set all channels to their G-APD reference voltage. Starts ramping if necessary.");
    2003 
    2004         T::AddEvent("SET_CHANNEL_OFFSET_TO_ZERO", "S:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
    2005             (bind(&StateMachineBias::SetChannelOffsetToZero, this, placeholders::_1))
    2006             ("Set a single channel channels to its G-APD reference voltage. Starts ramping if necessary."
    2007              "|channel[short]:Channel for which to set the target voltage [0-416]");
     1972*/
    20081973
    20091974
     
    20642029            (bind(&StateMachineBias::ExpertSetChannelDac, this, placeholders::_1))
    20652030            ("Send a single channel set command.");
     2031
     2032        T::AddEvent("EXPERT_LOAD_MAP_FILE", "C", State::kExpertMode)
     2033            (bind(&StateMachineBias::ExpertLoadMapFile, this, placeholders::_1))
     2034            ("Load a new mapping file.");
    20662035    }
    20672036
     
    21922161        ("sync-delay",      var<uint16_t>(500),  "Delay between sending the inital 0's after a newly established connection to synchronize the output stream in milliseconds")
    21932162        ("volt-max-abs",    var<float>(75),      "Absolte upper limit for the voltage (in Volts)")
    2194         ("volt-max-rel",    var<float>(2.5),     "Relative upper limit for the voltage w.r.t. the G-APD reference voltage (in Volts)")
     2163        ("volt-max-rel",    var<float>(3.5),     "Relative upper limit for the voltage w.r.t. the G-APD reference voltage (in Volts)")
    21952164        ("bias-map-file",   var<string>(),       "File with nominal and offset voltages for each channel.")
    21962165        ("bias-database",   var<string>(),       "")
Note: See TracChangeset for help on using the changeset viewer.