예제 #1
0
        private static byte InputDataRateToByteValue(InputDataRate dataRate)
        {
            switch (dataRate)
            {
            case InputDataRate.SampleRate2_5Sps:
                return(0x03);

            case InputDataRate.SampleRate5Sps:
                return(0x13);

            case InputDataRate.SampleRate10Sps:
                return(0x23);

            case InputDataRate.SampleRate15Sps:
                return(0x33);

            case InputDataRate.SampleRate25Sps:
                return(0x43);

            case InputDataRate.SampleRate30Sps:
                return(0x53);

            case InputDataRate.SampleRate50Sps:
                return(0x63);

            case InputDataRate.SampleRate60Sps:
                return(0x72);

            case InputDataRate.SampleRate100Sps:
                return(0x82);

            case InputDataRate.SampleRate500Sps:
                return(0x92);

            case InputDataRate.SampleRate1000Sps:
                return(0xA1);

            case InputDataRate.SampleRate2000Sps:
                return(0xB0);

            case InputDataRate.SampleRate3750Sps:
                return(0xC0);

            case InputDataRate.SampleRate7500Sps:
                return(0xD0);

            case InputDataRate.SampleRate15000Sps:
                return(0xE0);

            case InputDataRate.SampleRate30000Sps:
                return(0xF0);

            default:
                throw new ArgumentOutOfRangeException(nameof(dataRate), dataRate, null);
            }
        }
예제 #2
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();
 }
예제 #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));
        }