PMProcessRoutine.cs 21 KB

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