123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Uestc.Auto6.Dso.ComModel;
- namespace Uestc.Auto6.Dso.Hardware.Driver
- {
- #region CymometerGateTime
- /// <summary>
- /// 闸门时间可选列表
- /// </summary>
- public enum CymometerGateTime
- {
- Time_4us = 0,
- Time_4ms = 1,
- Time_1s = 2,
- Time_10s = 3,
- };
- #endregion
- /// <summary>
- /// 频率计
- /// </summary>
- public class AbstractAcquirer_Cymometer : AbstractAcquirer
- {
- internal CymometerGateTime _GateTime = CymometerGateTime.Time_1s;
- private const UInt32 MIN_FREQ_200HZ = 200;
- private const UInt32 MIN_PERIOD_200MS = 200000000;
- private const UInt32 FREQ_4NS_CLK = 4;
- internal override void Init()
- {
- Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_GateTimeReset, (UInt32)_GateTime);
- Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 1);
- Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 0);
- }
- internal override bool ReadAcqData()
- {
- return true;
- }
- internal void DoConfig()
- {
- Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_GateTimeReset, (UInt32)_GateTime);
- Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 1);
- Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Cymometer_CymometerReset, 0);
- }
- internal double readbackData = 0;
- private bool ReadData(int whichChannel = 0)
- {
- //int channel = (int)(Hd.CurrHdMessage?.Cymometer.Source ?? ChannelId.C1);
- var channelAcqBdAdcInputCorresponding = Hd.currProduct!.Acquirer_AnalogChannel!.GetChannelAcqBdAdcInputCorresponding(whichChannel);
- AcqBdNo acqBdNo = (channelAcqBdAdcInputCorresponding == null) ? AcqBdNo.B1 : channelAcqBdAdcInputCorresponding.BdNo;
- UInt32 status = 0;
- status = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_MeansureDoneFlag, acqBdNo));
- UInt32 count_l = 0, count_h = 0;
- UInt32 count = 0;
- UInt32 stdcount_l = 0, stdcount_h = 0;
- UInt32 stdcount = 0, count_period = 0;
- UInt32 count_period_l = 0, count_period_h = 0;
- if ((status & 0x0003) != 0)
- {
- count_l = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_FrequenceCountL, acqBdNo));
- count_h = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_FrequenceCountH, acqBdNo));
- count = (0x0000FFFF & count_l) | ((0x0000FFFF & count_h) << 16);
- count *= 1;
- stdcount_l = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_StandardFrequenceCountL, acqBdNo));
- stdcount_h = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_StandardFrequenceCountH, acqBdNo));
- stdcount = (0x0000FFFF & stdcount_l) | ((0x0000FFFF & stdcount_h) << 16);
- count_period_l = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_PeriodCountL, acqBdNo));
- count_period_h = (uint)(Hd.currProduct!.AcqBd!.ReadReg(AcqBdReg.R.Cymometer_PeriodCountH, acqBdNo));
- count_period = (0x0000FFFF & count_period_l) | ((count_period_h & 0x0FFFF) << 16);
- }
- else
- return false;
- if (count < 6249/*MIN_FREQ_200HZ / 8*/)
- {
- if ((status & 0x0002) != 0)
- {
- if ((count_period < MIN_PERIOD_200MS / FREQ_4NS_CLK * 25) && (count_period > 0))
- {
- readbackData = 250.0 * 25 / count_period * Math.Pow(10, 6);
- }
- else
- {
- readbackData = 0.0;
- }
- }
- else
- return false;
- }
- else
- {
- if ((status & 0x0001) != 0)
- {
- readbackData = count / ((stdcount) * 4.0) * Math.Pow(10, 9);
- }
- else
- {
- readbackData = readbackData;
- return false;
- }
- }
- return true;
- }
- /// <summary>
- /// 读取以Hz为单位的频率数。
- /// </summary>
- /// <param name="whichChannel">如果存在多个频率计,则读取指定通道的频率计。-1表示触发通道</param>
- /// <returns>如果读取失败,返回Double.NaN。以Hz为单位</returns>
- public double GetFrequencyByHz(int whichChannel = 0)
- {
- if (ReadData(whichChannel))
- {
- DoConfig();
- return readbackData;
- }
- else
- return readbackData;
- }
- public Int32 GateTime
- {
- get { return (Int32)_GateTime; }
- set
- {
- _GateTime = (CymometerGateTime)value;
- DoConfig();
- }
- }
- internal static void Config() => Hd.currProduct?.Acquirer_Cymometer?.DoConfig();
- }
- }
|