123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using Uestc.Auto6.Dso.ComModel;
- using System.IO;
- namespace Uestc.Auto6.Dso.Hardware.Driver
- {
- internal class SysAutoCalibration
- {
- public static SysAutoCalibration Default = new SysAutoCalibration();
- private List<Int32> _AcqProcBdLooptimeBySysClockCount = new List<int>() { 0, 0, 0, 0, 0, 0, 0, 0 };//最多8个AcqBoard,其序号是Acqboard Index
- public Int32 Trig_AcqProcBdLooptimBySysClockCount(int channelIndex)
- {
- if (channelIndex >= ChannelIdExt.AnaChnlNum)
- channelIndex = 0;
- ChannelBdAdcInputDefine? channelBdAdcInputDefine = Hd.currProduct?.Acquirer_AnalogChannel?.GetChannelAcqBdAdcInputCorresponding(channelIndex);
- if (channelBdAdcInputDefine != null)
- return _AcqProcBdLooptimeBySysClockCount[(int)channelBdAdcInputDefine.BdNo];
- else
- return _AcqProcBdLooptimeBySysClockCount[0];
- }
- string fileName_TrigScanAcqProcBdLoopTime = $@"\CaliData\TrigScanAcqProcBdLoopTimeData.txt";
- private bool LoadSettingTrigScanAcqProcBdLoopTime()
- {
- string txtFileName = $@"{AppDomain.CurrentDomain.BaseDirectory}{fileName_TrigScanAcqProcBdLoopTime}";
- if (File.Exists(txtFileName))
- {
- string[] fileContent = File.ReadAllLines(txtFileName);
- foreach (string line in fileContent)
- {
- if (line.Trim() == "" || line[0] == '#' || line.Substring(0, 2) == "//")
- continue;
- string[] items=line.Split(',');
- if (items.Length == 2)
- {
- AcqBdNo acqBdNo = items[0].Trim() switch
- {
- "B1"=> AcqBdNo.B1,
- "B2" => AcqBdNo.B2,
- "B3" => AcqBdNo.B3,
- "B4" => AcqBdNo.B4,
- "B5" => AcqBdNo.B5,
- "B6" => AcqBdNo.B6,
- "B7" => AcqBdNo.B7,
- "B8" => AcqBdNo.B8,
- _ => AcqBdNo.B1,
- };
- Int32 data = Int32.Parse(items[1]);
- _AcqProcBdLooptimeBySysClockCount[(int)acqBdNo] = data;
- }
- }
- }
- return false;
- }
- public void Trig_AcqProcBdLooptime_Cali()
- {
- if (!Hd.CurrDebugVarints.bEnable_AtStartTrigScanAcqProcBdLoopTime)
- {
- LoadSettingTrigScanAcqProcBdLoopTime();
- return;
- }
- int acqBoardDefineCount = Hd.currProduct!.AcqBd!.ExistsDefines.Count;
- #region 初始化
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestPredepth, 100U);
- Hd.currProduct!.AcqBd!.WriteToAllFpga(AcqBdReg.W.TrigCtrl_1st_SourceSelect, 0);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_holdtime_widthL, 4);
- HdIO.WriteReg(ProcBdReg.W.TrigCtrl_1st_PreDepthSetL, 300);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestPredepth, 300);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.ChMode_SamplingMode, 2);
- HdIO.WriteReg(PcieBdReg.W.RST_CTRL_PcieReset, 0x1);
- HdIO.WriteReg(PcieBdReg.W.RST_CTRL_PcieReset, 0x0);
- Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.FifoCtrl_FullProgDepth, 500);//采集板并行FIFO深度
- HdIO.WriteReg(ProcBdReg.W.Dpo_Enable, 0);
- HdIO.WriteReg(ProcBdReg.W.Average_Enable, 0);
- HdIO.WriteReg(ProcBdReg.W.TrigCtrl_Location_TestModeProEn, 1);
- Hd.currProduct!.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 1U);
- HdIO.WriteReg(ProcBdReg.W.DBI_SubDataDebugNum, 0xf);
- #endregion
- for (int acqBdIndex = 0; acqBdIndex < acqBoardDefineCount;
- acqBdIndex++)
- {
- if (Hd.currProduct!.AcqBd!.ExistsDefines[acqBdIndex])
- {
- HdIO.WriteReg(PcieBdReg.W.RST_CTRL_SysResetFromPcie, 0x1);
- Thread.Sleep(1);
- HdIO.WriteReg(PcieBdReg.W.RST_CTRL_SysResetFromPcie, 0x0);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_holdtime_widthL, 4);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_holdtime_widthH, 0);
- HdIO.WriteReg(ProcBdReg.W.FifoCtrl_AcqWriteEnable, 0);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_1st_CompareVoltage1Down, 0x700);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_1st_CompareVoltage1Up, 0x900);
- HdIO.WriteReg(ProcBdReg.W.TrigCtrl_1st_SourceControl, 0);
- HdIO.WriteReg(ProcBdReg.W.TrigCtrl_1st_HoldOffTimeL, 4);
- HdIO.WriteReg(ProcBdReg.W.TrigCtrl_Location_TestAcqNum, (UInt32)acqBdIndex);//此处需修改为哪一片采集板 8G 0-1-2-3
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 0U);
- Hd.currProduct.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 1U);
- HdIO.WriteReg(ProcBdReg.W.FifoCtrl_AcqWriteEnable, 1);
- Thread.Sleep(20);
- _AcqProcBdLooptimeBySysClockCount[acqBdIndex] = (Int32)(Hd.currProduct.AcqBd.ReadReg(AcqBdReg.R.TrigCtrl_Location_TrigOffset, (AcqBdNo)acqBdIndex));
- HdIO.WriteReg(ProcBdReg.W.FifoCtrl_AcqWriteEnable, 0);
- }
- }
- Hd.currProduct!.AcqBd.WriteToAllFpga(AcqBdReg.W.TrigCtrl_Location_TestModeEn, 0U);
- HdIO.WriteReg(ProcBdReg.W.TrigCtrl_Location_TestModeProEn, 0);
- }
- }
- }
|