PMGasVerificationRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. using System.Collections.Generic;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.SCCore;
  5. using Venus_RT.Devices;
  6. using Venus_RT.Devices.IODevices;
  7. using Aitex.Core.RT.Log;
  8. using Venus_Core;
  9. using Aitex.Core.Util;
  10. using System;
  11. using MECF.Framework.Common.DBCore;
  12. using MECF.Framework.Common.Routine;
  13. using System.Collections.ObjectModel;
  14. namespace Venus_RT.Modules.PMs
  15. {
  16. class PMGasVerificationRoutine : PMRoutineBase, IRoutine
  17. {
  18. private enum GasStep
  19. {
  20. kPrepareValves,
  21. kPumpDown_1,
  22. kGasFlow,
  23. KDelay_2S,
  24. KGetBeginPressure,
  25. kDelay_1,
  26. kGasVerification,
  27. kStopGasFlow,
  28. kPumpDown_2,
  29. kEnd,
  30. }
  31. public enum VerifyMode
  32. {
  33. OnePoint,
  34. TenPoint,
  35. }
  36. private double _basePressure;
  37. private double _beginPressure;
  38. private double _endPressure;
  39. private double _elapsedTime;
  40. private DeviceTimer _verificationDeviceTimer = new DeviceTimer();
  41. private int _mfcIndex;
  42. private float _mfcFlow;
  43. private int _flowTime;
  44. private int _pumpingTime;
  45. private int _holdTime;
  46. private double _mfcActualFlow;
  47. private double _maxPressure;
  48. private MfcBase1 _mfcDevice;
  49. private VerifyMode _paramMode;
  50. private Dictionary<int, float> _paramFlowSet = new Dictionary<int, float>();
  51. private Dictionary<float, Tuple<float, float>> _calibrationResult = new Dictionary<float, Tuple<float, float>>();
  52. private float _pressureStableTolerance = 2;//2mTorr
  53. private float _flowStableTolerance = 0.02f;//2%
  54. private double _chamberVolume;
  55. private double _gasTemperature;
  56. private double _leakRate;
  57. private double _maxDeviation;
  58. private readonly PumpDownRoutine _pumpDownRoutine;
  59. public ObservableCollection<MFCCalibrationData> _MFCCalibrationDatas = new ObservableCollection<MFCCalibrationData>();
  60. //private bool _flag;//判断3分钟是否大于9torr
  61. public PMGasVerificationRoutine(JetPMBase chamber,PumpDownRoutine pdRoutine) : base(chamber)
  62. {
  63. Name = "Gas Verification";
  64. _pumpDownRoutine = pdRoutine;
  65. }
  66. internal void Init(string mfc, double flow, int flowCount)
  67. {
  68. int.TryParse(mfc.Replace("MFC", ""), out _mfcIndex);
  69. _mfcDevice = DEVICE.GetDevice<MfcBase1>($"{Module}.MfcGas{_mfcIndex}");
  70. _mfcIndex -= 1;//start from 0
  71. _mfcFlow = (float)flow;
  72. if (flowCount == 10)
  73. _paramMode = VerifyMode.TenPoint;
  74. else
  75. _paramMode = VerifyMode.OnePoint;
  76. }
  77. public RState Start(params object[] objs)
  78. {
  79. if (!CheckLid())
  80. {
  81. return RState.Failed;
  82. }
  83. if (!CheckSlitDoor())
  84. {
  85. return RState.Failed;
  86. }
  87. if (!CheckDryPump())
  88. {
  89. return RState.Failed;
  90. }
  91. if(!CheckTurboPump())
  92. {
  93. return RState.Failed;
  94. }
  95. _calibrationResult.Clear();
  96. _paramFlowSet.Clear();
  97. _MFCCalibrationDatas.Clear();
  98. _basePressure = SC.GetValue<double>($"{Module}.MFCVerification.BasePressure");
  99. _chamberVolume = SC.GetValue<double>($"{Module}.MFCVerification.ChamberVolume");
  100. _gasTemperature = SC.GetValue<double>($"{Module}.MFCVerification.GasTemperature");
  101. _pumpingTime = SC.GetValue<int>($"{Module}.MFCVerification.PumpingTime");
  102. _flowTime = SC.GetValue<int>($"{Module}.MFCVerification.GasFlowTime");
  103. _holdTime = SC.GetValue<int>($"{Module}.MFCVerification.HoldTime");
  104. _maxDeviation = SC.GetValue<double>($"{Module}.MFCVerification.MaxDeviation");
  105. _pressureStableTolerance = (float)SC.GetValue<double>($"{Module}.MFCVerification.PressureStableTolerance");
  106. _flowStableTolerance = (float)(SC.GetValue<double>($"{Module}.MFCVerification.FlowStableTolerance") / 100.0);
  107. _maxPressure = SC.GetValue<double>($"{Module}.MFCVerification.TargetPressure");
  108. if (_paramMode == VerifyMode.TenPoint)
  109. {
  110. for (int i = 0; i < 10; i++)
  111. {
  112. _paramFlowSet.Add(i, (float)_mfcDevice.Scale * (i + 1) / 10);
  113. }
  114. }
  115. else
  116. {
  117. if (_mfcFlow <= 0 || _mfcFlow > _mfcDevice.Scale)
  118. {
  119. LOG.Write(eEvent.ERR_ROUTINE_FAILED, Module, Name, $"MFC set value {_mfcFlow} not valid");
  120. return RState.Failed;
  121. }
  122. _paramFlowSet.Add(0, _mfcFlow);
  123. }
  124. _mfcDevice.ResetVerificationData();
  125. _leakRate = 0;
  126. var dbData = DataQuery.Query($"SELECT * FROM \"leak_check_data\" where \"module_name\" = '{Module}' order by \"operate_time\" DESC;");
  127. if (dbData != null && dbData.Rows.Count > 0 && !dbData.Rows[0]["leak_rate"].Equals(DBNull.Value))
  128. {
  129. _leakRate = Convert.ToDouble(dbData.Rows[0]["leak_rate"]);
  130. }
  131. Reset();
  132. return Runner.Start(Module, Name);
  133. }
  134. public RState Monitor()
  135. {
  136. Runner.Run(GasStep.kPrepareValves, PrepareValve, _delay_50ms)
  137. .LoopStart(GasStep.kPumpDown_1, $"{_mfcDevice.Name} Gas Verification", _paramFlowSet.Count, PumpingDown, WaitPumpDone)
  138. .LoopRun(GasStep.kGasFlow, FlowGas, CheckGasStable)
  139. .LoopDelay(GasStep.KDelay_2S, 2 * 1000)
  140. .LoopRun(GasStep.KGetBeginPressure, GetBeginPressure, JudgePressure, (_holdTime+10) * 1000)
  141. //.LoopDelay(GasStep.kDelay_1, _holdTime * 1000)
  142. .LoopRun(GasStep.kGasVerification, CalcMfcCalibration, _delay_2s)
  143. .LoopEnd(GasStep.kStopGasFlow, StopGasFlow, IsPumpDownOK)
  144. .End(GasStep.kEnd, NullFun, _delay_2s);
  145. return Runner.Status;
  146. }
  147. private bool JudgePressure()
  148. {
  149. if (_verificationDeviceTimer.GetElapseTime()<3*60*1000 && _chamber.ChamberPressure>9000)
  150. {
  151. return true;
  152. }
  153. if (_verificationDeviceTimer.GetElapseTime() >_holdTime*1000)
  154. {
  155. return true;
  156. }
  157. return false;
  158. }
  159. public void Abort()
  160. {
  161. _verificationDeviceTimer.Stop();
  162. _chamber.StopAllGases();
  163. _chamber.CloseValves();
  164. _mfcDevice.ResetVerificationData();
  165. }
  166. private bool PrepareValve()
  167. {
  168. _chamber.CloseValves();
  169. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  170. _chamber.OpenValve(ValveType.Guage, true);
  171. _chamber.OpenValve(ValveType.GasFinal, true);
  172. return true;
  173. }
  174. private bool PumpingDown()
  175. {
  176. _chamber.SetPVPostion(1000);
  177. return true;
  178. }
  179. private bool WaitPumpDone()
  180. {
  181. if(Runner.StepElapsedMS >= _pumpingTime * 1000)
  182. {
  183. if(_chamber.ProcessPressure <= _basePressure)
  184. {
  185. return true;
  186. }
  187. else
  188. {
  189. Runner.Stop($"MFC Gas Verification fail, Cannot pumping down to {_basePressure} mTorr in {_pumpingTime} seconds");
  190. return true;
  191. }
  192. }
  193. return false;
  194. }
  195. private void OpenPVNVlv(int mfcIndex, bool on)
  196. {
  197. ValveType[] vlvs = new ValveType[] { ValveType.PV11, ValveType.PV21, ValveType.PV31, ValveType.PV41 };
  198. if (_chamber.ChamberType == JetChamber.VenusSE|| _chamber.ChamberType == JetChamber.VenusDE)
  199. {
  200. vlvs = new ValveType[] { ValveType.PV11, ValveType.PV21, ValveType.PV31, ValveType.PV41,ValveType.PV51,ValveType.PV61,ValveType.PV71,ValveType.PV81, ValveType.PV91, ValveType.PVA1, ValveType.PVB1, ValveType.PVC1, };
  201. }
  202. // if (mfcIndex < 4)
  203. //{
  204. _chamber.OpenValve(vlvs[mfcIndex], on);
  205. //}
  206. }
  207. private bool FlowGas()
  208. {
  209. Notify($"Start {_mfcDevice.Name} gas flow");
  210. _verificationDeviceTimer.Start(0);
  211. _beginPressure = _chamber.ChamberPressure;
  212. OpenPVNVlv(_mfcIndex, true);
  213. if (!_chamber.FlowGas(_mfcIndex, _paramMode == VerifyMode.TenPoint ? _paramFlowSet[Runner.LoopCounter] : _mfcFlow))
  214. {
  215. return false;
  216. }
  217. return true;
  218. }
  219. private bool CheckGasStable()
  220. {
  221. if (_verificationDeviceTimer.GetElapseTime() > _flowTime * 1000)
  222. {
  223. //System.Threading.Thread.Sleep(1000);
  224. //if (!_chamber.SetPVPostion(0))
  225. if(!_chamber.TurnPendulumValve(false))
  226. Runner.Stop("Stop Pendulum Valve failed.");
  227. return true;
  228. }
  229. //if (Math.Abs(_chamber.ChamberPressure - _beginPressure) > _pressureStableTolerance)
  230. //{
  231. // Runner.Stop($"");
  232. // return true;
  233. //}
  234. if (_verificationDeviceTimer.GetElapseTime() > 3000)
  235. {
  236. if (Math.Abs(_mfcDevice.SetPoint - _mfcDevice.FeedBack) / _mfcDevice.SetPoint > _flowStableTolerance)
  237. {
  238. Runner.Stop($"Gas is not Stable");
  239. return true;
  240. }
  241. }
  242. return false;
  243. }
  244. private bool GetBeginPressure()
  245. {
  246. Notify($"Get begin pressure {_chamber.ChamberPressure.ToString("f1")}");
  247. _beginPressure = _chamber.ChamberPressure;
  248. _verificationDeviceTimer.Start(0);
  249. //Notify($"Check finished one point");
  250. return true;
  251. }
  252. private bool CalcMfcCalibration()
  253. {
  254. //_mfcIndex += 1;
  255. // full open Pendulum valve
  256. _chamber.SetPVPostion(1000);
  257. _endPressure = _chamber.ChamberPressure; //mTorr
  258. _elapsedTime = _verificationDeviceTimer.GetElapseTime() / (1000 * 60); //unit minutes
  259. float flow = _paramMode == VerifyMode.TenPoint ? _paramFlowSet[Runner.LoopCounter] : _mfcFlow;
  260. _mfcActualFlow = 273.15 * _chamberVolume / ((273.15 + _gasTemperature) * 760000) * ((_endPressure - _beginPressure) / _elapsedTime - _leakRate);
  261. Notify($"Calculate flow: calculate flow={_mfcActualFlow}, setpoint={flow}, begin pressure(mtorr)={_beginPressure:f3}, end pressure(mtorr)={_endPressure:f3}," +
  262. $"elapsed time(minute)={_elapsedTime:f3}");
  263. _MFCCalibrationDatas.Add(new MFCCalibrationData(flow,_mfcActualFlow));
  264. double deviation = (Math.Abs(_mfcActualFlow) - Math.Abs(flow)) / Math.Abs(flow) * 100;
  265. bool isOk = Math.Abs(deviation) <= Math.Abs(_maxDeviation);
  266. if (!isOk)
  267. {
  268. LOG.Write(eEvent.ERR_ROUTINE_FAILED, Module, Name, $"MFC{(_mfcIndex+1).ToString()} verify failed, deviation{deviation} exceed max tolerance{_maxDeviation}");
  269. }
  270. if (_paramMode == VerifyMode.TenPoint)
  271. {
  272. _calibrationResult[flow] = Tuple.Create((float)_mfcActualFlow, (float)_elapsedTime);
  273. _mfcDevice.SetVerificationResult((float)flow, (float)_mfcActualFlow, _calibrationResult.Count == 10, _elapsedTime * 60, deviation, isOk,(int)VerifyMode.TenPoint);
  274. }
  275. else if(_paramMode == VerifyMode.OnePoint)
  276. {
  277. _mfcDevice.SetVerificationResult((float)flow, (float)_mfcActualFlow, true, _elapsedTime * 60, deviation, isOk, (int)VerifyMode.OnePoint);
  278. }
  279. return true;
  280. }
  281. private bool StopGasFlow()
  282. {
  283. Notify($"Stop gas {_mfcIndex} flow");
  284. if (!_chamber.FlowGas(_mfcIndex, 0))
  285. {
  286. return false;
  287. }
  288. OpenPVNVlv(_mfcIndex, false);
  289. _chamber.OpenValve(ValveType.TurboPumpPumping, false);
  290. _chamber.OpenValve(ValveType.FastPump, true);
  291. return _pumpDownRoutine.Start(_basePressure) == RState.Running;
  292. }
  293. private bool IsPumpDownOK()
  294. {
  295. var status = _pumpDownRoutine.Monitor();
  296. if (status == RState.End)
  297. {
  298. return true;
  299. }
  300. else if (status == RState.Failed || status == RState.Timeout)
  301. {
  302. Runner.Stop($"Pump down to {_basePressure} failed.");
  303. return true;
  304. }
  305. return false;
  306. }
  307. }
  308. }