Пример #1
0
 public Registers(
     InputGain gain,
     InputDataRate dataRate,
     InputDetectCurrentSources detectCurrentSources,
     bool autoCalibrate,
     bool useInputBuffer)
 {
     Gain                 = gain;
     DataRate             = dataRate;
     DetectCurrentSources = detectCurrentSources;
     AutoCalibrate        = autoCalibrate;
     UseInputBuffer       = useInputBuffer;
     GainFactor           = GetGainFactor();
 }
Пример #2
0
        private byte DetectCurrentSourcesToByteValue(InputDetectCurrentSources detectCurrentSources)
        {
            switch (detectCurrentSources)
            {
            case InputDetectCurrentSources.Off:
                return(0x00);

            case InputDetectCurrentSources.Detect500NanoAmpere:
                return(0x08);

            case InputDetectCurrentSources.Detect2MicroAmpere:
                return(0x10);

            case InputDetectCurrentSources.Detect10MicroAmpere:
                return(0x18);

            default:
                throw new ArgumentOutOfRangeException(nameof(detectCurrentSources), detectCurrentSources, null);
            }
        }
Пример #3
0
        private Registers ReadRegisters(SpiDevice spiDevice)
        {
            WaitDataReady();

            byte[] readRegResponse = new byte[4]; // Make room for Status, Mux, AdControl & AdDataRate

            byte[] readRegRequest =
            {
                Constants.Command.ReadReg,
                (byte)(readRegResponse.Length - 1)
            };

            spiDevice.Write(readRegRequest);

            _timing.WaitMicroseconds(10);

            spiDevice.Read(readRegResponse);

            byte statusRegister = readRegResponse[Constants.Register.Status];
            //byte muxRegister = readRegResponse[Constants.Register.Mux];  <-- The MUX value is not interesting
            byte adControlRegister  = readRegResponse[Constants.Register.AdControl];
            byte adDataRateRegister = readRegResponse[Constants.Register.AdDataRate];

            bool autoCalibrate  = (statusRegister & (1 << Constants.StatusRegister.AutoCalibrateBit)) != 0;
            bool useInputBuffer = (statusRegister & (1 << Constants.StatusRegister.AnalogInputBufferBit)) != 0;

            InputGain inputGain = ByteValueToInputGain((byte)(adControlRegister & 0x07));                                            // Bit 0-2 of the "AdControl" register holds the input gain value
            InputDetectCurrentSources inputDetectCurrentSources = ByteValueToDetectCurrentSources((byte)(adControlRegister & 0x18)); // Bit 3-4 of the "AdControl" register holds the "Detect Current Sources" value

            InputDataRate inputDataRate = ByteValueToInputDataRate(adDataRateRegister);

            return(new Registers(
                       inputGain,
                       inputDataRate,
                       inputDetectCurrentSources,
                       autoCalibrate,
                       useInputBuffer));
        }