PMProcessRoutine.cs 22 KB

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