示例#1
0
        /// <summary>
        /// Gets the divisor to scale raw data based on resolution. = 1/LSB
        /// </summary>
        /// <param name="res">The resolution.</param>
        /// <returns>System.UInt16.</returns>
        /// <exception cref="ArgumentOutOfRangeException">res - null</exception>
        public static ushort LsbDivisor(AdcResolution res)
        {
            switch (res)
            {
            case AdcResolution.Bit12:
                return(1000);

            case AdcResolution.Bit14:
                return(4000);

            case AdcResolution.Bit16:
                return(16000);

            default:
                throw new ArgumentOutOfRangeException(nameof(res), res, null);
            }
        }
示例#2
0
        /// <summary>
        /// Gets the voltage value corresponding to the least significant bit based on resolution.
        /// </summary>
        /// <param name="res">The resolution.</param>
        /// <returns>System.Double.</returns>
        /// <exception cref="ArgumentOutOfRangeException">res - null</exception>
        public static double LSBValue(AdcResolution res)
        {
            switch (res)
            {
            case AdcResolution.Bit12:
                return(1e-3);

            case AdcResolution.Bit14:
                return(250e-6);

            case AdcResolution.Bit16:
                return(62.5e-6);

            default:
                throw new ArgumentOutOfRangeException(nameof(res), res, null);
            }
        }
示例#3
0
        public static int UpdateFrequency(AdcResolution res)
        {
            switch (res)
            {
            case AdcResolution.Bit12:
                return(240);

            case AdcResolution.Bit14:
                return(60);

            case AdcResolution.Bit16:
                return(15);

            default:
                throw new ArgumentOutOfRangeException(nameof(res), res, null);
            }
        }
示例#4
0
 /// <summary>
 /// Constructs Mcp3427 instance
 /// </summary>
 /// <param name="i2CDevice">I2C device used to communicate with the device</param>
 /// <param name="mode">ADC operation mode</param>
 /// <param name="resolution">ADC resolution</param>
 /// <param name="pgaGain">PGA gain</param>
 public Mcp3427(I2cDevice i2CDevice, AdcMode mode = AdcMode.Continuous, AdcResolution resolution = AdcResolution.Bit12, AdcGain pgaGain = AdcGain.X1)
     : this(i2CDevice)
 {
     SetConfig(0, mode: mode, resolution: resolution, pgaGain: pgaGain);
 }
示例#5
0
 /// <summary>
 /// Constructs ConversionResult instance
 /// </summary>
 /// <param name="channel">ADC channel</param>
 /// <param name="rawData">Raw ADC value</param>
 /// <param name="resolution">ADC resolution</param>
 public ConversionResult(byte channel, short rawData, AdcResolution resolution)
 {
     Channel        = channel;
     RawValue       = rawData;
     VoltageDivisor = Helpers.LsbDivisor(resolution);
 }
示例#6
0
 /// <summary>
 /// Gets the voltage value corresponding to the least significant bit based on resolution.
 /// </summary>
 /// <param name="res">The resolution.</param>
 /// <returns>System.Double.</returns>
 /// <exception cref="ArgumentOutOfRangeException">res - null</exception>
 public static double LSBValue(AdcResolution res) => res switch
 {
示例#7
0
 public static byte SetResolutionBits(byte configByte, AdcResolution resolution)
 {
     return((byte)((configByte & ~Helpers.Masks.ResolutionMask) | (byte)resolution));
 }