PMProcessRoutine.cs 12 KB

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