PMGasVerificationRoutine.cs 12 KB

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