PMProcessRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. string chuckcontent= RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipe.Header.ChuckRecipe, false);
  152. var chuckRecipe = Recipe.Load(chuckcontent);
  153. if(chuckRecipe != null)
  154. {
  155. ChuckRecipeName = recipe.Header.ChuckRecipe;
  156. _qeRecipes.Enqueue(chuckRecipe);
  157. }
  158. }
  159. ProcessRecipeHead = recipe.Header;
  160. ProcessRecipeName = recipeName;
  161. _qeRecipes.Enqueue(recipe);
  162. if(_recipeRunningMode == 1 && recipe.Header.DechuckRecipe != null)
  163. {
  164. string dechuckcontent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipe.Header.DechuckRecipe, false);
  165. var dechuckRecipe = Recipe.Load(dechuckcontent);
  166. if(dechuckRecipe != null)
  167. {
  168. DechuckRecipeNamae = recipe.Header.DechuckRecipe;
  169. _qeRecipes.Enqueue(dechuckRecipe);
  170. }
  171. }
  172. break;
  173. case RecipeType.Chuck:
  174. ChuckRecipeName = recipeName;
  175. _qeRecipes.Enqueue(recipe);
  176. break;
  177. case RecipeType.DeChuck:
  178. DechuckRecipeNamae = recipeName;
  179. _qeRecipes.Enqueue(recipe);
  180. break;
  181. case RecipeType.Clean:
  182. CleanRecipeName = recipeName;
  183. _qeRecipes.Enqueue(recipe);
  184. break;
  185. }
  186. foreach(Recipe rcp in _qeRecipes)
  187. {
  188. if (AssignFuns(rcp) == false)
  189. {
  190. Stop($"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  191. FaEvent.FaPostAlarm(Module.ToString(), $"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  192. return RState.Failed;
  193. }
  194. }
  195. _bLoopMode = false;
  196. _loopStartStep = 0;
  197. _loopCounter = 0;
  198. _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");
  199. _OffsetTemp = SC.GetValue<double>($"{Module}.Chiller.ChillerTemperatureOffset");
  200. _faCallback.RecipeStart(_chamber.Module.ToString(), recipeName);
  201. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.InProcess);
  202. return Runner.Start(Module, Name);
  203. }
  204. public RState Monitor()
  205. {
  206. Runner.Run((int)ProcessStep.kPreparePressure, PreparePressure, IsPressureReady)
  207. .Run((int)ProcessStep.kPrepareTemperature, PrepareTemp, IsTempReady)
  208. .Run((int)ProcessStep.kRunRecipes, StartNewRecipe, RunRecipes,5*60*60*1000)
  209. .End((int)ProcessStep.kEnd, ProcessDone, _delay_1s);
  210. return Runner.Status;
  211. }
  212. private bool PreparePressure()
  213. {
  214. if(_chamber.ProcessHighPressure < 5 && _chamber.ProcessLowPressure<BasePressure)
  215. {
  216. _needPumpDown = false;
  217. return true;
  218. }
  219. _needPumpDown = true;
  220. return _pumpDownRoutine.Start(BasePressure) == RState.Running;
  221. }
  222. private bool IsPressureReady()
  223. {
  224. if (_needPumpDown == false)
  225. return true;
  226. var status = _pumpDownRoutine.Monitor();
  227. if(status == RState.End)
  228. {
  229. return true;
  230. }
  231. else if (status == RState.Failed || status == RState.Timeout)
  232. {
  233. Runner.Stop($"Pump down to {BasePressure} failed.");
  234. FaEvent.FaPostAlarm(Module.ToString(), $"Pump down to {BasePressure} failed.");
  235. return true;
  236. }
  237. return false;
  238. }
  239. private bool PrepareTemp()
  240. {
  241. currentRecipeResult.RecipeCurrentCounter = 1;
  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.RecipeStepNumber = step.StepNo;
  284. currentRecipeResult.RecipeStepType=step.Type.ToString();
  285. currentRecipeResult.RecipeStepSetTime=step.Time;
  286. //currentRecipeResult.RecipeStepDuringTime = (int)_stepTime.ElapsedMilliseconds/1000;
  287. currentRecipeResult.RecipeStepDuringTime = new System.TimeSpan(0, 0, System.Convert.ToInt32(_stepTime.ElapsedMilliseconds/1000));
  288. var result = step.Run();
  289. if(result == RState.Failed)
  290. {
  291. UpdateWaferStatus(false);
  292. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  293. FaEvent.FaPostAlarm(Module.ToString(), $"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  294. return true;
  295. }
  296. else if(result == RState.End || isMaualEndStep == true)
  297. {
  298. if(_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)
  299. _currentRecipe.Steps[_currentStep].End();
  300. if(_currentRecipe.Steps[_currentStep].CycleEnd)
  301. {
  302. if(_loopCounter > 0)
  303. {
  304. _loopCounter--;
  305. currentRecipeResult.RecipeCurrentCounter += 1;
  306. _currentStep = _loopStartStep;
  307. return StartNewStep() != RState.Running;
  308. }
  309. else
  310. {
  311. _bLoopMode = false;
  312. _loopStartStep = 0;
  313. }
  314. }
  315. if (_currentStep < _currentRecipe.Steps.Count - 1|| isMaualEndStep==true)
  316. {
  317. result = RState.End;
  318. isMaualEndStep =false;
  319. _currentStep++;
  320. return StartNewStep() != RState.Running;
  321. }
  322. else
  323. {
  324. Notify($"Recipe:{CurrentRunningRecipe} finished");
  325. FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} finished");
  326. UpdateWaferStatus();
  327. _chamber.EPDRecipeStop();
  328. return !StartNewRecipe();
  329. }
  330. }
  331. return false;
  332. }
  333. private bool ProcessDone()
  334. {
  335. _stepTime.Stop();
  336. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Idle);
  337. CloseAllValves();
  338. _chamber.GeneratorBiasPowerOn(false);
  339. _chamber.GeneratorPowerOn(false);
  340. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  341. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  342. _chamber.OpenValve(ValveType.Guage, true);
  343. _chamber.SetPVPostion(1000);
  344. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  345. ProcessDataRecorder.RecordPrecess(Guid.NewGuid().ToString(), RecipeStartTime, DateTime.Now, CurrentRunningRecipe, "", _chamber.Name, "", "");
  346. return true;
  347. }
  348. private void UpdateWaferStatus(bool bDone = true)
  349. {
  350. if(bDone == false)
  351. {
  352. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Failed);
  353. if(_currentRecipe.Header.Type == RecipeType.Chuck)
  354. {
  355. // set wafer chucked flag even if the chuck recipe failed.
  356. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  357. }
  358. }
  359. switch(_currentRecipe.Header.Type)
  360. {
  361. case RecipeType.Process:
  362. break;
  363. case RecipeType.Chuck:
  364. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);
  365. break;
  366. case RecipeType.DeChuck:
  367. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Completed);
  368. WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Dechucked);
  369. break;
  370. }
  371. }
  372. public void Abort()
  373. {
  374. _chamber.GeneratorBiasPowerOn(false);
  375. _chamber.GeneratorPowerOn(false);
  376. _chamber.TurnPendulumValve(false);
  377. CloseAllValves();
  378. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  379. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  380. }
  381. }
  382. }