PMProcessRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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.Common.Util;
  7. using Aitex.Core.RT.RecipeCenter;
  8. using Venus_RT.Devices;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using Venus_Core;
  12. using System.ServiceModel.Security.Tokens;
  13. using System.Diagnostics;
  14. using MECF.Framework.Common.DBCore;
  15. using Venus_RT.FAs;
  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 DechuckRecipeNamae { get; set; }
  31. public string CleanRecipeName { get; set; }
  32. public RecipeHead ProcessRecipeHead { get; set; }
  33. public DateTime RecipeStartTime { get; private set; }
  34. private readonly PumpDownRoutine _pumpDownRoutine;
  35. private readonly ProcessHelper _processHelper;
  36. private bool _withWafer = true;
  37. private bool _needPumpDown = false;
  38. private Recipe _currentRecipe = null;
  39. private int _currentStep = 0;
  40. private Queue<Recipe> _qeRecipes = new Queue<Recipe>();
  41. private double _tolerance;
  42. private double _OffsetTemp = 0.0f;
  43. private bool _bLoopMode = false;
  44. private int _loopStartStep = 0;
  45. private int _loopCounter = 0;
  46. private int _recipeRunningMode = 0;
  47. private Stopwatch _stepTime = new Stopwatch();
  48. public RecipeResult currentRecipeResult;
  49. public bool isMaualEndStep;
  50. private RecipeFACallback _faCallback;
  51. private double ChillerTemp
  52. {
  53. get
  54. {
  55. if (ProcessRecipeHead != null)
  56. {
  57. if (!string.IsNullOrEmpty(ProcessRecipeHead.ChillerTemp))
  58. {
  59. double setpoint = Convert.ToDouble(ProcessRecipeHead.ChillerTemp);
  60. if (setpoint > 0 && setpoint < 600)
  61. return setpoint;
  62. }
  63. }
  64. return 0;
  65. }
  66. }
  67. private double BasePressure
  68. {
  69. get
  70. {
  71. if (ProcessRecipeHead != null)
  72. {
  73. if (!string.IsNullOrEmpty(ProcessRecipeHead.BasePressure))
  74. {
  75. double setpoint = Convert.ToDouble(ProcessRecipeHead.BasePressure);
  76. if (setpoint > 0 && setpoint < 750000)
  77. return setpoint;
  78. }
  79. }
  80. return SC.GetValue<int>($"{Module}.Pump.PumpBasePressure");
  81. }
  82. }
  83. public double EstimatedTotalLeftTime
  84. {
  85. get;
  86. private set;
  87. }
  88. public PMProcessRoutine(JetPMBase chamber, PumpDownRoutine pdRoutine) : base(chamber)
  89. {
  90. Name = "Process";
  91. _pumpDownRoutine = pdRoutine;
  92. _processHelper = new ProcessHelper(chamber);
  93. _faCallback = new RecipeFACallback();
  94. }
  95. private bool AssignFuns(Recipe recipe)
  96. {
  97. foreach(var step in recipe.Steps)
  98. {
  99. if (_processHelper.LoadStepFuns(step) == false)
  100. return false;
  101. foreach(ProcessUnitBase unit in step.LstUnit)
  102. {
  103. if (_processHelper.LoadMethods(unit) == false)
  104. {
  105. Stop($"Cannot find the process routine for unit:{unit.GetType()}");
  106. return false;
  107. }
  108. }
  109. }
  110. return true;
  111. }
  112. public RState Start(params object[] objs)
  113. {
  114. if (_withWafer && WaferManager.Instance.CheckNoWafer(Module.ToString(), 0))
  115. {
  116. Stop($"can not run process, no wafer at {Module}");
  117. FaEvent.FaPostAlarm(Module.ToString(), $"can not run process, no wafer at {Module}");
  118. return RState.Failed;
  119. }
  120. if (!_chamber.IsRFGInterlockOn)
  121. {
  122. Stop("射频电源 Interlock条件不满足");
  123. FaEvent.FaPostAlarm(Module.ToString(), "射频电源 Interlock条件不满足");
  124. return RState.Failed;
  125. }
  126. if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())
  127. {
  128. return RState.Failed;
  129. }
  130. RecipeStartTime = DateTime.Now;
  131. // Load/Validate Recipe
  132. _qeRecipes.Clear();
  133. string recipeName = (string)objs[0];
  134. currentRecipeResult = new RecipeResult();
  135. currentRecipeResult.RecipeName = recipeName;
  136. string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false);
  137. Recipe recipe = Recipe.Load(recipeContent);
  138. currentRecipeResult.RecipeStepCount=recipe.Steps.Count;
  139. if (recipe == null)
  140. {
  141. Stop($"Load Recipe:{recipeName} failed");
  142. FaEvent.FaPostAlarm(Module.ToString(), $"Load Recipe:{recipeName} failed");
  143. return RState.Failed;
  144. }
  145. _recipeRunningMode = SC.GetValue<int>($"{Module}.RecipeRunningMode");
  146. switch (recipe.Header.Type)
  147. {
  148. case RecipeType.Process:
  149. if(_recipeRunningMode == 1 && recipe.Header.ChuckRecipe != null)
  150. {
  151. var chuckRecipe = Recipe.Load(recipe.Header.ChuckRecipe);
  152. if(chuckRecipe != null)
  153. {
  154. ChuckRecipeName = recipe.Header.ChuckRecipe;
  155. _qeRecipes.Enqueue(chuckRecipe);
  156. }
  157. }
  158. ProcessRecipeHead = recipe.Header;
  159. ProcessRecipeName = recipeName;
  160. _qeRecipes.Enqueue(recipe);
  161. if(_recipeRunningMode == 1 && recipe.Header.DechuckRecipe != null)
  162. {
  163. var dechuckRecipe = Recipe.Load(recipe.Header.DechuckRecipe);
  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.RecipeStepNumber = step.StepNo;
  282. currentRecipeResult.RecipeStepType=step.Type.ToString();
  283. currentRecipeResult.RecipeStepSetTime=step.Time;
  284. //currentRecipeResult.RecipeStepDuringTime = (int)_stepTime.ElapsedMilliseconds/1000;
  285. currentRecipeResult.RecipeStepDuringTime = new System.TimeSpan(0, 0, System.Convert.ToInt32(_stepTime.ElapsedMilliseconds/1000));
  286. var result = step.Run();
  287. if(result == RState.Failed)
  288. {
  289. UpdateWaferStatus(false);
  290. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  291. FaEvent.FaPostAlarm(Module.ToString(), $"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  292. return true;
  293. }
  294. else if(result == RState.End || isMaualEndStep == true)
  295. {
  296. if(_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)
  297. _currentRecipe.Steps[_currentStep].End();
  298. if(_currentRecipe.Steps[_currentStep].CycleEnd)
  299. {
  300. if(_loopCounter > 0)
  301. {
  302. _loopCounter--;
  303. currentRecipeResult.RecipeCurrentCounter += 1;
  304. _currentStep = _loopStartStep;
  305. return StartNewStep() != RState.Running;
  306. }
  307. else
  308. {
  309. _bLoopMode = false;
  310. _loopStartStep = 0;
  311. }
  312. }
  313. if (_currentStep < _currentRecipe.Steps.Count - 1|| isMaualEndStep==true)
  314. {
  315. result = RState.End;
  316. isMaualEndStep =false;
  317. _currentStep++;
  318. return StartNewStep() != RState.Running;
  319. }
  320. else
  321. {
  322. Notify($"Recipe:{CurrentRunningRecipe} finished");
  323. FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} finished");
  324. UpdateWaferStatus();
  325. _chamber.EPDRecipeStop();
  326. return !StartNewRecipe();
  327. }
  328. }
  329. return false;
  330. }
  331. private bool ProcessDone()
  332. {
  333. _stepTime.Stop();
  334. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Idle);
  335. CloseAllValves();
  336. _chamber.GeneratorBiasPowerOn(false);
  337. _chamber.GeneratorPowerOn(false);
  338. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  339. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  340. _chamber.OpenValve(ValveType.Guage, true);
  341. _chamber.SetPVPostion(1000);
  342. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  343. ProcessDataRecorder.RecordPrecess(Guid.NewGuid().ToString(), RecipeStartTime, DateTime.Now, CurrentRunningRecipe, "", _chamber.Name, "", "");
  344. return true;
  345. }
  346. private void UpdateWaferStatus(bool bDone = true)
  347. {
  348. if(bDone == false)
  349. {
  350. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Failed);
  351. if(_currentRecipe.Header.Type == RecipeType.Chuck)
  352. {
  353. // set wafer chucked flag even if the chuck recipe failed.
  354. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  355. }
  356. }
  357. switch(_currentRecipe.Header.Type)
  358. {
  359. case RecipeType.Process:
  360. break;
  361. case RecipeType.Chuck:
  362. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  363. break;
  364. case RecipeType.DeChuck:
  365. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Completed);
  366. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Dechucked);
  367. break;
  368. }
  369. }
  370. public void Abort()
  371. {
  372. _chamber.GeneratorBiasPowerOn(false);
  373. _chamber.GeneratorPowerOn(false);
  374. _chamber.TurnPendulumValve(false);
  375. CloseAllValves();
  376. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  377. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  378. }
  379. }
  380. }