Changeset 12663
- Timestamp:
- 11/28/11 16:13:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/biasctrl.cc
r12507 r12663 42 42 bool fIsVerbose; 43 43 44 vector<uint16_t> f VoltCmd; // Current command voltage in DAC units (12bit = 90V)44 vector<uint16_t> fDacCmd; // Current command voltage in DAC units (12bit = 90V) 45 45 46 46 vector<bool> fPresent; … … 49 49 int64_t fSendCounter; 50 50 51 int16_t fGlobal VoltCmd; // Command value to be reached51 int16_t fGlobalDacCmd; // Command value to be reached 52 52 // uint16_t fExpertVoltRef; // Command value to be reached 53 53 … … 65 65 66 66 protected: 67 vector<uint16_t> f Volt; // Current voltage in DAC units (12bit = 90V)68 vector<uint16_t> f VoltRef; // Current reference voltage in DAC units (12bit = 90V)69 vector<uint16_t> f VoltGapd; // Nominal G-APD voltages at 25deg C67 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 70 70 71 71 vector<int16_t> fCurrent; // Current in ADC units (12bit = 5mA) 72 72 73 uint16_t f VoltMaxAbs;74 uint16_t f VoltMaxRel;73 uint16_t fDacMaxAbs; 74 uint16_t fDacMaxRel; 75 75 76 76 virtual void UpdateA() … … 105 105 return false; 106 106 } 107 if (dac>f VoltMaxAbs)108 { 109 str << "DAC value " << dac << " exceeds allowed absolute maximum of " << f VoltMaxAbs;107 if (dac>fDacMaxAbs) 108 { 109 str << "DAC value " << dac << " exceeds allowed absolute maximum of " << fDacMaxAbs; 110 110 Error(str); 111 111 return false; 112 112 } 113 if (dac>f VoltGapd[ch]+fVoltMaxRel)114 { 115 str << "DAC value " << dac << " exceeds allowed channel maximum of " << f VoltGapd[ch] << " + " << fVoltMaxRel;113 if (dac>fDacGapd[ch]+fDacMaxRel) 114 { 115 str << "DAC value " << dac << " exceeds allowed channel maximum of " << fDacGapd[ch] << " + " << fDacMaxRel; 116 116 Error(str); 117 117 return false; … … 251 251 { 252 252 for (int i=0; i<kNumChannels; i++) 253 f Volt[i] = fGlobalVoltCmd;254 255 fGlobal VoltCmd = -1;253 fDac[i] = fGlobalDacCmd; 254 255 fGlobalDacCmd = -1; 256 256 257 257 return true; … … 293 293 294 294 if (cmd==kCmdChannelSet) 295 f Volt[id] = fVoltCmd[id];295 fDac[id] = fDacCmd[id]; 296 296 297 297 return true; … … 584 584 if (fWrapCounter<0) 585 585 { 586 f Volt.assign( kNumChannels, 0);587 f VoltRef.assign(kNumChannels, 0);588 f VoltCmd.assign(kNumChannels, 0);586 fDac.assign( kNumChannels, 0); 587 fDacRef.assign(kNumChannels, 0); 588 fDacCmd.assign(kNumChannels, 0); 589 589 } 590 590 … … 592 592 fSendCounter = -1; 593 593 fWrapCounter = -1; 594 fGlobal VoltCmd= -1;594 fGlobalDacCmd = -1; 595 595 fIsInitializing = true; 596 596 fIsRamping = false; … … 658 658 data.insert(data.end(), cmd.begin(), cmd.end()); 659 659 660 f VoltCmd[ch] = dac[ch];660 fDacCmd[ch] = dac[ch]; 661 661 } 662 662 … … 673 673 uint16_t RampOneStep(uint16_t ch) 674 674 { 675 if (f VoltRef[ch]>fVolt[ch])676 return f Volt[ch]+fRampStep>fVoltRef[ch] ? fVoltRef[ch] : fVolt[ch]+fRampStep;677 678 if (f VoltRef[ch]<fVolt[ch])679 return f Volt[ch]-fRampStep<fVoltRef[ch] ? fVoltRef[ch] : fVolt[ch]-fRampStep;680 681 return f Volt[ch];675 if (fDacRef[ch]>fDac[ch]) 676 return fDac[ch]+fRampStep>fDacRef[ch] ? fDacRef[ch] : fDac[ch]+fRampStep; 677 678 if (fDacRef[ch]<fDac[ch]) 679 return fDac[ch]-fRampStep<fDacRef[ch] ? fDacRef[ch] : fDac[ch]-fRampStep; 680 681 return fDac[ch]; 682 682 } 683 683 … … 701 701 { 702 702 dac[ch] = RampOneStep(ch); 703 if (dac[ch]!=f Volt[ch] && fPresent[ch/kNumChannelsPerBoard])703 if (dac[ch]!=fDac[ch] && fPresent[ch/kNumChannelsPerBoard]) 704 704 identical = false; 705 705 } … … 769 769 fBufferUpdate(3*kNumChannels), 770 770 fIsVerbose(false), 771 fVoltCmd(kNumChannels), 772 //fRefCurrent(kNumChannels), 771 fDacCmd(kNumChannels), 773 772 fPresent(kNumBoards), 774 773 fWrapCounter(-1), … … 780 779 fWaitingForAnswer(-1), 781 780 fCounter(8), 782 f Volt(kNumChannels),783 f VoltRef(kNumChannels),784 f VoltGapd(kNumChannels),781 fDac(kNumChannels), 782 fDacRef(kNumChannels), 783 fDacGapd(kNumChannels), 785 784 fCurrent(kNumChannels) 786 785 { … … 807 806 808 807 for (int ch=0; ch<kNumChannels; ch++) 809 dac[ch] = fCurrent[ch]<0 ? 0 : f Volt[ch];808 dac[ch] = fCurrent[ch]<0 ? 0 : fDac[ch]; 810 809 811 810 SetAllChannels(dac, true); … … 848 847 return false; 849 848 850 f VoltRef[ch] = dac;849 fDacRef[ch] = dac; 851 850 852 851 if (!fIsRamping) … … 904 903 for (size_t ch=0; ch<kNumChannels; ch++) 905 904 { 906 if (f VoltRef[ch]+dac[ch]>kMaxDac)905 if (fDacRef[ch]+dac[ch]>kMaxDac) 907 906 { 908 907 ostringstream msg; 909 msg << "AddDac - New voltage reference " << f VoltRef[ch] << "+" << dac[ch] << " out of range [0," << kMaxDac << " for channel " << ch << ".";908 msg << "AddDac - New voltage reference " << fDacRef[ch] << "+" << dac[ch] << " out of range [0," << kMaxDac << " for channel " << ch << "."; 910 909 Error(msg); 911 910 return false; 912 911 } 913 912 914 if (f VoltRef[ch]+dac[ch]<0)915 f VoltRef[ch] = 0;913 if (fDacRef[ch]+dac[ch]<0) 914 fDacRef[ch] = 0; 916 915 else 917 f VoltRef[ch] += dac[ch];916 fDacRef[ch] += dac[ch]; 918 917 } 919 918 … … 966 965 return false; 967 966 968 f VoltRef[ch] = dac[ch];967 fDacRef[ch] = dac[ch]; 969 968 } 970 969 … … 1020 1019 1021 1020 for (size_t ch=0; ch<kNumChannels; ch++) 1022 if (f VoltGapd[ch]+dac>kMaxDac)1021 if (fDacGapd[ch]+dac>kMaxDac) 1023 1022 { 1024 1023 ostringstream msg; 1025 msg << "SetGapdVoltage - New voltage reference " << f VoltGapd[ch] << "+" << dac << " out of range [0," << kMaxDac << " for channel " << ch << ".";1024 msg << "SetGapdVoltage - New voltage reference " << fDacGapd[ch] << "+" << dac << " out of range [0," << kMaxDac << " for channel " << ch << "."; 1026 1025 Error(msg); 1027 1026 return false; … … 1029 1028 1030 1029 for (size_t ch=0; ch<kNumChannels; ch++) 1031 f VoltRef[ch] = fVoltGapd[ch]+dac<0 ? 0 : fVoltGapd[ch]+dac;1030 fDacRef[ch] = fDacGapd[ch]+dac<0 ? 0 : fDacGapd[ch]+dac; 1032 1031 1033 1032 if (!fIsRamping) … … 1039 1038 bool SetGapdReferenceCh(uint16_t ch) 1040 1039 { 1041 if (!CheckChDac("SetGapdReferenceCh", f VoltGapd[ch], ch))1042 return false; 1043 1044 f VoltRef[ch] = fVoltGapd[ch];1040 if (!CheckChDac("SetGapdReferenceCh", fDacGapd[ch], ch)) 1041 return false; 1042 1043 fDacRef[ch] = fDacGapd[ch]; 1045 1044 1046 1045 if (!fIsRamping) … … 1054 1053 { 1055 1054 for (size_t ch=0; ch<kNumChannels; ch++) 1056 f VoltRef[ch] = 0;1055 fDacRef[ch] = 0; 1057 1056 1058 1057 if (!fIsRamping) … … 1071 1070 1072 1071 for (size_t i=0; i<kNumChannels; i++) 1073 f VoltGapd[i] = volt[i]*4096/90;1072 fDacGapd[i] = volt[i]*4096/90; 1074 1073 1075 1074 UpdateVgapd(); … … 1150 1149 return false; 1151 1150 1152 f VoltCmd[ch] = dac;1151 fDacCmd[ch] = dac; 1153 1152 1154 1153 ostringstream msg; … … 1182 1181 return false; 1183 1182 1184 if (fGlobal VoltCmd>=0)1183 if (fGlobalDacCmd>=0) 1185 1184 { 1186 1185 Error("ExpertGlobalSetDac - Still waiting for previous answer to 'GlobalSet'"); … … 1188 1187 } 1189 1188 1190 fGlobal VoltCmd = dac;1189 fGlobalDacCmd = dac; 1191 1190 1192 1191 ostringstream msg; … … 1271 1270 const int id = c+kNumChannelsPerBoard*b; 1272 1271 Out() << " "; 1273 Out() << (f Volt[id]==fVoltRef[id]?kGreen:kRed);1274 Out() << setw(5) << f Volt[id]*90/4096. << '/';1275 Out() << setw(5) << f VoltRef[id]*90/4096.;1272 Out() << (fDac[id]==fDacRef[id]?kGreen:kRed); 1273 Out() << setw(5) << fDac[id]*90/4096. << '/'; 1274 Out() << setw(5) << fDacRef[id]*90/4096.; 1276 1275 } 1277 1276 Out() << endl; … … 1307 1306 { 1308 1307 const int id = c+kNumChannelsPerBoard*b; 1309 Out() << " " << setw(5) << f VoltGapd[id]*90/4096.;1308 Out() << " " << setw(5) << fDacGapd[id]*90/4096.; 1310 1309 } 1311 1310 Out() << endl; … … 1352 1351 void SetVoltMaxAbs(float max) 1353 1352 { 1354 f VoltMaxAbs = max*4096/90;1355 if (f VoltMaxAbs>4095)1356 f VoltMaxAbs = 4095;1353 fDacMaxAbs = max*4096/90; 1354 if (fDacMaxAbs>4095) 1355 fDacMaxAbs = 4095; 1357 1356 if (max<0) 1358 f VoltMaxAbs = 0;1357 fDacMaxAbs = 0; 1359 1358 } 1360 1359 1361 1360 void SetVoltMaxRel(float max) 1362 1361 { 1363 f VoltMaxRel = max*4096/90;1364 if (f VoltMaxRel>4095)1365 f VoltMaxRel = 4095;1362 fDacMaxRel = max*4096/90; 1363 if (fDacMaxRel>4095) 1364 fDacMaxRel = 4095; 1366 1365 if (max<0) 1367 f VoltMaxRel = 0;1366 fDacMaxRel = 0; 1368 1367 } 1369 1368 1370 1369 uint16_t GetVoltMaxAbs() const 1371 1370 { 1372 return f VoltMaxAbs * 90./4096;1371 return fDacMaxAbs * 90./4096; 1373 1372 } 1374 1373 1375 1374 uint16_t GetVoltMaxRel() const 1376 1375 { 1377 return f VoltMaxRel * 90./4096;1376 return fDacMaxRel * 90./4096; 1378 1377 } 1379 1378 … … 1427 1426 bool isoff = true; 1428 1427 for (int ch=0; ch<kNumChannels; ch++) 1429 if (fPresent[ch/kNumChannelsPerBoard] && f Volt[ch]!=0)1428 if (fPresent[ch/kNumChannelsPerBoard] && fDac[ch]!=0) 1430 1429 isoff = false; 1431 1430 if (isoff) … … 1433 1432 1434 1433 for (int ch=0; ch<kNumChannels; ch++) 1435 if (fPresent[ch/kNumChannelsPerBoard] && f Volt[ch]!=fVoltRef[ch])1434 if (fPresent[ch/kNumChannelsPerBoard] && fDac[ch]!=fDacRef[ch]) 1436 1435 return BIAS::kNotReferenced; 1437 1436 … … 1460 1459 { 1461 1460 vector<uint16_t> vec; 1462 vec.insert(vec.end(), f Volt.begin(), fVolt.end());1463 vec.insert(vec.end(), f VoltRef.begin(), fVoltRef.end());1461 vec.insert(vec.end(), fDac.begin(), fDac.end()); 1462 vec.insert(vec.end(), fDacRef.begin(), fDacRef.end()); 1464 1463 fDimVoltage.Update(vec); 1465 1464 } … … 1467 1466 void UpdateVgapd() 1468 1467 { 1469 fDimGapd.Update(f VoltGapd);1468 fDimGapd.Update(fDacGapd); 1470 1469 } 1471 1470 … … 2059 2058 2060 2059 BiasMap map; 2061 if (!map.Read(conf.Get<string>("bias-map-file"))) 2062 { 2063 T::Error("Reading reference voltages from "+conf.Get<string>("bias-map-file")+" failed."); 2060 2061 if (!conf.Has("bias-map-file") && !conf.Has("bias-database")) 2062 { 2063 T::Error("Neither bias-map-file not bias-dtabase specified."); 2064 2064 return 5; 2065 2065 } 2066 2066 2067 try 2068 { 2069 if (conf.Has("bias-map-file")) 2070 map.Read(conf.Get<string>("bias-map-file")); 2071 2072 if (conf.Has("bias-database")) 2073 map.Retrieve(conf.Get<string>("bias-database")); 2074 } 2075 catch (const runtime_error &e) 2076 { 2077 T::Error("Getting reference voltages failed: "+string(e.what())); 2078 return 7; 2079 } 2080 2067 2081 if (!fBias.SetNewGapdVoltage(map.Vgapd())) 2068 2082 { 2069 2083 T::Error("Setting reference voltages failed."); 2070 return 6;2084 return 8; 2071 2085 } 2072 2086 … … 2103 2117 ("volt-max-rel", var<float>(2.5), "Relative upper limit for the voltage w.r.t. the G-APD reference voltage (in Volts)") 2104 2118 ("bias-map-file", var<string>("GAPDmap.txt"), "File with nominal and offset voltages for each channel.") 2119 ("bias-database", var<string>(""), "") 2105 2120 ; 2106 2121
Note:
See TracChangeset
for help on using the changeset viewer.