PMProcessRoutine.cs 20 KB

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