PMGasVerificationRoutine.cs 12 KB

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