Changeset 13236 for trunk/FACT++


Ignore:
Timestamp:
03/26/12 22:01:13 (13 years ago)
Author:
tbretz
Message:
Changed the code in a way that now it operates on floating point values rather than dac counts and only converts to dac counts as last step. This also enables that the bias crate calibration offset is now separated from the set-value and the displayed value in the gui should be the actual output value of the crate.
File:
1 edited

Legend:

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

    r13189 r13236  
    4141
    4242    bool fIsVerbose;
    43 
    44     vector<uint16_t> fDacCmd;     // Current command voltage in DAC units (12bit = 90V)
     43    bool fIsDummyMode;
    4544
    4645    vector<bool>     fPresent;
     
    5049
    5150    int16_t fGlobalDacCmd;      // Command value to be reached
    52 //    uint16_t fExpertVoltRef;      // Command value to be reached
    5351
    5452    int16_t fRampStep;
     
    6563
    6664protected:
    67     vector<uint16_t> fDac;        // Current voltage in DAC units (12bit = 90V)
    68     vector<uint16_t> fDacRef;     // Current reference voltage in DAC units (12bit = 90V)
    69     vector<uint16_t> fDacGapd;    // Nominal G-APD voltages at 25deg C
    7065
    7166    vector<int16_t>  fCurrent;     // Current in ADC units (12bit = 5mA)
    7267
    73     uint16_t fDacMaxAbs;
    74     uint16_t fDacMaxRel;
    75 
    7668    virtual void UpdateA()
    7769    {
     
    8678    }
    8779
     80    // ====================================================
     81
     82    vector<float> fBreakdownVoltage;      // Breakdown voltage of GAPDs
     83    vector<float> fOvervoltage;           // Requested overvoltage of GAPDs
     84    vector<float> fChannelCalibration;    // Bias crate channel offset
     85    vector<float> fChannelOffset;         // User defined channel offset
     86
     87    float fVoltageMaxAbs;  // Maximum voltage
     88    float fVoltageMaxRel;  // Maximum voltgage above (what?)
     89
     90    vector<uint16_t> fDacTarget;    // Target values
     91    vector<uint16_t> fDacCommand;   // Last sent command value
     92    vector<uint16_t> fDacActual;    // Actual value
     93
     94    // ====================================================
     95
    8896private:
    89     bool CheckChDac(const string &cmd, uint16_t dac, uint16_t ch=0)
    90     {
    91         ostringstream str;
    92         str << cmd << " - ";
    93 
    94         if (ch>=kNumChannels)
    95         {
    96             str << "Channel " << ch << " out of range [0,416].";
    97             Error(str);
    98             return false;
    99         }
    100 
    101         if (dac>kMaxDac)
    102         {
    103             str << "DAC value " << dac << " out of range [0,4095].";
    104             Error(str);
    105             return false;
    106         }
    107         if (dac>fDacMaxAbs)
    108         {
    109             str << "DAC value " << dac << " exceeds allowed absolute maximum of " << fDacMaxAbs;
    110             Error(str);
    111             return false;
    112         }
    113         if (dac>fDacGapd[ch]+fDacMaxRel)
    114         {
    115             str << "DAC value " << dac << " exceeds allowed channel maximum of " << fDacGapd[ch] << " + " << fDacMaxRel;
    116             Error(str);
    117             return false;
    118         }
    119 
    120         return true;
    121     }
    122 
    12397    vector<char> GetCmd(uint16_t board, uint16_t channel, Command_t cmd, uint16_t dac=0)
    12498    {
     
    230204        {
    231205            Message("Reset button on crate pressed!");
    232             SetZero();
     206            RampAllDacs(0);
    233207            return true;
    234208        }
     
    251225            {
    252226                for (int i=0; i<kNumChannels; i++)
    253                     fDac[i] = fGlobalDacCmd;
     227                    fDacActual[i] = fGlobalDacCmd;
    254228
    255229                fGlobalDacCmd = -1;
     
    293267
    294268        if (cmd==kCmdChannelSet)
    295             fDac[id] = fDacCmd[id];
     269            fDacActual[id] = fDacCommand[id];
    296270
    297271        return true;
     
    583557        if (fWrapCounter<0)
    584558        {
    585             fDac.assign(   kNumChannels, 0);
    586             fDacRef.assign(kNumChannels, 0);
    587             fDacCmd.assign(kNumChannels, 0);
     559            fDacTarget.assign(kNumChannels, 0);
     560            fDacCommand.assign(kNumChannels, 0);
     561            fDacActual.assign(kNumChannels, 0);
    588562        }
    589563
     
    648622    // --------------------------------------------------------------------
    649623
     624    void PrintLineCmdDac(int b, int ch, const vector<uint16_t> &dac)
     625    {
     626        Out() << setw(2) << b << "|";
     627
     628        for (int c=ch; c<ch+4; c++)
     629        {
     630            const int id = c+kNumChannelsPerBoard*b;
     631            Out() << " " << setw(4) << int32_t(dac[id])<<"/"<<fDacActual[id] << ":" << setw(5) << fDacTarget[id]*90./4096;
     632        }
     633        Out() << endl;
     634    }
     635
     636    void PrintCommandDac(const vector<uint16_t> &dac)
     637    {
     638        Out() << dec << setprecision(2) << fixed << setfill(' ');
     639        for (int b=0; b<kNumBoards; b++)
     640        {
     641            if (!fPresent[b])
     642            {
     643                Out() << setw(2) << b << "-" << endl;
     644                continue;
     645            }
     646
     647            PrintLineCmdDac(b,  0, dac);
     648            PrintLineCmdDac(b,  4, dac);
     649            PrintLineCmdDac(b,  8, dac);
     650            PrintLineCmdDac(b, 12, dac);
     651            PrintLineCmdDac(b, 16, dac);
     652            PrintLineCmdDac(b, 20, dac);
     653            PrintLineCmdDac(b, 24, dac);
     654            PrintLineCmdDac(b, 28, dac);
     655        }
     656    }
     657
    650658    void SetAllChannels(const vector<uint16_t> &dac, bool special=false)
    651659    {
     660        if (fIsDummyMode)
     661        {
     662            PrintCommandDac(dac);
     663            return;
     664        }
     665
    652666        vector<char> data;
    653667        data.reserve(kNumChannels*3);
     
    659673            data.insert(data.end(), cmd.begin(), cmd.end());
    660674
    661             fDacCmd[ch] = dac[ch];
     675            fDacCommand[ch] = dac[ch];
    662676        }
    663677
     
    674688    uint16_t RampOneStep(uint16_t ch)
    675689    {
    676         if (fDacRef[ch]>fDac[ch])
    677             return fDac[ch]+fRampStep>fDacRef[ch] ? fDacRef[ch] : fDac[ch]+fRampStep;
    678 
    679         if (fDacRef[ch]<fDac[ch])
    680             return fDac[ch]-fRampStep<fDacRef[ch] ? fDacRef[ch] : fDac[ch]-fRampStep;
    681 
    682         return fDac[ch];
     690        if (fDacTarget[ch]>fDacActual[ch])
     691            return fDacActual[ch]+fRampStep>fDacTarget[ch] ? fDacTarget[ch] : fDacActual[ch]+fRampStep;
     692
     693        if (fDacTarget[ch]<fDacActual[ch])
     694            return fDacActual[ch]-fRampStep<fDacTarget[ch] ? fDacTarget[ch] : fDacActual[ch]-fRampStep;
     695
     696        return fDacActual[ch];
    683697    }
    684698
     
    702716        {
    703717            dac[ch] = RampOneStep(ch);
    704             if (dac[ch]!=fDac[ch] && fPresent[ch/kNumChannelsPerBoard])
     718            if (dac[ch]!=fDacActual[ch] && fPresent[ch/kNumChannelsPerBoard])
    705719                identical = false;
    706720        }
     
    785799        fBufferUpdate(3*kNumChannels),
    786800        fIsVerbose(false),
    787         fDacCmd(kNumChannels),
     801        fIsDummyMode(false),
    788802        fPresent(kNumBoards),
    789803        fWrapCounter(-1),
     
    795809        fWaitingForAnswer(-1),
    796810        fCounter(8),
    797         fDac(kNumChannels),
    798         fDacRef(kNumChannels),
    799         fDacGapd(kNumChannels),
    800         fCurrent(kNumChannels)
     811        fCurrent(kNumChannels),
     812        fBreakdownVoltage(kNumChannels, 0),
     813        fOvervoltage(kNumChannels),
     814        fChannelCalibration(kNumChannels),
     815        fChannelOffset(kNumChannels),
     816        fVoltageMaxAbs(75),
     817        fVoltageMaxRel(2),
     818        fDacTarget(kNumChannels),
     819        fDacCommand(kNumChannels),
     820        fDacActual(kNumChannels)
    801821    {
    802822        SetLogStream(&imp);
    803823    }
     824
     825    // --------------------------------------------------------------------
     826
     827    bool CheckDac(uint16_t dac)
     828    {
     829        if (dac<4096)
     830            return true;
     831
     832        ostringstream msg;
     833        msg << "CheckDac - Dac value of " << dac << " exceeds maximum of 4095.";
     834        Error(msg);
     835        return false;
     836    }
     837
     838    bool CheckChannel(uint16_t ch)
     839    {
     840        if (ch<kNumChannels)
     841            return true;
     842
     843        ostringstream msg;
     844        msg << "CheckChannel - Channel " << ch << " out of range [0;" << kNumChannels-1 << "].";
     845        Error(msg);
     846        return false;
     847    }
     848
     849    bool CheckChannelVoltage(uint16_t ch, float volt)
     850    {
     851        if (volt>fVoltageMaxAbs)
     852        {
     853            ostringstream msg;
     854            msg << "CheckChannelVoltage - Set voltage " << volt << "V of channel " << ch << " exeeds absolute limit of " << fVoltageMaxAbs << "V.";
     855            Error(msg);
     856            return false;
     857        }
     858
     859        if (fBreakdownVoltage[ch]<=0)
     860            return true;
     861
     862        if (volt>fBreakdownVoltage[ch]+fVoltageMaxRel)
     863        {
     864            ostringstream msg;
     865            msg << "CheckChannelVoltage - Set voltage " << volt << "V of channel " << ch << " exeeds limit of " << fVoltageMaxRel << "V above breakdown voltage " << fBreakdownVoltage[ch] << "V + limit " << fVoltageMaxRel << "V.";
     866            Error(msg);
     867            return false;
     868        }
     869
     870        return true;
     871    }
     872
     873    // --------------------------------------------------------------------
     874
     875    bool RampSingleChannelDac(uint16_t ch, uint16_t dac)
     876    {
     877        if (!CheckChannel(ch))
     878            return false;
     879
     880        if (!CheckDac(dac))
     881            return false;
     882
     883        fDacTarget[ch] = dac;
     884        UpdateV();
     885
     886        if (!fIsRamping)
     887            fIsRamping = RampOneStep();
     888
     889        return true;
     890    }
     891
     892    bool RampAllChannelsDac(const vector<uint16_t> &dac)
     893    {
     894        for (int ch=0; ch<kNumChannels; ch++)
     895            if (!CheckDac(dac[ch]))
     896                return false;
     897
     898        fDacTarget = dac;
     899        UpdateV();
     900
     901        if (!fIsRamping)
     902            fIsRamping = RampOneStep();
     903
     904        return true;
     905    }
     906
     907    bool RampAllDacs(uint16_t dac)
     908    {
     909        return RampAllChannelsDac(vector<uint16_t>(kNumChannels, dac));
     910    }
     911
     912    // --------------------------------------------------------------------
     913
     914    uint16_t ConvertVoltToDac(uint16_t ch, double volt)
     915    {
     916        volt += fChannelCalibration[ch];
     917        if (volt<0)
     918            volt = 0;
     919
     920        return volt*4096/90;
     921    }
     922
     923    // --------------------------------------------------------------------
     924
     925    bool RampSingleChannelVoltage(uint16_t ch, float volt)
     926    {
     927        if (!CheckChannel(ch))
     928            return false;
     929
     930        if (!CheckChannelVoltage(ch, volt))
     931            return false;
     932
     933        const uint16_t dac = ConvertVoltToDac(ch, volt);
     934        return RampSingleChannelDac(ch, dac);
     935    }
     936
     937    bool RampAllChannelsVoltage(const vector<float> &volt)
     938    {
     939        vector<uint16_t> dac(kNumChannels);
     940        for (size_t ch=0; ch<kNumChannels; ch++)
     941        {
     942            if (!CheckChannelVoltage(ch, volt[ch]))
     943                return false;
     944
     945            dac[ch] = ConvertVoltToDac(ch, volt[ch]);
     946        }
     947
     948        return RampAllChannelsDac(dac);
     949    }
     950
     951    bool RampAllVoltages(float volt)
     952    {
     953        return RampAllChannelsVoltage(vector<float>(kNumChannels, volt));
     954    }
     955
     956    // --------------------------------------------------------------------
     957
     958    bool RampSingleChannelOffset(uint16_t ch, float offset, bool relative)
     959    {
     960        if (!CheckChannel(ch))
     961            return false;
     962
     963        if (relative)
     964            offset += fDacActual[ch]*90./4096 - fBreakdownVoltage[ch] - fOvervoltage[ch];
     965
     966        const float volt = fBreakdownVoltage[ch]>0 ? fBreakdownVoltage[ch] + fOvervoltage[ch] + offset : 0;
     967
     968        if (!RampSingleChannelVoltage(ch, volt))
     969            return false;
     970
     971        fChannelOffset[ch] = offset;
     972
     973        return true;
     974    }
     975
     976    bool RampAllChannelsOffset(vector<float> offset, bool relative)
     977    {
     978        vector<float> volt(kNumChannels);
     979
     980        if (relative)
     981            for (size_t ch=0; ch<kNumChannels; ch++)
     982                offset[ch] += fDacActual[ch]*90./4096 - fBreakdownVoltage[ch] - fOvervoltage[ch];
     983
     984        for (size_t ch=0; ch<kNumChannels; ch++)
     985            volt[ch] = fBreakdownVoltage[ch]>0 ? fBreakdownVoltage[ch] + fOvervoltage[ch] + offset[ch] : 0;
     986
     987        if (!RampAllChannelsVoltage(volt))
     988            return false;
     989
     990        fChannelOffset = offset;
     991
     992        return true;
     993    }
     994
     995    bool RampAllOffsets(float offset, bool relative)
     996    {
     997        return RampAllChannelsOffset(vector<float>(kNumChannels, offset), relative);
     998    }
     999
     1000    /*
     1001    bool RampSingleChannelOvervoltage(float offset)
     1002    {
     1003        return RampAllChannelsOvervoltage(vector<float>(kNumChannels, offset));
     1004    }
     1005    bool RampAllOvervoltages(const vector<float> &overvoltage)
     1006    {
     1007        vector<float> volt(kNumChannels);
     1008
     1009        for (size_t ch=0; ch<kNumChannels; ch++)
     1010            volt[ch] = fBreakdownVoltage[ch] + fOvervoltage[ch] + fChannelOffset[ch];
     1011
     1012#warning What about empty channels?
     1013
     1014        if (!RampAllChannelsVoltage(volt))
     1015            return false;
     1016
     1017        for (size_t ch=0; ch<kNumChannels; ch++)
     1018            fOvervoltage[ch] = overvoltage[ch];
     1019
     1020        return true;
     1021    }*/
     1022
     1023    // --------------------------------------------------------------------
    8041024
    8051025    void OverCurrentReset()
     
    8191039        }
    8201040
    821         vector<uint16_t> dac(kNumChannels);
     1041        vector<uint16_t> dac(fDacActual);
    8221042
    8231043        for (int ch=0; ch<kNumChannels; ch++)
    824             dac[ch] = fCurrent[ch]<0 ? 0 : fDac[ch];
     1044            if (fCurrent[ch]<0)
     1045                dac[ch] = 0;
    8251046
    8261047        SetAllChannels(dac, true);
     
    8561077    }
    8571078
    858     // --------------------------------------------------------------------
    859 
    860     bool ChannelSetDac(uint16_t ch, uint16_t dac)
    861     {
    862         if (!CheckChDac("ChannelSetDac", dac, ch))
    863             return false;
    864 
    865         fDacRef[ch] = dac;
    866 
    867         if (!fIsRamping)
    868             fIsRamping = RampOneStep();
    869 
    870         return true;
    871     }
    872 
    873     bool ChannelSetVolt(uint16_t ch, double volt)
    874     {
    875         if (volt<0 || volt>90)
    876         {
    877             ostringstream msg;
    878             msg << "ChannelSetVolt - Given voltage " << volt << "V out of range [0V,90V].";
    879             Error(msg);
    880             return false;
    881         }
    882 
    883         return ChannelSetDac(ch, volt*4096/90.);
    884     }
    885 /*
    886     bool GlobalSetDac(uint16_t dac)
    887     {
    888         if (!CheckChDac("GlobalSetDac", dac))
    889             return false;
    890 
    891         for (size_t ch=0; ch<kNumChannels; ch++)
    892             fVoltRef[ch] = dac;
    893 
    894         if (!fIsRamping)
    895             fIsRamping = RampOneStep();
    896 
    897         return true;
    898     }
    899 
    900     bool GlobalSetVolt(float volt)
    901     {
    902         if (volt<0 || volt>90)
    903         {
    904             Error("GlobalSetVolt - Voltage out of range [0V,90V].");
    905             return false;
    906         }
    907 
    908         return GlobalSetDac(volt*4096/90);
    909     }
    910 */
    911     bool AddDac(const vector<int16_t> &dac)
    912     {
    913         if (dac.size()!=kNumChannels)
    914         {
    915             Error("AddDac - Wrong size of array.");
    916             return false;
    917         }
    918 
    919         for (size_t ch=0; ch<kNumChannels; ch++)
    920         {
    921             if (fDacRef[ch]+dac[ch]>kMaxDac)
    922             {
    923                 ostringstream msg;
    924                 msg << "AddDac - New voltage reference " << fDacRef[ch] << "+" << dac[ch] << " out of range [0," << kMaxDac << " for channel " << ch << ".";
    925                 Error(msg);
    926                 return false;
    927             }
    928 
    929             if (fDacRef[ch]+dac[ch]<0)
    930                 fDacRef[ch] = 0;
    931             else
    932                 fDacRef[ch] += dac[ch];
    933         }
    934 
    935         if (!fIsRamping)
    936             fIsRamping = RampOneStep();
    937 
    938         return true;
    939     }
    940 
    941     bool AddVolt(const vector<float> &offset)
    942     {
    943         vector<int16_t> dac(offset.size());
    944 
    945         for (size_t ch=0; ch<offset.size(); ch++)
    946         {
    947             if (offset[ch]<-90 || offset[ch]>90)
    948             {
    949                 ostringstream msg;
    950                 msg << "AddVolt - Offset voltage " << offset[ch] << "V for channel " << ch << " out of range [-90V,90V].";
    951                 Error(msg);
    952                 return false;
    953             }
    954             dac[ch] = offset[ch]*4096/90;
    955         }
    956 
    957         return AddDac(dac);
    958     }
    959 
    960     bool GlobalAddDac(int16_t offset)
    961     {
    962         return AddDac(vector<int16_t>(kNumChannels, offset));
    963     }
    964 
    965     bool GlobalAddVolt(float offset)
    966     {
    967         return AddVolt(vector<float>(kNumChannels, offset));
    968     }
    969 
    970     bool SetDac(const vector<int16_t> &dac)
    971     {
    972         if (dac.size()!=kNumChannels)
    973         {
    974             Error("SetDac - Wrong size of array.");
    975             return false;
    976         }
    977 
    978         for (size_t ch=0; ch<kNumChannels; ch++)
    979         {
    980             if (!CheckChDac("SetDac", dac[ch]))
    981                 return false;
    982 
    983             fDacRef[ch] = dac[ch];
    984         }
    985 
    986         if (!fIsRamping)
    987             fIsRamping = RampOneStep();
    988 
    989         return true;
    990     }
    991 
    992     bool SetVolt(const vector<float> &volt)
    993     {
    994         vector<int16_t> dac(volt.size());
    995 
    996         for (size_t ch=0; ch<volt.size(); ch++)
    997         {
    998             if (volt[ch]<0 || volt[ch]>90)
    999             {
    1000                 ostringstream msg;
    1001                 msg << "SetVolt - Voltage " << volt[ch] << "V out of range [0V,90V] for channel " << ch << ".";
    1002                 Error(msg);
    1003                 return false;
    1004             }
    1005             dac[ch] = volt[ch]*4096/90;
    1006         }
    1007 
    1008         return SetDac(dac);
    1009     }
    1010 
    1011     bool GlobalSetDac(int16_t dac)
    1012     {
    1013         return SetDac(vector<int16_t>(kNumChannels, dac));
    1014     }
    1015 
    1016     bool GlobalSetVolt(float volt)
    1017     {
    1018         return SetVolt(vector<float>(kNumChannels, volt));
    1019     }
    1020 
    1021 
    1022     // --------------------------------------------------------------------
    1023 
    1024     bool SetGapdVoltage(float offset)
    1025     {
    1026         if (offset<-90 || offset>90)
    1027         {
    1028             ostringstream msg;
    1029             msg << "SetGapdVoltage - Offset voltage " << offset << "V out of range [-90V,90V].";
    1030             Error(msg);
    1031             return false;
    1032         }
    1033 
    1034         const int16_t dac = offset*4096/90;
    1035 
    1036         for (size_t ch=0; ch<kNumChannels; ch++)
    1037             if (fDacGapd[ch]+dac>kMaxDac)
    1038             {
    1039                 ostringstream msg;
    1040                 msg << "SetGapdVoltage - New voltage reference " << fDacGapd[ch] << "+" << dac << " out of range [0," << kMaxDac << " for channel " << ch << ".";
    1041                 Error(msg);
    1042                 return false;
    1043             }
    1044 
    1045         for (size_t ch=0; ch<kNumChannels; ch++)
    1046             fDacRef[ch] = fDacGapd[ch]+dac<0 ? 0 : fDacGapd[ch]+dac;
    1047 
    1048         if (!fIsRamping)
    1049             fIsRamping = RampOneStep();
    1050 
    1051         return true;
    1052     }
    1053 
    1054     bool SetGapdVoltages(const vector<float> &offset)
    1055     {
    1056         vector<int16_t> dac(kNumChannels);
    1057         for (size_t ch=0; ch<kNumChannels; ch++)
    1058         {
    1059             if (offset[ch]<-90 || offset[ch]>90)
    1060             {
    1061                 ostringstream msg;
    1062                 msg << "SetGapdVoltage - Offset voltage " << offset[ch] << "V of channel " << ch << " out of range [-90V,90V].";
    1063                 Error(msg);
    1064                 return false;
    1065             }
    1066 
    1067             dac[ch] = offset[ch]*4096/90;
    1068 
    1069             if (fDacGapd[ch]+dac[ch]>kMaxDac)
    1070             {
    1071                 ostringstream msg;
    1072                 msg << "SetGapdVoltage - New voltage reference " << fDacGapd[ch] << "+" << dac[ch] << " out of range [0," << kMaxDac << " for channel " << ch << ".";
    1073                 Error(msg);
    1074                 return false;
    1075             }
    1076         }
    1077 
    1078         for (size_t ch=0; ch<kNumChannels; ch++)
    1079             fDacRef[ch] = fDacGapd[ch]+dac[ch]<0 ? 0 : fDacGapd[ch]+dac[ch];
    1080 
    1081         if (!fIsRamping)
    1082             fIsRamping = RampOneStep();
    1083 
    1084         return true;
    1085     }
    1086 
    1087     bool SetGapdReferenceCh(uint16_t ch)
    1088     {
    1089         if (!CheckChDac("SetGapdReferenceCh", fDacGapd[ch], ch))
    1090             return false;
    1091 
    1092         fDacRef[ch] = fDacGapd[ch];
    1093 
    1094         if (!fIsRamping)
    1095             fIsRamping = RampOneStep();
    1096 
    1097         return true;
    1098     }
    1099 
    1100 
    1101     void SetZero()
    1102     {
    1103         for (size_t ch=0; ch<kNumChannels; ch++)
    1104             fDacRef[ch] = 0;
    1105 
    1106         if (!fIsRamping)
    1107             fIsRamping = RampOneStep();
    1108     }
    1109 
    1110     bool SetNewGapdVoltage(const vector<float> &volt)
     1079    bool SetReferences(const vector<float> &volt, const vector<float> &offset)
    11111080    {
    11121081        if (volt.size()!=kNumChannels)
    11131082        {
    11141083            ostringstream out;
    1115             out << "SetNewGapdVoltage - Given vector has " << volt.size() << " elements - expected " << kNumChannels << endl;
     1084            out << "SetReferences - Given vector has " << volt.size() << " elements - expected " << kNumChannels << endl;
    11161085            Error(out);
    11171086            return false;
    11181087        }
    1119 
    1120         for (size_t i=0; i<kNumChannels; i++)
    1121             fDacGapd[i] = volt[i]*4096/90;
     1088        if (offset.size()!=kNumChannels)
     1089        {
     1090            ostringstream out;
     1091            out << "SetReferences - Given vector has " << volt.size() << " elements - expected " << kNumChannels << endl;
     1092            Error(out);
     1093            return false;
     1094        }
     1095
     1096        fBreakdownVoltage   = volt;
     1097        fChannelCalibration = offset;
     1098        fOvervoltage.assign(kNumChannels, 0);
    11221099
    11231100        UpdateVgapd();
     
    11951172        }
    11961173
    1197         if (!CheckChDac("ExpertChannelSetDac", dac, ch))
    1198             return false;
    1199 
    1200         fDacCmd[ch] = dac;
     1174        if (!CheckDac(dac))
     1175            return false;
     1176
     1177        fDacCommand[ch] = dac;
    12011178
    12021179        ostringstream msg;
     
    12271204        }
    12281205
    1229         if (!CheckChDac("ExpertGlobalSetDac", dac))
     1206        if (!CheckDac(dac))
    12301207            return false;
    12311208
     
    12591236    {
    12601237        fIsVerbose = b;
     1238    }
     1239
     1240    void SetDummyMode(bool b)
     1241    {
     1242        fIsDummyMode = b;
    12611243    }
    12621244
     
    13191301            const int id = c+kNumChannelsPerBoard*b;
    13201302            Out() << " ";
    1321             Out() << (fDac[id]==fDacRef[id]?kGreen:kRed);
    1322             Out() << setw(5) << fDac[id]*90/4096. << '/';
    1323             Out() << setw(5) << fDacRef[id]*90/4096.;
     1303            Out() << (fDacActual[id]==fDacTarget[id]?kGreen:kRed);
     1304            Out() << setw(5) << fDacActual[id]*90/4096. << '/';
     1305            Out() << setw(5) << fDacTarget[id]*90/4096.;
    13241306        }
    13251307        Out() << endl;
     
    13551337        {
    13561338            const int id = c+kNumChannelsPerBoard*b;
    1357             Out() << " " << setw(5) << fDacGapd[id]*90/4096.;
     1339            Out() << " " << setw(5) << fBreakdownVoltage[id]+fOvervoltage[id];
    13581340        }
    13591341        Out() << endl;
    13601342    }
    13611343
    1362     void PrintGapd()
     1344    void PrintReferenceVoltage()
    13631345    {
    13641346        Out() << dec << setprecision(2) << fixed << setfill(' ');
     
    14001382    void SetVoltMaxAbs(float max)
    14011383    {
    1402         fDacMaxAbs = max*4096/90;
    1403         if (fDacMaxAbs>4095)
    1404             fDacMaxAbs = 4095;
     1384        if (max>90)
     1385            max = 90;
    14051386        if (max<0)
    1406             fDacMaxAbs = 0;
     1387            max = 0;
     1388
     1389        fVoltageMaxAbs = max;
    14071390    }
    14081391
    14091392    void SetVoltMaxRel(float max)
    14101393    {
    1411         fDacMaxRel = max*4096/90;
    1412         if (fDacMaxRel>4095)
    1413             fDacMaxRel = 4095;
     1394        if (max>90)
     1395            max = 90;
    14141396        if (max<0)
    1415             fDacMaxRel = 0;
     1397            max = 0;
     1398
     1399        fVoltageMaxRel = max;
    14161400    }
    14171401
    14181402    uint16_t GetVoltMaxAbs() const
    14191403    {
    1420         return fDacMaxAbs * 90./4096;
     1404        return fVoltageMaxAbs;
    14211405    }
    14221406
    14231407    uint16_t GetVoltMaxRel() const
    14241408    {
    1425         return fDacMaxRel * 90./4096;
    1426     }
    1427 
    1428 /*
    1429     void AdaptVoltages()
    1430     {
    1431         // Correct voltages according to current
    1432         for (int i=0; i<kNumChannels; i++)
    1433         {
    1434             if (fVoltRef[i]==0 || fCurrent[i]<0 || fRefCurrent[i]<0)
    1435                 continue;
    1436 
    1437             // Calculate difference and convert ADC units to Amp
    1438             // const double diffcur = (fRefCurrent[i]-fCurrent[i])*5000/4096
    1439             //const int32_t diffcur = int32_t(fRefCurrent[i]-fCurrent[i])*5000;
    1440 
    1441             // Calculate voltage difference
    1442             // #define RESISTOR 1000 // Ohm
    1443             //const double diffvolt = diffcur*RESISTOR/1e6;
    1444 
    1445             // Calculate new vlaue by onverting voltage difference to DAC units
    1446             //const int32_t dac = fRefVolt[i] + diffvolt*4096/90.0;
    1447             SetVoltage(i, fRefVolt[i] + (fRefCurrent[i]-fCurrent[i])/18);
    1448         }
    1449     }
    1450 
    1451     void SetReferenceCurrent()
    1452     {
    1453         fRefCurrent = fCurrent;
    1454     }
    1455     */
     1409        return fVoltageMaxRel;
     1410    }
    14561411
    14571412    States_t GetStatus()
     
    14751430        bool isoff = true;
    14761431        for (int ch=0; ch<kNumChannels; ch++)
    1477             if (fPresent[ch/kNumChannelsPerBoard] && fDac[ch]!=0)
     1432            if (fPresent[ch/kNumChannelsPerBoard] && fDacActual[ch]!=0)
    14781433                isoff = false;
    14791434        if (isoff)
     
    14811436
    14821437        for (int ch=0; ch<kNumChannels; ch++)
    1483             if (fPresent[ch/kNumChannelsPerBoard] && fDac[ch]!=fDacRef[ch])
     1438            if (fPresent[ch/kNumChannelsPerBoard] && fDacActual[ch]!=fDacTarget[ch])
    14841439                return BIAS::kNotReferenced;
    14851440
     
    14971452
    14981453    DimDescribedService fDimCurrent;
    1499     DimDescribedService fDimVoltage;
     1454    DimDescribedService fDimDac;
     1455    DimDescribedService fDimVolt;
    15001456    DimDescribedService fDimGapd;
    15011457
     
    15071463    void UpdateV()
    15081464    {
    1509         vector<uint16_t> vec;
    1510         vec.insert(vec.end(), fDac.begin(),    fDac.end());
    1511         vec.insert(vec.end(), fDacRef.begin(), fDacRef.end());
    1512         fDimVoltage.Update(vec);
     1465        vector<uint16_t> val(2*kNumChannels);
     1466        memcpy(val.data(),              fDacActual.data(), kNumChannels*2);
     1467        memcpy(val.data()+kNumChannels, fDacTarget.data(), kNumChannels*2);
     1468        fDimDac.Update(val);
     1469
     1470        vector<float> volt(kNumChannels);
     1471        for (float ch=0; ch<kNumChannels; ch++)
     1472            volt[ch] = fDacActual[ch]*90./4096 - fChannelCalibration[ch];
     1473        fDimVolt.Update(volt);
    15131474    }
    15141475
    15151476    void UpdateVgapd()
    15161477    {
    1517         fDimGapd.Update(fDacGapd);
     1478        vector<float> volt;
     1479        volt.reserve(3*kNumChannels);
     1480        volt.insert(volt.end(), fBreakdownVoltage.begin(),   fBreakdownVoltage.end());
     1481        volt.insert(volt.end(), fOvervoltage.begin(),        fOvervoltage.end());
     1482        volt.insert(volt.end(), fChannelCalibration.begin(), fChannelCalibration.end());
     1483        fDimGapd.Update(volt);
    15181484    }
    15191485
     
    15211487    ConnectionDimBias(ba::io_service& ioservice, MessageImp &imp) :
    15221488        ConnectionBias(ioservice, imp),
    1523         fDimCurrent("BIAS_CONTROL/CURRENT", "S:416",       "|I[uA]:Bias current"),
    1524         fDimVoltage("BIAS_CONTROL/VOLTAGE", "S:416;S:416", "|U[V]:Applied bias voltage|Uref[V]:Reference bias voltage"),
    1525         fDimGapd(   "BIAS_CONTROL/NOMINAL", "S:416",       "|U[V]:Nominal G-APD voltage at 25deg C")
     1489        fDimCurrent("BIAS_CONTROL/CURRENT", "S:416",
     1490                    "|I[uA]:Bias current"),
     1491        fDimDac("BIAS_CONTROL/DAC", "S:416;S:416",
     1492                "|U[dac]:Current dac setting"
     1493                "|Uref[dac]:Reference dac setting"),
     1494        fDimVolt("BIAS_CONTROL/VOLTAGE", "F:416",
     1495                 "|Uout[V]:Output voltage"),
     1496        fDimGapd("BIAS_CONTROL/NOMINAL", "F:416;F:416;F:416",
     1497                 "|Ubr[V]:Nominal breakdown voltage at 25deg C"
     1498                 "|Uov[V]:Nominal overvoltage"
     1499                 "|Uoff[V]:Bias crate channel offsets")
    15261500    {
    15271501    }
     
    15641538    // --------------------------------------------------------------------
    15651539
    1566     int SetGapdVoltage(const EventImp &evt)
    1567     {
    1568         if (!CheckEventSize(evt.GetSize(), "SetGapdVoltage", 4))
    1569             return false;
    1570 
    1571         fBias.SetGapdVoltage(evt.GetFloat());
     1540    // SET_GLOBAL_DAC_VALUE
     1541    int SetGlobalDac(const EventImp &evt)
     1542    {
     1543        if (!CheckEventSize(evt.GetSize(), "SetGlobalDac", 2))
     1544            return false;
     1545
     1546        fBias.RampAllDacs(evt.GetUShort());
    15721547
    15731548        return T::GetCurrentState();
    15741549    }
    15751550
    1576     int SetGapdVoltages(const EventImp &evt)
    1577     {
    1578         if (!CheckEventSize(evt.GetSize(), "SetGapdVoltages", 4*416))
     1551    // SET_CHANNEL_DAC_VALUE
     1552    int SetChannelDac(const EventImp &evt)
     1553    {
     1554        if (!CheckEventSize(evt.GetSize(), "SetChannelDac", 4))
     1555            return false;
     1556
     1557        fBias.RampSingleChannelDac(evt.Get<uint16_t>(), evt.Get<uint16_t>(2));
     1558
     1559        return T::GetCurrentState();
     1560    }
     1561
     1562    // --------------------------------------------------------------------
     1563
     1564    // SET_CHANNEL_VOLTAGE
     1565    int SetChannelVolt(const EventImp &evt)
     1566    {
     1567        if (!CheckEventSize(evt.GetSize(), "SetChannelVolt", 6))
     1568            return false;
     1569
     1570        fBias.RampSingleChannelVoltage(evt.GetUShort(), evt.Get<float>(2));
     1571
     1572        return T::GetCurrentState();
     1573    }
     1574
     1575    // SET_GLOBAL_VOLTAGE
     1576    int SetGlobalVolt(const EventImp &evt)
     1577    {
     1578        if (!CheckEventSize(evt.GetSize(), "SetGlobalVolt", 4))
     1579            return false;
     1580
     1581        fBias.RampAllVoltages(evt.GetFloat());
     1582
     1583        return T::GetCurrentState();
     1584    }
     1585
     1586    // SET_ALL_CHANNELS_VOLTAGES
     1587    int SetAllChannelsVolt(const EventImp &evt)
     1588    {
     1589        if (!CheckEventSize(evt.GetSize(), "SetAllChannelsVolt", 4*kNumChannels))
    15791590            return false;
    15801591
    15811592        const float *ptr = evt.Ptr<float>();
    1582         fBias.SetGapdVoltages(vector<float>(ptr, ptr+416));
     1593        fBias.RampAllChannelsVoltage(vector<float>(ptr, ptr+kNumChannels));
    15831594
    15841595        return T::GetCurrentState();
     
    15871598    // --------------------------------------------------------------------
    15881599
    1589     int SetGlobalVolt(const EventImp &evt)
    1590     {
    1591         if (!CheckEventSize(evt.GetSize(), "SetGlobalVolt", 4))
    1592             return false;
    1593 
    1594         fBias.GlobalSetVolt(evt.GetFloat());
     1600    // SET_GLOBAL_OFFSET
     1601    int SetGlobalOffset(const EventImp &evt)
     1602    {
     1603        if (!CheckEventSize(evt.GetSize(), "SetGlobalOffset", 4))
     1604            return false;
     1605
     1606        fBias.RampAllOffsets(evt.GetFloat(), false);
    15951607
    15961608        return T::GetCurrentState();
    15971609    }
    15981610
    1599     int SetGlobalDac(const EventImp &evt)
    1600     {
    1601         if (!CheckEventSize(evt.GetSize(), "SetGlobalDac", 2))
    1602             return false;
    1603 
    1604         fBias.GlobalSetDac(evt.GetUShort());
     1611    // SET_SINGLE_CHANNEL_OFFSET
     1612    int SetChannelOffset(const EventImp &evt)
     1613    {
     1614        if (!CheckEventSize(evt.GetSize(), "SetSingleChannelOffset", 6))
     1615            return false;
     1616
     1617        fBias.RampSingleChannelOffset(evt.Get<uint16_t>(), evt.Get<float>(2), false);
    16051618
    16061619        return T::GetCurrentState();
    16071620    }
    16081621
     1622    // SET_ALL_CHANNELS_OFFSET
     1623    int SetAllChannelsOffset(const EventImp &evt)
     1624    {
     1625        if (!CheckEventSize(evt.GetSize(), "SetAllChannelsOffset", 4*kNumChannels))
     1626            return false;
     1627
     1628        const float *ptr = evt.Ptr<float>();
     1629        fBias.RampAllChannelsOffset(vector<float>(ptr, ptr+kNumChannels), false);
     1630
     1631        return T::GetCurrentState();
     1632    }
     1633
     1634    // --------------------------------------------------------------------
     1635
     1636    // INCREASE_GLOBAL_VOLTAGE
    16091637    int IncGlobalVolt(const EventImp &evt)
    16101638    {
     
    16121640            return false;
    16131641
    1614         fBias.GlobalAddVolt(evt.GetFloat());
     1642        fBias.RampAllOffsets(evt.GetFloat(), true);
    16151643
    16161644        return T::GetCurrentState();
    16171645    }
    16181646
    1619     int IncGlobalDac(const EventImp &evt)
    1620     {
    1621         if (!CheckEventSize(evt.GetSize(), "IncGlobalDac", 2))
    1622             return false;
    1623 
    1624         fBias.GlobalAddDac(evt.GetShort());
     1647    // INCREASE_CHANNEL_VOLTAGE
     1648    int IncChannelVolt(const EventImp &evt)
     1649    {
     1650        if (!CheckEventSize(evt.GetSize(), "IncChannelVolt", 6))
     1651            return false;
     1652
     1653        fBias.RampSingleChannelOffset(evt.Get<uint16_t>(), evt.Get<float>(2), true);
    16251654
    16261655        return T::GetCurrentState();
    16271656    }
    16281657
    1629     int DecGlobalVolt(const EventImp &evt)
    1630     {
    1631         if (!CheckEventSize(evt.GetSize(), "DecGlobalVolt", 4))
    1632             return false;
    1633 
    1634         fBias.GlobalAddVolt(-evt.GetFloat());
     1658    // INCREASE_ALL_CHANNELS_VOLTAGES
     1659    int IncAllChannelsVolt(const EventImp &evt)
     1660    {
     1661        if (!CheckEventSize(evt.GetSize(), "IncAllChannelsVolt", 4*kNumChannels))
     1662            return false;
     1663
     1664        const float *ptr = evt.Ptr<float>();
     1665        fBias.RampAllChannelsOffset(vector<float>(ptr, ptr+416), true);
    16351666
    16361667        return T::GetCurrentState();
    16371668    }
    16381669
    1639     int DecGlobalDac(const EventImp &evt)
    1640     {
    1641         if (!CheckEventSize(evt.GetSize(), "DecGlobalDac", 2))
    1642             return false;
    1643 
    1644         fBias.GlobalAddDac(-evt.GetShort());
    1645 
    1646         return T::GetCurrentState();
    1647     }
    1648 
    1649     int SetChannelVolt(const EventImp &evt)
    1650     {
    1651         if (!CheckEventSize(evt.GetSize(), "SetChannelVolt", 6))
    1652             return false;
    1653 
    1654         fBias.ChannelSetVolt(evt.GetUShort(), evt.Get<float>(2));
    1655 
    1656         return T::GetCurrentState();
    1657     }
    1658 
    1659     int SetChannelDac(const EventImp &evt)
    1660     {
    1661         if (!CheckEventSize(evt.GetSize(), "SetChannelDac", 4))
    1662             return false;
    1663 
    1664         fBias.ChannelSetDac(evt.Get<uint16_t>(), evt.Get<uint16_t>(2));
    1665 
    1666         return T::GetCurrentState();
    1667     }
    1668 
    1669     int SetGapdReferenceCh(const EventImp &evt)
    1670     {
    1671         if (!CheckEventSize(evt.GetSize(), "SetGapdReferenceCh", 2))
    1672             return false;
    1673 
    1674         fBias.SetGapdReferenceCh(evt.GetUShort());
    1675 
    1676         return T::GetCurrentState();
    1677     }
    1678 
    1679 
    16801670    // --------------------------------------------------------------------
    16811671
    1682     int AddReferenceDac(const EventImp &evt)
    1683     {
    1684         if (!CheckEventSize(evt.GetSize(), "AddReferenceDac", 2*kNumChannels))
    1685             return false;
    1686 
    1687         const int16_t *ptr = evt.Ptr<int16_t>();
    1688         fBias.AddDac(vector<int16_t>(ptr, ptr+416));
    1689 
    1690         return T::GetCurrentState();
    1691     }
    1692 
    1693     int AddReferenceVolt(const EventImp &evt)
    1694     {
    1695         if (!CheckEventSize(evt.GetSize(), "AddReferenceVolt", 4*kNumChannels))
    1696             return false;
    1697 
    1698         const float_t *ptr = evt.Ptr<float>();
    1699         fBias.AddVolt(vector<float>(ptr, ptr+416));
    1700 
    1701         return T::GetCurrentState();
    1702     }
    1703 
    1704     int SetReferenceDac(const EventImp &evt)
    1705     {
    1706         if (!CheckEventSize(evt.GetSize(), "SetReferenceDac", 2*kNumChannels))
    1707             return false;
    1708 
    1709         const int16_t *ptr = evt.Ptr<int16_t>();
    1710         fBias.SetDac(vector<int16_t>(ptr, ptr+416));
    1711 
    1712         return T::GetCurrentState();
    1713     }
    1714 
    1715     int SetReferenceVolt(const EventImp &evt)
    1716     {
    1717         if (!CheckEventSize(evt.GetSize(), "SetReferenceVolt", 4*kNumChannels))
    1718             return false;
    1719 
    1720         const float_t *ptr = evt.Ptr<float>();
    1721         fBias.SetVolt(vector<float>(ptr, ptr+416));
     1672    // SET_CHANNEL_OFFSET_TO_ZERO
     1673    int SetChannelOffsetToZero(const EventImp &evt)
     1674    {
     1675        if (!CheckEventSize(evt.GetSize(), "SetChannelOffsetToZero", 2))
     1676            return false;
     1677
     1678        fBias.RampSingleChannelOffset(evt.GetUShort(), 0, false);
    17221679
    17231680        return T::GetCurrentState();
     
    18161773
    18171774        fBias.SetVerbose(evt.GetBool());
     1775
     1776        return T::GetCurrentState();
     1777    }
     1778
     1779    int SetDummyMode(const EventImp &evt)
     1780    {
     1781        if (!CheckEventSize(evt.GetSize(), "SetDummyMode", 1))
     1782            return T::kSM_FatalError;
     1783
     1784        fBias.SetDummyMode(evt.GetBool());
    18181785
    18191786        return T::GetCurrentState();
     
    18901857
    18911858        // Verbosity commands
    1892         T::AddEvent("SET_VERBOSE", "B")
     1859        T::AddEvent("SET_VERBOSE", "B:1")
    18931860            (bind(&StateMachineBias::SetVerbosity, this, placeholders::_1))
    18941861            ("set verbosity state"
    18951862             "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
     1863
     1864        T::AddEvent("ENABLE_DUMMY_MODE", "B:1")
     1865            (bind(&StateMachineBias::SetDummyMode, this, placeholders::_1))
     1866            ("Enable dummy mode. In this mode SetAllChannels prints informations instead of sending anything to the bias crate."
     1867             "|enable[bool]:disable or enable dummy mode");
    18961868
    18971869        // Conenction commands
     
    18991871            (bind(&StateMachineBias::Disconnect, this))
    19001872            ("disconnect from USB");
    1901 
    19021873        T::AddEvent("RECONNECT", "O", kDisconnected, kConnected, kVoltageOff)
    19031874            (bind(&StateMachineBias::Reconnect, this, placeholders::_1))
     
    19221893
    19231894
    1924 
     1895        T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1896            (bind(&StateMachineBias::SetChannelDac, this, placeholders::_1))
     1897            ("Set a new target value in DAC counts for a single channel. Starts ramping if necessary."
     1898             "|channel[short]:Channel for which to set the target voltage [0-415]"
     1899             "|voltage[dac]:Target voltage in DAC units for the given channel");
     1900        T::AddEvent("SET_GLOBAL_DAC", "S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1901            (bind(&StateMachineBias::SetGlobalDac, this, placeholders::_1))
     1902            ("Set a new target value for all channels in DAC counts. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
     1903             "|voltage[dac]:Global target voltage in DAC counts.");
     1904
     1905
     1906        T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1907            (bind(&StateMachineBias::SetChannelVolt, this, placeholders::_1))
     1908            ("Set a new target voltage for a single channel. Starts ramping if necessary."
     1909             "|channel[short]:Channel for which to set the target voltage [0-415]"
     1910             "|voltage[V]:Target voltage in volts for the given channel (will be converted to DAC units)");
    19251911        T::AddEvent("SET_GLOBAL_VOLTAGE", "F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    19261912            (bind(&StateMachineBias::SetGlobalVolt, this, placeholders::_1))
    1927             ("Set all channels to a new reference voltage. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
     1913            ("Set a new target voltage for all channels. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
    19281914             "|voltage[V]:Global target voltage in volts (will be converted to DAC units)");
    1929 
    1930         T::AddEvent("SET_GLOBAL_DAC", "S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1931             (bind(&StateMachineBias::SetGlobalDac, this, placeholders::_1))
    1932             ("Set all channels to a new DAC reference. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
    1933              "|voltage[dac]:Global target voltage as DAC counts.");
    1934 
     1915        T::AddEvent("SET_ALL_CHANNELS_VOLTAGE", "F:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1916            (bind(&StateMachineBias::SetAllChannelsVolt, this, placeholders::_1))
     1917            ("Set all channels to the given new reference voltage. Starts ramping if necessary."
     1918             "voltage[V]:New reference voltage for all channels");
     1919
     1920
     1921        T::AddEvent("INCREASE_CHANNEL_VOLTAGE", "S:1;F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1922            (bind(&StateMachineBias::IncChannelVolt, this, placeholders::_1))
     1923            ("Increases the voltage of all channels by the given offset. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
     1924             "|channel[short]:Channel for which to adapt the voltage [0-415]"
     1925             "|offset[V]:Offset to be added to all channels (will be converted to DAC counts)");
    19351926        T::AddEvent("INCREASE_GLOBAL_VOLTAGE", "F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    19361927            (bind(&StateMachineBias::IncGlobalVolt, this, placeholders::_1))
    1937             ("Set all channels to a new reference voltage. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
     1928            ("Increases the voltage of all channels by the given offset. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
    19381929             "|offset[V]:Offset to be added to all channels (will be converted to DAC counts)");
    1939 
    1940         T::AddEvent("INCREASE_GLOBAL_DAC", "S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1941             (bind(&StateMachineBias::IncGlobalDac, this, placeholders::_1))
    1942             ("Set all channels to a new DAC reference. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
    1943              "|offset[dac]:Offset to be added to all channels as DAC counts");
    1944 
    1945         T::AddEvent("DECREASE_GLOBAL_VOLTAGE", "F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1946             (bind(&StateMachineBias::DecGlobalVolt, this, placeholders::_1))
    1947             ("Set all channels to a new reference voltage. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
    1948              "|offset[V]:Offset to be subtracted from all channels (will be converted to DAC counts)");
    1949 
    1950         T::AddEvent("DECREASE_GLOBAL_DAC", "S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1951             (bind(&StateMachineBias::DecGlobalDac, this, placeholders::_1))
    1952             ("Set all channels to a new DAC reference. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
    1953              "|offset[dac]:Offset to be subtracted from all channels as DAC counts");
    1954 
    1955         T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1956             (bind(&StateMachineBias::SetChannelVolt, this, placeholders::_1))
    1957             ("Set a single channel to a new reference voltage. Starts ramping if necessary."
    1958              "|channel[short]:Channel for which to set the target voltage [0-416]"
    1959              "|voltage[V]:Target voltage in volts for the given channel (will be converted to DAC units)");
    1960 
    1961         T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1962             (bind(&StateMachineBias::SetChannelDac, this, placeholders::_1))
    1963             ("Set a single channel to a new DAC reference value. Starts ramping if necessary."
    1964              "|channel[short]:Channel for which to set the target voltage [0-416]"
    1965              "|voltage[dac]:Target voltage in DAC units for the given channel");
    1966 
    1967         T::AddEvent("SET_GLOBAL_GAPD_REFERENCE_VOLTAGE", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1968             (Wrapper(bind(&ConnectionBias::SetGapdVoltage, &fBias, 0.)))
     1930        T::AddEvent("INCREASE_ALL_CHANNELS_VOLTAGE", "F:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1931            (bind(&StateMachineBias::IncAllChannelsVolt, this, placeholders::_1))
     1932            ("Add the given voltages to the current reference voltages. Starts ramping if necessary."
     1933             "offset[V]:Offsets to be added to the reference voltage of all channels in volts");
     1934
     1935
     1936        // SET_SINGLE_CHANNEL_OFFSET
     1937        T::AddEvent("SET_CHANNEL_OFFSET", "S:1;F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1938            (bind(&StateMachineBias::SetChannelOffset, this, placeholders::_1))
     1939            ("Set single channels to its G-APD breakdown voltage plus overvoltage plus the given offset. Starts ramping if necessary."
     1940             "|channel[short]:Channel for which to set the target voltage [0-415]"
     1941             "|offset[V]:Offset to be added to the G-APD reference voltage of the given channel");
     1942        T::AddEvent("SET_GLOBAL_OFFSET", "F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1943            (bind(&StateMachineBias::SetGlobalOffset, this, placeholders::_1))
     1944            ("Set all channels to their G-APD breakdown voltage plus overvoltage plus the given offset. Starts ramping if necessary."
     1945             "|offset[V]:Offset to be added to the G-APD reference voltage globally");
     1946        T::AddEvent("SET_ALL_CHANNELS_OFFSET", "F:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1947            (bind(&StateMachineBias::SetAllChannelsOffset, this, placeholders::_1))
     1948            ("Set all channels to their G-APD reference voltage plus the given offset. Starts ramping if necessary."
     1949             "|offset[V]:Offset to be added to teh G-APD reference voltage globally");
     1950
     1951
     1952        T::AddEvent("SET_GLOBAL_OFFSET_TO_ZERO", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1953            (Wrapper(bind(&ConnectionBias::RampAllOffsets, &fBias, 0., false)))
    19691954            ("Set all channels to their G-APD reference voltage. Starts ramping if necessary.");
    19701955
    1971         T::AddEvent("SET_CHANNEL_GAPD_REFERENCE_VOLTAGE", "S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1972             (bind(&StateMachineBias::SetGapdReferenceCh, this, placeholders::_1))
     1956        T::AddEvent("SET_CHANNEL_OFFSET_TO_ZERO", "S:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
     1957            (bind(&StateMachineBias::SetChannelOffsetToZero, this, placeholders::_1))
    19731958            ("Set a single channel channels to its G-APD reference voltage. Starts ramping if necessary."
    19741959             "|channel[short]:Channel for which to set the target voltage [0-416]");
    19751960
    1976         T::AddEvent("SET_GAPD_REFERENCE_OFFSET", "F:1", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1977             (bind(&StateMachineBias::SetGapdVoltage, this, placeholders::_1))
    1978             ("Set all channels to their G-APD reference voltage plus the given offset. Starts ramping if necessary."
    1979              "|offset[V]:Offset to be added to teh G-APD reference voltage globally");
    1980 
    1981         T::AddEvent("SET_ALL_CHANNELS_OFFSET", "F:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1982             (bind(&StateMachineBias::SetGapdVoltages, this, placeholders::_1))
    1983             ("Set all channels to their G-APD reference voltage plus the given offset. Starts ramping if necessary."
    1984              "|offset[V]:Offset to be added to teh G-APD reference voltage");
     1961
    19851962
    19861963        T::AddEvent("SET_ZERO_VOLTAGE", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1987             (Wrapper(bind(&ConnectionBias::SetZero, &fBias)))
     1964            (Wrapper(bind(&ConnectionBias::RampAllDacs, &fBias, 0)))
    19881965            ("Set all channels to a zero reference voltage. Starts ramping if necessary.");
    19891966
    1990         T::AddEvent("SET_REFERENCE_VOLTAGES", "F:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1991             (bind(&StateMachineBias::SetReferenceVolt, this, placeholders::_1))
    1992             ("Set all channels to the given new reference voltage. Starts ramping if necessary."
    1993              "voltage[V]:New reference voltage for all channels");
    1994 
    1995         T::AddEvent("SET_REFERENCE_DACS", "S:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    1996             (bind(&StateMachineBias::SetReferenceDac, this, placeholders::_1))
    1997             ("Set all channels to the given new reference voltage. Starts ramping if necessary."
    1998              "voltage[dac]:New reference voltage for all channels in DAC units");
    1999 
    2000         T::AddEvent("ADD_REFERENCE_VOLTAGES", "F:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    2001             (bind(&StateMachineBias::AddReferenceVolt, this, placeholders::_1))
    2002             ("Add the given voltages to the current reference voltages. Starts ramping if necessary."
    2003              "offset[V]:Offsets to be added to the reference voltage of all channels in volts");
    2004 
    2005         T::AddEvent("ADD_REFERENCE_DACS", "S:416", kConnected, kVoltageOff, kVoltageOn, kNotReferenced, kOverCurrent)
    2006             (bind(&StateMachineBias::AddReferenceDac, this, placeholders::_1))
    2007             ("Add the given voltages to the current reference voltages. Starts ramping if necessary."
    2008              "offset[dac]:Offsets to be added to the reference voltage of all channels in DAC units");
    20091967
    20101968
     
    20311989            ("Print a table with all voltages (current and reference voltages as currently in memory)");
    20321990        T::AddEvent("PRINT_GAPD_REFERENCE_VOLTAGES")
    2033             (Wrapper(bind(&ConnectionBias::PrintGapd, &fBias)))
    2034             ("Print the G-APD reference values obtained from file");
     1991            (Wrapper(bind(&ConnectionBias::PrintReferenceVoltage, &fBias)))
     1992            ("Print the G-APD reference values (breakdown voltage + overvoltage) obtained from file");
    20351993
    20361994
     
    20682026
    20692027        fBias.SetVerbose(!conf.Get<bool>("quiet"));
     2028        fBias.SetDummyMode(conf.Get<bool>("dummy-mode"));
    20702029
    20712030        if (conf.Has("dev"))
     
    21472106        }
    21482107
    2149         if (!fBias.SetNewGapdVoltage(map.Vgapd()))
     2108        if (!fBias.SetReferences(map.Vgapd(), map.Voffset()))
    21502109        {
    21512110            T::Error("Setting reference voltages failed.");
     
    21792138        ("dev",             var<string>(),       "Device address of USB port to bias-power supply")
    21802139        ("quiet,q",         po_bool(),           "Disable printing contents of all received messages (except dynamic data) in clear text.")
     2140        ("dummy-mode",      po_bool(),           "Dummy mode - SetAllChannels prints info instead of sending new values.")
    21812141        ("ramp-delay",      var<uint16_t>(15),   "Delay between the answer of one ramping step and sending the next ramp command to all channels in milliseconds.")
    21822142        ("ramp-step",       var<uint16_t>(46),   "Maximum step in DAC counts during ramping (Volt = DAC*90/4096)")
Note: See TracChangeset for help on using the changeset viewer.