PMGasVerificationRoutine.cs 11 KB

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