PMProcessRoutine.cs 20 KB

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