PMProcessRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 SetCoolantTemp(ChillerTemp, _OffsetTemp);
  241. }
  242. private bool IsTempReady()
  243. {
  244. return CheckCoolantTemp(ChillerTemp, _tolerance);
  245. }
  246. public RState StartNewStep()
  247. {
  248. _stepTime.Restart();
  249. var state = _currentRecipe.Steps[_currentStep].Start();
  250. if (state != RState.Running)
  251. return state;
  252. if (_currentRecipe.Steps[_currentStep].CycleStart)
  253. {
  254. if (!_bLoopMode)
  255. {
  256. _bLoopMode = true;
  257. _loopStartStep = _currentStep;
  258. _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber-1;
  259. currentRecipeResult.RecipeAllCounters = _currentRecipe.Steps[_currentStep].CycleNumber;
  260. }
  261. }
  262. return RState.Running;
  263. }
  264. private bool StartNewRecipe()
  265. {
  266. if(_qeRecipes.Count > 0)
  267. {
  268. _currentStep = 0;
  269. _currentRecipe = _qeRecipes.Dequeue();
  270. CurrentRunningRecipe = _currentRecipe.Header.Name;
  271. Notify($"Recipe:{CurrentRunningRecipe} start");
  272. FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} start");
  273. _chamber.EPDRecipeStart(CurrentRunningRecipe);
  274. return StartNewStep() == RState.Running;
  275. }
  276. return false;
  277. }
  278. private bool RunRecipes()
  279. {
  280. var step = _currentRecipe.Steps[_currentStep];
  281. currentRecipeResult.RecipeStepCount = _currentRecipe.Steps.Count;
  282. currentRecipeResult.RecipeName = _currentRecipe.Header.Name;
  283. currentRecipeResult.RecipeType = _currentRecipe.Header.Type.ToString();
  284. currentRecipeResult.RecipeStepNumber = step.StepNo;
  285. currentRecipeResult.RecipeStepType=step.Type.ToString();
  286. currentRecipeResult.RecipeStepSetTime=step.Time;
  287. currentRecipeResult.RecipeType=_currentRecipe.Header.Type.ToString();
  288. //currentRecipeResult.RecipeStepDuringTime = (int)_stepTime.ElapsedMilliseconds/1000;
  289. currentRecipeResult.RecipeStepDuringTime = new System.TimeSpan(0, 0, System.Convert.ToInt32(_stepTime.ElapsedMilliseconds/1000));
  290. var result = step.Run();
  291. if(result == RState.Failed)
  292. {
  293. UpdateWaferStatus(false);
  294. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  295. FaEvent.FaPostAlarm(Module.ToString(), $"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  296. return true;
  297. }
  298. else if(result == RState.End || isMaualEndStep == true)
  299. {
  300. if(_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)
  301. _currentRecipe.Steps[_currentStep].End();
  302. if(_currentRecipe.Steps[_currentStep].CycleEnd)
  303. {
  304. if(_loopCounter > 0)
  305. {
  306. _loopCounter--;
  307. currentRecipeResult.RecipeCurrentCounter += 1;
  308. _currentStep = _loopStartStep;
  309. return StartNewStep() != RState.Running;
  310. }
  311. else
  312. {
  313. _bLoopMode = false;
  314. _loopStartStep = 0;
  315. }
  316. }
  317. if (_currentStep < _currentRecipe.Steps.Count - 1|| isMaualEndStep==true)
  318. {
  319. result = RState.End;
  320. isMaualEndStep =false;
  321. _currentStep++;
  322. return StartNewStep() != RState.Running;
  323. }
  324. else
  325. {
  326. Notify($"Recipe:{CurrentRunningRecipe} finished");
  327. FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} finished");
  328. UpdateWaferStatus();
  329. _chamber.EPDRecipeStop();
  330. return !StartNewRecipe();
  331. }
  332. }
  333. return false;
  334. }
  335. private bool ProcessDone()
  336. {
  337. _stepTime.Stop();
  338. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Idle);
  339. CloseAllValves();
  340. _chamber.GeneratorBiasPowerOn(false);
  341. _chamber.GeneratorPowerOn(false);
  342. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  343. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  344. _chamber.OpenValve(ValveType.Guage, true);
  345. _chamber.SetPVPostion(1000);
  346. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  347. ProcessDataRecorder.RecordPrecess(Guid.NewGuid().ToString(), RecipeStartTime, DateTime.Now, CurrentRunningRecipe, "", _chamber.Name, "", "");
  348. return true;
  349. }
  350. private void UpdateWaferStatus(bool bDone = true)
  351. {
  352. if(bDone == false)
  353. {
  354. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Failed);
  355. if(_currentRecipe.Header.Type == RecipeType.Chuck)
  356. {
  357. // set wafer chucked flag even if the chuck recipe failed.
  358. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  359. }
  360. }
  361. switch(_currentRecipe.Header.Type)
  362. {
  363. case RecipeType.Process:
  364. break;
  365. case RecipeType.Chuck:
  366. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  367. break;
  368. case RecipeType.DeChuck:
  369. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Completed);
  370. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Dechucked);
  371. break;
  372. }
  373. }
  374. public void Abort()
  375. {
  376. _chamber.GeneratorBiasPowerOn(false);
  377. _chamber.GeneratorPowerOn(false);
  378. _chamber.TurnPendulumValve(false);
  379. CloseAllValves();
  380. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  381. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  382. }
  383. }
  384. }