SysAutoCalibration.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Diagnostics;
  8. using Uestc.Auto6.Dso.ComModel;
  9. using System.IO;
  10. namespace Uestc.Auto6.Dso.Hardware.Driver
  11. {
  12. internal class SysAutoCalibration
  13. {
  14. public static SysAutoCalibration Default = new SysAutoCalibration();
  15. private List<Int32> _AcqProcBdLooptimeBySysClockCount = new List<int>() { 0, 0, 0, 0, 0, 0, 0, 0 };//最多8个AcqBoard,其序号是Acqboard Index
  16. public Int32 Trig_AcqProcBdLooptimBySysClockCount(int channelIndex)
  17. {
  18. if (channelIndex >= ChannelIdExt.AnaChnlNum)
  19. channelIndex = 0;
  20. ChannelBdAdcInputDefine? channelBdAdcInputDefine = Hd.currProduct?.Acquirer_AnalogChannel?.GetChannelAcqBdAdcInputCorresponding(channelIndex);
  21. if (channelBdAdcInputDefine != null)
  22. return _AcqProcBdLooptimeBySysClockCount[(int)channelBdAdcInputDefine.BdNo];
  23. else
  24. return _AcqProcBdLooptimeBySysClockCount[0];
  25. }
  26. string fileName_TrigScanAcqProcBdLoopTime = $@"\CaliData\TrigScanAcqProcBdLoopTimeData.txt";
  27. private bool LoadSettingTrigScanAcqProcBdLoopTime()
  28. {
  29. string txtFileName = $@"{AppDomain.CurrentDomain.BaseDirectory}{fileName_TrigScanAcqProcBdLoopTime}";
  30. if (File.Exists(txtFileName))
  31. {
  32. string[] fileContent = File.ReadAllLines(txtFileName);
  33. foreach (string line in fileContent)
  34. {
  35. if (line.Trim() == "" || line[0] == '#' || line.Substring(0, 2) == "//")
  36. continue;
  37. string[] items=line.Split(',');
  38. if (items.Length == 2)
  39. {
  40. AcqBdNo acqBdNo = items[0].Trim() switch
  41. {
  42. "B1"=> AcqBdNo.B1,
  43. "B2" => AcqBdNo.B2,
  44. "B3" => AcqBdNo.B3,
  45. "B4" => AcqBdNo.B4,
  46. "B5" => AcqBdNo.B5,
  47. "B6" => AcqBdNo.B6,
  48. "B7" => AcqBdNo.B7,
  49. "B8" => AcqBdNo.B8,
  50. _ => AcqBdNo.B1,
  51. };
  52. Int32 data = Int32.Parse(items[1]);
  53. _AcqProcBdLooptimeBySysClockCount[(int)acqBdNo] = data;
  54. }
  55. }
  56. }
  57. return false;
  58. }
  59. public void Trig_AcqProcBdLooptime_Cali()
  60. {
  61. if (!Hd.CurrDebugVarints.bEnable_AtStartTrigScanAcqProcBdLoopTime)
  62. {
  63. LoadSettingTrigScanAcqProcBdLoopTime();
  64. return;
  65. }
  66. int acqBoardDefineCount = Hd.currProduct!.AcqBd!.ExistsDefines.Count;
  67. #region 初始化
  68. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestPredepth, 100U);
  69. Hd.currProduct!.AcqBd!.WriteToAllFpga(AcqBdReg.W.TrigCtrl_1st_SourceSelect, 0);
  70. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_holdtime_widthL, 4);
  71. HdIO.WriteReg(ProcBdReg.W.TrigCtrl_1st_PreDepthSetL, 300);
  72. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestPredepth, 300);
  73. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.ChMode_SamplingMode, 2);
  74. HdIO.WriteReg(PcieBdReg.W.RST_CTRL_PcieReset, 0x1);
  75. HdIO.WriteReg(PcieBdReg.W.RST_CTRL_PcieReset, 0x0);
  76. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.FifoCtrl_FullProgDepth, 500);//采集板并行FIFO深度
  77. HdIO.WriteReg(ProcBdReg.W.Dpo_Enable, 0);
  78. HdIO.WriteReg(ProcBdReg.W.Average_Enable, 0);
  79. HdIO.WriteReg(ProcBdReg.W.TrigCtrl_Location_TestModeProEn, 1);
  80. Hd.currProduct!.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 1U);
  81. HdIO.WriteReg(ProcBdReg.W.DBI_SubDataDebugNum, 0xf);
  82. #endregion
  83. for (int acqBdIndex = 0; acqBdIndex < acqBoardDefineCount;
  84. acqBdIndex++)
  85. {
  86. if (Hd.currProduct!.AcqBd!.ExistsDefines[acqBdIndex])
  87. {
  88. HdIO.WriteReg(PcieBdReg.W.RST_CTRL_SysResetFromPcie, 0x1);
  89. Thread.Sleep(1);
  90. HdIO.WriteReg(PcieBdReg.W.RST_CTRL_SysResetFromPcie, 0x0);
  91. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_holdtime_widthL, 4);
  92. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_holdtime_widthH, 0);
  93. HdIO.WriteReg(ProcBdReg.W.FifoCtrl_AcqWriteEnable, 0);
  94. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_1st_CompareVoltage1Down, 0x700);
  95. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_1st_CompareVoltage1Up, 0x900);
  96. HdIO.WriteReg(ProcBdReg.W.TrigCtrl_1st_SourceControl, 0);
  97. HdIO.WriteReg(ProcBdReg.W.TrigCtrl_1st_HoldOffTimeL, 4);
  98. HdIO.WriteReg(ProcBdReg.W.TrigCtrl_Location_TestAcqNum, (UInt32)acqBdIndex);//此处需修改为哪一片采集板 8G 0-1-2-3
  99. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 0U);
  100. Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 1U);
  101. HdIO.WriteReg(ProcBdReg.W.FifoCtrl_AcqWriteEnable, 1);
  102. Thread.Sleep(20);
  103. _AcqProcBdLooptimeBySysClockCount[acqBdIndex] = (Int32)(Hd.currProduct.AcqBd.ReadReg(AcqBdReg.R.TrigCtrl_Location_TrigOffset, (AcqBdNo)acqBdIndex));
  104. HdIO.WriteReg(ProcBdReg.W.FifoCtrl_AcqWriteEnable, 0);
  105. }
  106. }
  107. Hd.currProduct!.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 0U);
  108. HdIO.WriteReg(ProcBdReg.W.TrigCtrl_Location_TestModeProEn, 0);
  109. }
  110. }
  111. }