PMProcessRoutine.cs 17 KB

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