Changeset 17024 for trunk/FACT++/src/biasctrl.cc
- Timestamp:
- 08/19/13 16:33:21 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/biasctrl.cc
r16965 r17024 69 69 vector<int16_t> fCurrent; // Current in ADC units (12bit = 5mA) 70 70 71 virtual void Update AV()71 virtual void UpdateVA() 72 72 { 73 73 } … … 84 84 85 85 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 88 87 89 88 vector<float> fCalibrationOffset; // Bias crate channel offset … … 375 374 // Check if new values have been received 376 375 if (cmd==kCmdRead || cmd==kCmdChannelSet || cmd==kExpertChannelSet) 377 Update AV();376 UpdateVA(); 378 377 379 378 // ----- Take action depending on what is going on ----- … … 658 657 { 659 658 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]); 661 660 } 662 661 Out() << endl; … … 841 840 fCurrent(kNumChannels), 842 841 fBreakdownVoltage(kNumChannels, 0), 843 fOvervoltage(kNumChannels), 844 fChannelOffset(kNumChannels), 842 //fChannelOffset(kNumChannels), 845 843 fCalibrationOffset(kNumChannels), 846 fCalibrationSlope(kNumChannels, 90 ./4096),844 fCalibrationSlope(kNumChannels, 90000), 847 845 fVoltageMaxAbs(75), 848 846 fVoltageMaxRel(2), … … 945 943 uint16_t ConvertVoltToDac(uint16_t ch, double volt) 946 944 { 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] 953 950 } 954 951 955 952 double ConvertDacToVolt(uint16_t ch, uint16_t dac) 956 953 { 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]; 958 959 } 959 960 … … 993 994 // -------------------------------------------------------------------- 994 995 996 /* 995 997 bool RampSingleChannelOffset(uint16_t ch, float offset, bool relative) 996 998 { … … 998 1000 return false; 999 1001 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; 1004 1006 1005 1007 if (!RampSingleChannelVoltage(ch, volt)) … … 1015 1017 vector<float> volt(kNumChannels); 1016 1018 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]; 1020 1022 1021 1023 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; 1023 1025 1024 1026 if (!RampAllChannelsVoltage(volt)) … … 1034 1036 return RampAllChannelsOffset(vector<float>(kNumChannels, offset), relative); 1035 1037 } 1038 */ 1036 1039 1037 1040 /* … … 1141 1144 fCalibrationOffset = offset; 1142 1145 fCalibrationSlope = slope; 1143 fOvervoltage.assign(kNumChannels, 0);1144 1146 1145 1147 UpdateVgapd(); … … 1347 1349 Out() << " "; 1348 1350 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]); 1351 1356 } 1352 1357 Out() << endl; … … 1382 1387 { 1383 1388 const int id = c+kNumChannelsPerBoard*b; 1384 Out() << " " << setw(5) << fBreakdownVoltage[id] +fOvervoltage[id];1389 Out() << " " << setw(5) << fBreakdownVoltage[id]; 1385 1390 } 1386 1391 Out() << endl; … … 1506 1511 DimDescribedService fDimGapd; 1507 1512 1508 void Update AV()1513 void UpdateVA() 1509 1514 { 1510 1515 const Time now; 1516 1517 UpdateV(now); 1518 1511 1519 fDimCurrent.setTime(now); 1512 1520 fDimCurrent.Update(fCurrent); 1513 1514 UpdateV(now);1515 1521 } 1516 1522 … … 1539 1545 volt.reserve(3*kNumChannels); 1540 1546 volt.insert(volt.end(), fBreakdownVoltage.begin(), fBreakdownVoltage.end()); 1541 volt.insert(volt.end(), fOvervoltage.begin(), fOvervoltage.end());1542 1547 volt.insert(volt.end(), fCalibrationOffset.begin(), fCalibrationOffset.end()); 1543 1548 volt.insert(volt.end(), fCalibrationSlope.begin(), fCalibrationSlope.end()); … … 1557 1562 fDimGapd("BIAS_CONTROL/NOMINAL", "F:416;F:416;F:416;F:416", 1558 1563 "|Ubr[V]:Nominal breakdown voltage at 25deg C" 1559 "|Uov[V]:Nominal overvoltage"1560 1564 "|Uoff[V]:Bias crate channel calibration offsets" 1561 "| Uslope[V/dac]:Bias crate channel calibration slope")1565 "|Rcal[Ohm]:Bias crate channel calibration slope") 1562 1566 { 1563 1567 } … … 1660 1664 // -------------------------------------------------------------------- 1661 1665 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 1699 1667 int IncGlobalVolt(const EventImp &evt) 1700 1668 { … … 1729 1697 return T::GetCurrentState(); 1730 1698 } 1731 1699 */ 1732 1700 // -------------------------------------------------------------------- 1733 1701 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()); 1741 1708 1742 1709 return T::GetCurrentState(); 1743 1710 } 1744 1711 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()); 1753 1718 1754 1719 return T::GetCurrentState(); 1755 1720 } 1756 1721 1757 int ExpertSet GlobalDac(const EventImp &evt)1758 { 1759 if (!CheckEventSize(evt.GetSize(), "ExpertSet GlobalDac", 2))1760 return false; 1761 1762 fBias.Expert GlobalSetDac(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)); 1763 1728 1764 1729 return T::GetCurrentState(); 1765 1730 } 1766 1731 1767 int ExpertSetChannel Volt(const EventImp &evt)1768 { 1769 if (!CheckEventSize(evt.GetSize(), "ExpertSetChannel Volt", 6))1770 return false; 1771 1772 fBias.ExpertChannelSet Volt(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)); 1773 1738 1774 1739 return T::GetCurrentState(); 1775 1740 } 1776 1741 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 } 1783 1773 1784 1774 return T::GetCurrentState(); … … 1964 1954 (bind(&StateMachineBias::SetAllChannelsVolt, this, placeholders::_1)) 1965 1955 ("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 /* 1969 1959 T::AddEvent("INCREASE_CHANNEL_VOLTAGE", "S:1;F:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent) 1970 1960 (bind(&StateMachineBias::IncChannelVolt, this, placeholders::_1)) … … 1980 1970 ("Add the given voltages to the current reference voltages. Starts ramping if necessary." 1981 1971 "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 */ 2008 1973 2009 1974 … … 2064 2029 (bind(&StateMachineBias::ExpertSetChannelDac, this, placeholders::_1)) 2065 2030 ("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."); 2066 2035 } 2067 2036 … … 2192 2161 ("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") 2193 2162 ("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)") 2195 2164 ("bias-map-file", var<string>(), "File with nominal and offset voltages for each channel.") 2196 2165 ("bias-database", var<string>(), "")
Note:
See TracChangeset
for help on using the changeset viewer.