PMProcessRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 (!_chamber.IsRFGInterlockOn)
  111. {
  112. Stop("射频电源 Interlock条件不满足");
  113. return RState.Failed;
  114. }
  115. if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())
  116. {
  117. return RState.Failed;
  118. }
  119. // Load/Validate Recipe
  120. _qeRecipes.Clear();
  121. string recipeName = (string)objs[0];
  122. string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false);
  123. Recipe recipe = Recipe.Load(recipeContent);
  124. if(recipe == null)
  125. {
  126. Stop($"Load Recipe:{recipeName} failed");
  127. return RState.Failed;
  128. }
  129. _recipeRunningMode = SC.GetValue<int>($"{Module}.RecipeRunningMode");
  130. switch (recipe.Header.Type)
  131. {
  132. case RecipeType.Process:
  133. if(_recipeRunningMode == 1 && recipe.Header.ChuckRecipe != null)
  134. {
  135. var chuckRecipe = Recipe.Load(recipe.Header.ChuckRecipe);
  136. if(chuckRecipe != null)
  137. {
  138. ChuckRecipeName = recipe.Header.ChuckRecipe;
  139. _qeRecipes.Enqueue(chuckRecipe);
  140. }
  141. }
  142. ProcessRecipeHead = recipe.Header;
  143. ProcessRecipeName = recipeName;
  144. _qeRecipes.Enqueue(recipe);
  145. if(_recipeRunningMode == 1 && recipe.Header.DechuckRecipe != null)
  146. {
  147. var dechuckRecipe = Recipe.Load(recipe.Header.DechuckRecipe);
  148. if(dechuckRecipe != null)
  149. {
  150. DechuckRecipeNamae = recipe.Header.DechuckRecipe;
  151. _qeRecipes.Enqueue(dechuckRecipe);
  152. }
  153. }
  154. break;
  155. case RecipeType.Chuck:
  156. ChuckRecipeName = recipeName;
  157. _qeRecipes.Enqueue(recipe);
  158. break;
  159. case RecipeType.DeChuck:
  160. DechuckRecipeNamae = recipeName;
  161. _qeRecipes.Enqueue(recipe);
  162. break;
  163. case RecipeType.Clean:
  164. CleanRecipeName = recipeName;
  165. _qeRecipes.Enqueue(recipe);
  166. break;
  167. }
  168. foreach(Recipe rcp in _qeRecipes)
  169. {
  170. if (AssignFuns(rcp) == false)
  171. {
  172. Stop($"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  173. return RState.Failed;
  174. }
  175. }
  176. _bLoopMode = false;
  177. _loopStartStep = 0;
  178. _loopCounter = 0;
  179. _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");
  180. _OffsetTemp = SC.GetValue<double>($"{Module}.Chiller.ChillerTemperatureOffset");
  181. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.InProcess);
  182. return Runner.Start(Module, Name);
  183. }
  184. public RState Monitor()
  185. {
  186. Runner.Run((int)ProcessStep.kPreparePressure, PreparePressure, IsPressureReady)
  187. .Run((int)ProcessStep.kPrepareTemperature, PrepareTemp, IsTempReady)
  188. .Run((int)ProcessStep.kRunRecipes, StartNewRecipe, RunRecipes)
  189. .End((int)ProcessStep.kEnd, ProcessDone, _delay_1s);
  190. return Runner.Status;
  191. }
  192. private bool PreparePressure()
  193. {
  194. if(_chamber.ChamberPressure < BasePressure)
  195. {
  196. _needPumpDown = false;
  197. return true;
  198. }
  199. _needPumpDown = true;
  200. return _pumpDownRoutine.Start(BasePressure) == RState.Running;
  201. }
  202. private bool IsPressureReady()
  203. {
  204. if (_needPumpDown == false)
  205. return true;
  206. var status = _pumpDownRoutine.Monitor();
  207. if(status == RState.End)
  208. {
  209. return true;
  210. }
  211. else if (status == RState.Failed || status == RState.Timeout)
  212. {
  213. Runner.Stop($"Pump down to {BasePressure} failed.");
  214. return true;
  215. }
  216. return false;
  217. }
  218. private bool PrepareTemp()
  219. {
  220. return SetCoolantTemp(ChillerTemp, _OffsetTemp);
  221. }
  222. private bool IsTempReady()
  223. {
  224. return CheckCoolantTemp(ChillerTemp, _tolerance);
  225. }
  226. private RState StartNewStep()
  227. {
  228. var state = _currentRecipe.Steps[_currentStep].Start();
  229. if (state != RState.Running)
  230. return state;
  231. if (_currentRecipe.Steps[_currentStep].CycleStart)
  232. {
  233. if (!_bLoopMode)
  234. {
  235. _bLoopMode = true;
  236. _loopStartStep = _currentStep;
  237. _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber;
  238. }
  239. }
  240. return RState.Running;
  241. }
  242. private bool StartNewRecipe()
  243. {
  244. if(_qeRecipes.Count > 0)
  245. {
  246. _currentStep = 0;
  247. _currentRecipe = _qeRecipes.Dequeue();
  248. CurrentRunningRecipe = _currentRecipe.Header.Name;
  249. Notify($"Recipe:{CurrentRunningRecipe} start");
  250. return StartNewStep() == RState.Running;
  251. }
  252. return false;
  253. }
  254. private bool RunRecipes()
  255. {
  256. var step = _currentRecipe.Steps[_currentStep];
  257. var result = step.Run();
  258. if(result == RState.Failed)
  259. {
  260. UpdateWaferStatus(false);
  261. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  262. return true;
  263. }
  264. else if(result == RState.End)
  265. {
  266. if(_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)
  267. _currentRecipe.Steps[_currentStep].End();
  268. if(_currentRecipe.Steps[_currentStep].CycleEnd)
  269. {
  270. if(_loopCounter > 0)
  271. {
  272. _loopCounter--;
  273. _currentStep = _loopStartStep;
  274. return StartNewStep() != RState.Running;
  275. }
  276. else
  277. {
  278. _bLoopMode = false;
  279. _loopStartStep = 0;
  280. }
  281. }
  282. if (_currentStep < _currentRecipe.Steps.Count - 1)
  283. {
  284. _currentStep++;
  285. return StartNewStep() != RState.Running;
  286. }
  287. else
  288. {
  289. Notify($"Recipe:{CurrentRunningRecipe} finished");
  290. UpdateWaferStatus();
  291. return !StartNewRecipe();
  292. }
  293. }
  294. return false;
  295. }
  296. private bool ProcessDone()
  297. {
  298. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  299. return true;
  300. }
  301. private void UpdateWaferStatus(bool bDone = true)
  302. {
  303. if(bDone == false)
  304. {
  305. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Failed);
  306. if(_currentRecipe.Header.Type == RecipeType.Chuck)
  307. {
  308. // set wafer chucked flag even if the chuck recipe failed.
  309. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  310. }
  311. }
  312. switch(_currentRecipe.Header.Type)
  313. {
  314. case RecipeType.Process:
  315. break;
  316. case RecipeType.Chuck:
  317. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  318. break;
  319. case RecipeType.DeChuck:
  320. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Completed);
  321. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Dechucked);
  322. break;
  323. }
  324. }
  325. public void Abort()
  326. {
  327. CloseAllValves();
  328. }
  329. }
  330. }