PMProcessRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. using System.ServiceModel.Security.Tokens;
  13. using System.Diagnostics;
  14. using MECF.Framework.Common.DBCore;
  15. namespace Venus_RT.Modules.PMs
  16. {
  17. class PMProcessRoutine : PMRoutineBase, IRoutine
  18. {
  19. private enum ProcessStep
  20. {
  21. kPreparePressure,
  22. kPrepareTemperature,
  23. kRunRecipes,
  24. kEnd,
  25. }
  26. public string CurrentRunningRecipe { get; set; }
  27. public string ProcessRecipeName { get; set; }
  28. public string ChuckRecipeName { get; set; }
  29. public string DechuckRecipeNamae { get; set; }
  30. public string CleanRecipeName { get; set; }
  31. public RecipeHead ProcessRecipeHead { get; set; }
  32. public DateTime RecipeStartTime { get; private set; }
  33. private readonly PumpDownRoutine _pumpDownRoutine;
  34. private readonly ProcessHelper _processHelper;
  35. private bool _withWafer = true;
  36. private bool _needPumpDown = false;
  37. private Recipe _currentRecipe = null;
  38. private int _currentStep = 0;
  39. private Queue<Recipe> _qeRecipes = new Queue<Recipe>();
  40. private double _tolerance;
  41. private double _OffsetTemp = 0.0f;
  42. private bool _bLoopMode = false;
  43. private int _loopStartStep = 0;
  44. private int _loopCounter = 0;
  45. private int _recipeRunningMode = 0;
  46. private Stopwatch _stepTime = new Stopwatch();
  47. public RecipeResult currentRecipeResult;
  48. public bool isMaualEndStep;
  49. private double ChillerTemp
  50. {
  51. get
  52. {
  53. if (ProcessRecipeHead != null)
  54. {
  55. if (!string.IsNullOrEmpty(ProcessRecipeHead.ChillerTemp))
  56. {
  57. double setpoint = Convert.ToDouble(ProcessRecipeHead.ChillerTemp);
  58. if (setpoint > 0 && setpoint < 600)
  59. return setpoint;
  60. }
  61. }
  62. return 0;
  63. }
  64. }
  65. private double BasePressure
  66. {
  67. get
  68. {
  69. if (ProcessRecipeHead != null)
  70. {
  71. if (!string.IsNullOrEmpty(ProcessRecipeHead.BasePressure))
  72. {
  73. double setpoint = Convert.ToDouble(ProcessRecipeHead.BasePressure);
  74. if (setpoint > 0 && setpoint < 750000)
  75. return setpoint;
  76. }
  77. }
  78. return SC.GetValue<int>($"{Module}.Pump.PumpBasePressure");
  79. }
  80. }
  81. public double EstimatedTotalLeftTime
  82. {
  83. get;
  84. private set;
  85. }
  86. public PMProcessRoutine(JetPMBase chamber, PumpDownRoutine pdRoutine) : base(chamber)
  87. {
  88. Name = "Process";
  89. _pumpDownRoutine = pdRoutine;
  90. _processHelper = new ProcessHelper(chamber);
  91. }
  92. private bool AssignFuns(Recipe recipe)
  93. {
  94. foreach(var step in recipe.Steps)
  95. {
  96. if (_processHelper.LoadStepFuns(step) == false)
  97. return false;
  98. foreach(ProcessUnitBase unit in step.LstUnit)
  99. {
  100. if (_processHelper.LoadMethods(unit) == false)
  101. {
  102. Stop($"Cannot find the process routine for unit:{unit.GetType()}");
  103. return false;
  104. }
  105. }
  106. }
  107. return true;
  108. }
  109. public RState Start(params object[] objs)
  110. {
  111. if (_withWafer && WaferManager.Instance.CheckNoWafer(Module.ToString(), 0))
  112. {
  113. Stop($"can not run process, no wafer at {Module}");
  114. return RState.Failed;
  115. }
  116. if (!_chamber.IsRFGInterlockOn)
  117. {
  118. Stop("射频电源 Interlock条件不满足");
  119. return RState.Failed;
  120. }
  121. if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())
  122. {
  123. return RState.Failed;
  124. }
  125. RecipeStartTime = DateTime.Now;
  126. // Load/Validate Recipe
  127. _qeRecipes.Clear();
  128. string recipeName = (string)objs[0];
  129. currentRecipeResult = new RecipeResult();
  130. currentRecipeResult.RecipeName = recipeName;
  131. string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false);
  132. Recipe recipe = Recipe.Load(recipeContent);
  133. currentRecipeResult.RecipeStepCount=recipe.Steps.Count;
  134. if (recipe == null)
  135. {
  136. Stop($"Load Recipe:{recipeName} failed");
  137. return RState.Failed;
  138. }
  139. _recipeRunningMode = SC.GetValue<int>($"{Module}.RecipeRunningMode");
  140. switch (recipe.Header.Type)
  141. {
  142. case RecipeType.Process:
  143. if(_recipeRunningMode == 1 && recipe.Header.ChuckRecipe != null)
  144. {
  145. var chuckRecipe = Recipe.Load(recipe.Header.ChuckRecipe);
  146. if(chuckRecipe != null)
  147. {
  148. ChuckRecipeName = recipe.Header.ChuckRecipe;
  149. _qeRecipes.Enqueue(chuckRecipe);
  150. }
  151. }
  152. ProcessRecipeHead = recipe.Header;
  153. ProcessRecipeName = recipeName;
  154. _qeRecipes.Enqueue(recipe);
  155. if(_recipeRunningMode == 1 && recipe.Header.DechuckRecipe != null)
  156. {
  157. var dechuckRecipe = Recipe.Load(recipe.Header.DechuckRecipe);
  158. if(dechuckRecipe != null)
  159. {
  160. DechuckRecipeNamae = recipe.Header.DechuckRecipe;
  161. _qeRecipes.Enqueue(dechuckRecipe);
  162. }
  163. }
  164. break;
  165. case RecipeType.Chuck:
  166. ChuckRecipeName = recipeName;
  167. _qeRecipes.Enqueue(recipe);
  168. break;
  169. case RecipeType.DeChuck:
  170. DechuckRecipeNamae = recipeName;
  171. _qeRecipes.Enqueue(recipe);
  172. break;
  173. case RecipeType.Clean:
  174. CleanRecipeName = recipeName;
  175. _qeRecipes.Enqueue(recipe);
  176. break;
  177. }
  178. foreach(Recipe rcp in _qeRecipes)
  179. {
  180. if (AssignFuns(rcp) == false)
  181. {
  182. Stop($"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  183. return RState.Failed;
  184. }
  185. }
  186. _bLoopMode = false;
  187. _loopStartStep = 0;
  188. _loopCounter = 0;
  189. _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");
  190. _OffsetTemp = SC.GetValue<double>($"{Module}.Chiller.ChillerTemperatureOffset");
  191. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.InProcess);
  192. return Runner.Start(Module, Name);
  193. }
  194. public RState Monitor()
  195. {
  196. Runner.Run((int)ProcessStep.kPreparePressure, PreparePressure, IsPressureReady)
  197. .Run((int)ProcessStep.kPrepareTemperature, PrepareTemp, IsTempReady)
  198. .Run((int)ProcessStep.kRunRecipes, StartNewRecipe, RunRecipes,5*60*60*1000)
  199. .End((int)ProcessStep.kEnd, ProcessDone, _delay_1s);
  200. return Runner.Status;
  201. }
  202. private bool PreparePressure()
  203. {
  204. if(_chamber.ProcessHighPressure < 5 && _chamber.ProcessLowPressure<BasePressure)
  205. {
  206. _needPumpDown = false;
  207. return true;
  208. }
  209. _needPumpDown = true;
  210. return _pumpDownRoutine.Start(BasePressure) == RState.Running;
  211. }
  212. private bool IsPressureReady()
  213. {
  214. if (_needPumpDown == false)
  215. return true;
  216. var status = _pumpDownRoutine.Monitor();
  217. if(status == RState.End)
  218. {
  219. return true;
  220. }
  221. else if (status == RState.Failed || status == RState.Timeout)
  222. {
  223. Runner.Stop($"Pump down to {BasePressure} failed.");
  224. return true;
  225. }
  226. return false;
  227. }
  228. private bool PrepareTemp()
  229. {
  230. return SetCoolantTemp(ChillerTemp, _OffsetTemp);
  231. }
  232. private bool IsTempReady()
  233. {
  234. return CheckCoolantTemp(ChillerTemp, _tolerance);
  235. }
  236. public RState StartNewStep()
  237. {
  238. _stepTime.Restart();
  239. var state = _currentRecipe.Steps[_currentStep].Start();
  240. if (state != RState.Running)
  241. return state;
  242. if (_currentRecipe.Steps[_currentStep].CycleStart)
  243. {
  244. if (!_bLoopMode)
  245. {
  246. _bLoopMode = true;
  247. _loopStartStep = _currentStep;
  248. _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber;
  249. }
  250. }
  251. return RState.Running;
  252. }
  253. private bool StartNewRecipe()
  254. {
  255. if(_qeRecipes.Count > 0)
  256. {
  257. _currentStep = 0;
  258. _currentRecipe = _qeRecipes.Dequeue();
  259. CurrentRunningRecipe = _currentRecipe.Header.Name;
  260. Notify($"Recipe:{CurrentRunningRecipe} start");
  261. return StartNewStep() == RState.Running;
  262. }
  263. return false;
  264. }
  265. private bool RunRecipes()
  266. {
  267. var step = _currentRecipe.Steps[_currentStep];
  268. currentRecipeResult.RecipeStepNumber = step.StepNo;
  269. currentRecipeResult.RecipeStepType=step.Type.ToString();
  270. currentRecipeResult.RecipeStepSetTime=step.Time;
  271. //currentRecipeResult.RecipeStepDuringTime = (int)_stepTime.ElapsedMilliseconds/1000;
  272. currentRecipeResult.RecipeStepDuringTime = new System.TimeSpan(0, 0, System.Convert.ToInt32(_stepTime.ElapsedMilliseconds/1000));
  273. var result = step.Run();
  274. if(result == RState.Failed)
  275. {
  276. UpdateWaferStatus(false);
  277. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  278. return true;
  279. }
  280. else if(result == RState.End || isMaualEndStep == true)
  281. {
  282. if(_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)
  283. _currentRecipe.Steps[_currentStep].End();
  284. if(_currentRecipe.Steps[_currentStep].CycleEnd)
  285. {
  286. if(_loopCounter > 0)
  287. {
  288. _loopCounter--;
  289. _currentStep = _loopStartStep;
  290. return StartNewStep() != RState.Running;
  291. }
  292. else
  293. {
  294. _bLoopMode = false;
  295. _loopStartStep = 0;
  296. }
  297. }
  298. if (_currentStep < _currentRecipe.Steps.Count - 1|| isMaualEndStep==true)
  299. {
  300. result = RState.End;
  301. isMaualEndStep =false;
  302. _currentStep++;
  303. return StartNewStep() != RState.Running;
  304. }
  305. else
  306. {
  307. Notify($"Recipe:{CurrentRunningRecipe} finished");
  308. UpdateWaferStatus();
  309. return !StartNewRecipe();
  310. }
  311. }
  312. return false;
  313. }
  314. private bool ProcessDone()
  315. {
  316. _stepTime.Stop();
  317. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Idle);
  318. CloseAllValves();
  319. _chamber.GeneratorBiasPowerOn(false);
  320. _chamber.GeneratorPowerOn(false);
  321. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  322. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  323. _chamber.OpenValve(ValveType.Guage, true);
  324. _chamber.SetPVPostion(1000);
  325. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  326. ProcessDataRecorder.RecordPrecess(Guid.NewGuid().ToString(), RecipeStartTime, DateTime.Now, CurrentRunningRecipe, "", _chamber.Name, "", "");
  327. return true;
  328. }
  329. private void UpdateWaferStatus(bool bDone = true)
  330. {
  331. if(bDone == false)
  332. {
  333. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Failed);
  334. if(_currentRecipe.Header.Type == RecipeType.Chuck)
  335. {
  336. // set wafer chucked flag even if the chuck recipe failed.
  337. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  338. }
  339. }
  340. switch(_currentRecipe.Header.Type)
  341. {
  342. case RecipeType.Process:
  343. break;
  344. case RecipeType.Chuck:
  345. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  346. break;
  347. case RecipeType.DeChuck:
  348. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Completed);
  349. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Dechucked);
  350. break;
  351. }
  352. }
  353. public void Abort()
  354. {
  355. _chamber.GeneratorBiasPowerOn(false);
  356. _chamber.GeneratorPowerOn(false);
  357. _chamber.TurnPendulumValve(false);
  358. CloseAllValves();
  359. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  360. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  361. }
  362. }
  363. }