PMProcessRoutine.cs 18 KB

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