/// <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); } }
/// <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); } }
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); } }
/// <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); }
/// <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); }
/// <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 {
public static byte SetResolutionBits(byte configByte, AdcResolution resolution) { return((byte)((configByte & ~Helpers.Masks.ResolutionMask) | (byte)resolution)); }