PMProcessRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Common;
  6. using Aitex.Common.Util;
  7. using Aitex.Core.RT.RecipeCenter;
  8. using Venus_RT.Devices;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using Venus_Core;
  12. namespace Venus_RT.Modules.PMs
  13. {
  14. class PMProcessRoutine : PMRoutineBase, IRoutine
  15. {
  16. private enum ProcessStep
  17. {
  18. kPreparePressure,
  19. kPrepareTemperature,
  20. kRunRecipes,
  21. kEnd,
  22. }
  23. public string CurrentRunningRecipe { get; set; }
  24. public string ProcessRecipeName { get; set; }
  25. public string ChuckRecipeName { get; set; }
  26. public string DechuckRecipeNamae { get; set; }
  27. public string CleanRecipeName { get; set; }
  28. public RecipeHead ProcessRecipeHead { get; set; }
  29. public DateTime RecipeStartTime { get; private set; }
  30. private readonly PumpDownRoutine _pumpDownRoutine;
  31. private readonly ProcessHelper _processHelper;
  32. private bool _withWafer = true;
  33. private bool _needPumpDown = false;
  34. private Recipe _currentRecipe = null;
  35. private int _currentStep = 0;
  36. private Queue<Recipe> _qeRecipes = new Queue<Recipe>();
  37. private double _tolerance;
  38. private double _OffsetTemp = 0.0f;
  39. private bool _bLoopMode = false;
  40. private int _loopStartStep = 0;
  41. private int _loopCounter = 0;
  42. private double ChillerTemp
  43. {
  44. get
  45. {
  46. if (ProcessRecipeHead != null)
  47. {
  48. if (!string.IsNullOrEmpty(ProcessRecipeHead.ChillerTemp))
  49. {
  50. double setpoint = Convert.ToDouble(ProcessRecipeHead.ChillerTemp);
  51. if (setpoint > 0 && setpoint < 600)
  52. return setpoint;
  53. }
  54. }
  55. return 0;
  56. }
  57. }
  58. private double BasePressure
  59. {
  60. get
  61. {
  62. if (ProcessRecipeHead != null)
  63. {
  64. if (!string.IsNullOrEmpty(ProcessRecipeHead.BasePressure))
  65. {
  66. double setpoint = Convert.ToDouble(ProcessRecipeHead.BasePressure);
  67. if (setpoint > 0 && setpoint < 750000)
  68. return setpoint;
  69. }
  70. }
  71. return SC.GetValue<int>($"{Module}.Pump.PumpBasePressure");
  72. }
  73. }
  74. public double EstimatedTotalLeftTime
  75. {
  76. get;
  77. private set;
  78. }
  79. public PMProcessRoutine(JetPM chamber, PumpDownRoutine pdRoutine) : base(chamber)
  80. {
  81. Name = "Process";
  82. _pumpDownRoutine = pdRoutine;
  83. _processHelper = new ProcessHelper(chamber);
  84. }
  85. private bool AssignFuns(Recipe recipe)
  86. {
  87. foreach(var step in recipe.Steps)
  88. {
  89. if (ProcessHelper.LoadStepFuns(step) == false)
  90. return false;
  91. foreach(ProcessUnitBase unit in step.LstUnit)
  92. {
  93. if (ProcessHelper.LoadMethods(unit) == false)
  94. {
  95. Stop($"Cannot find the process routine for unit:{unit.GetType()}");
  96. return false;
  97. }
  98. }
  99. }
  100. return true;
  101. }
  102. public RState Start(params object[] objs)
  103. {
  104. if (_withWafer && WaferManager.Instance.CheckNoWafer(Module.ToString(), 0))
  105. {
  106. Stop($"can not run process, no wafer at {Module}");
  107. return RState.Failed;
  108. }
  109. if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())
  110. {
  111. return RState.Failed;
  112. }
  113. // Load/Validate Recipe
  114. _qeRecipes.Clear();
  115. string recipeName = (string)objs[0];
  116. string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false);
  117. Recipe recipe = Recipe.Load(recipeContent);
  118. if(recipe == null)
  119. {
  120. Stop($"Load Recipe:{recipeName} failed");
  121. return RState.Failed;
  122. }
  123. if (AssignFuns(recipe) == false)
  124. {
  125. Stop($"Associate process alogrithm with recipe:{recipeName} failed");
  126. return RState.Failed;
  127. }
  128. switch(recipe.Header.Type)
  129. {
  130. case RecipeType.Process:
  131. if(recipe.Header.ChuckRecipe != null)
  132. {
  133. var chuckRecipe = Recipe.Load(recipe.Header.ChuckRecipe);
  134. if(chuckRecipe != null)
  135. {
  136. ChuckRecipeName = recipe.Header.ChuckRecipe;
  137. _qeRecipes.Enqueue(chuckRecipe);
  138. }
  139. }
  140. ProcessRecipeHead = recipe.Header;
  141. ProcessRecipeName = recipeName;
  142. _qeRecipes.Enqueue(recipe);
  143. if(recipe.Header.DechuckRecipe != null)
  144. {
  145. var dechuckRecipe = Recipe.Load(recipe.Header.DechuckRecipe);
  146. if(dechuckRecipe != null)
  147. {
  148. DechuckRecipeNamae = recipe.Header.DechuckRecipe;
  149. _qeRecipes.Enqueue(dechuckRecipe);
  150. }
  151. }
  152. break;
  153. case RecipeType.Chuck:
  154. ChuckRecipeName = recipeName;
  155. _qeRecipes.Enqueue(recipe);
  156. break;
  157. case RecipeType.DeChuck:
  158. DechuckRecipeNamae = recipeName;
  159. _qeRecipes.Enqueue(recipe);
  160. break;
  161. case RecipeType.Clean:
  162. CleanRecipeName = recipeName;
  163. _qeRecipes.Enqueue(recipe);
  164. break;
  165. }
  166. _bLoopMode = false;
  167. _loopStartStep = 0;
  168. _loopCounter = 0;
  169. _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");
  170. _OffsetTemp = SC.GetValue<double>($"{Module}.Chiller.ChillerTemperatureOffset");
  171. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.InProcess);
  172. return Runner.Start(Module, Name);
  173. }
  174. public RState Monitor()
  175. {
  176. Runner.Run((int)ProcessStep.kPreparePressure, PreparePressure, IsPressureReady)
  177. .Run((int)ProcessStep.kPrepareTemperature, PrepareTemp, IsTempReady)
  178. .Run((int)ProcessStep.kRunRecipes, StartNewRecipe, RunRecipes)
  179. .End((int)ProcessStep.kEnd, ProcessDone, _delay_1s);
  180. return Runner.Status;
  181. }
  182. private bool PreparePressure()
  183. {
  184. if(_chamber.ChamberPressure < BasePressure)
  185. {
  186. _needPumpDown = false;
  187. return true;
  188. }
  189. _needPumpDown = true;
  190. return _pumpDownRoutine.Start(BasePressure) == RState.Running;
  191. }
  192. private bool IsPressureReady()
  193. {
  194. if (_needPumpDown == false)
  195. return true;
  196. var status = _pumpDownRoutine.Monitor();
  197. if(status == RState.End)
  198. {
  199. return true;
  200. }
  201. else if (status == RState.Failed || status == RState.Timeout)
  202. {
  203. Runner.Stop($"Pump down to {BasePressure} failed.");
  204. return true;
  205. }
  206. return false;
  207. }
  208. private bool PrepareTemp()
  209. {
  210. return SetCoolantTemp(ChillerTemp, _OffsetTemp);
  211. }
  212. private bool IsTempReady()
  213. {
  214. return CheckCoolantTemp(ChillerTemp, _tolerance);
  215. }
  216. private RState StartNewStep()
  217. {
  218. var state = _currentRecipe.Steps[_currentStep].Start();
  219. if (state != RState.Running)
  220. return state;
  221. if (_currentRecipe.Steps[_currentStep].CycleStart)
  222. {
  223. if (!_bLoopMode)
  224. {
  225. _bLoopMode = true;
  226. _loopStartStep = _currentStep;
  227. _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber;
  228. }
  229. }
  230. return RState.Running;
  231. }
  232. private bool StartNewRecipe()
  233. {
  234. if(_qeRecipes.Count > 0)
  235. {
  236. _currentStep = 0;
  237. _currentRecipe = _qeRecipes.Dequeue();
  238. CurrentRunningRecipe = _currentRecipe.Header.Name;
  239. Notify($"Recipe:{CurrentRunningRecipe} start");
  240. return StartNewStep() == RState.Running;
  241. }
  242. return false;
  243. }
  244. private bool RunRecipes()
  245. {
  246. var step = _currentRecipe.Steps[_currentStep];
  247. var result = step.Run();
  248. if(result == RState.Failed)
  249. {
  250. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  251. return true;
  252. }
  253. else if(result == RState.End)
  254. {
  255. if(_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)
  256. _currentRecipe.Steps[_currentStep].End();
  257. if(_currentRecipe.Steps[_currentStep].CycleEnd)
  258. {
  259. if(_loopCounter > 0)
  260. {
  261. _loopCounter--;
  262. _currentStep = _loopStartStep;
  263. return StartNewStep() != RState.Running;
  264. }
  265. else
  266. {
  267. _bLoopMode = false;
  268. _loopStartStep = 0;
  269. }
  270. }
  271. if (_currentStep < _currentRecipe.Steps.Count - 1)
  272. {
  273. _currentStep++;
  274. return StartNewStep() != RState.Running;
  275. }
  276. else
  277. {
  278. Notify($"Recipe:{CurrentRunningRecipe} finished");
  279. return !StartNewRecipe();
  280. }
  281. }
  282. return false;
  283. }
  284. private bool ProcessDone()
  285. {
  286. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  287. return true;
  288. }
  289. public void Abort()
  290. {
  291. CloseAllValves();
  292. }
  293. }
  294. }