/// <summary> /// Creates a new instance of the MCP960X. /// </summary> /// <param name="i2cDevice">The I2C device used for communication.</param> /// <param name="adcMeasurementResolutionType">ADC Measurement Resolution. It defaults to 18bit.</param> /// <param name="burstModeTemperatureSamplesType">Number of Burst Mode Temperature Samples. It defaults to 1 sample.</param> /// <param name="coldJunctionResolutionType">Cold junction resolution. It defaults to 0.0625°C.</param> /// <param name="digitalFilterCoefficientsType">Digital filter. It defaults to MID filter.</param> /// <param name="shutdownModesType">Shutdown Mode. It defaults to Normal operation.</param> /// <param name="thermocoupleType">Thermocouple type. It defaults to K.</param> /// <remarks> /// alerts are disabled /// </remarks> public Mcp960x(I2cDevice i2cDevice, ADCMeasurementResolutionType adcMeasurementResolutionType = ADCMeasurementResolutionType.R18, BurstModeTemperatureSamplesType burstModeTemperatureSamplesType = BurstModeTemperatureSamplesType.S1, ColdJunctionResolutionType coldJunctionResolutionType = ColdJunctionResolutionType.N_0_0625, DigitalFilterCoefficientsType digitalFilterCoefficientsType = DigitalFilterCoefficientsType.N4, ShutdownModesType shutdownModesType = ShutdownModesType.Normal, ThermocoupleType thermocoupleType = ThermocoupleType.K) { _i2cDevice = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice)); int deviceAddress = i2cDevice.ConnectionSettings.DeviceAddress; if (deviceAddress < 0x60 || deviceAddress > 0x67) { throw new ArgumentOutOfRangeException(nameof(i2cDevice), "The MCP960X address must be between 96 (0x60) and 103 (0x67)."); } _adcMeasurementResolutionType = (byte)adcMeasurementResolutionType; _burstModeTemperatureSamplesType = (byte)burstModeTemperatureSamplesType; _coldJunctionResolutionType = (byte)coldJunctionResolutionType; _digitalFilterCoefficientsType = (byte)digitalFilterCoefficientsType; _shutdownModesType = (byte)shutdownModesType; _thermocoupleType = (byte)thermocoupleType; Initialize(); }
/// <summary> /// 电压(V)转换成温度(摄氏) /// </summary> /// <param name="type">热电偶类型,支持B,E,J,K,N,R,S,T</param> /// <param name="voltValue">电压值(V)</param> /// <param name="cjcValue">冷点补偿温度(摄氏),默认25度</param> /// <returns></returns> public static double Convert(ThermocoupleType type, double voltValue, bool enableCJC = true, double cjcValue = 25.0) { switch (type) { case ThermocoupleType.TypeB: return(TC_TypeB.VoltToTemperature(voltValue, enableCJC, cjcValue)); case ThermocoupleType.TypeE: return(TC_TypeE.VoltToTemperature(voltValue, enableCJC, cjcValue)); case ThermocoupleType.TypeJ: return(TC_TypeJ.VoltToTemperature(voltValue, enableCJC, cjcValue)); case ThermocoupleType.TypeK: return(TC_TypeK.VoltToTemperature(voltValue, enableCJC, cjcValue)); case ThermocoupleType.TypeN: return(TC_TypeN.VoltToTemperature(voltValue, enableCJC, cjcValue)); case ThermocoupleType.TypeR: return(TC_TypeR.VoltToTemperature(voltValue, enableCJC, cjcValue)); case ThermocoupleType.TypeS: return(TC_TypeS.VoltToTemperature(voltValue, enableCJC, cjcValue)); case ThermocoupleType.TypeT: return(TC_TypeT.VoltToTemperature(voltValue, enableCJC, cjcValue)); default: return(TC_TypeB.VoltToTemperature(voltValue, enableCJC, cjcValue)); } }
/// <summary> /// Setup for the MAX31856, which sets the chip select pin and the configurations/defaults /// </summary> /// <param name="thermocoupleType">Type of thermocouple based on ThermocoupleType enum</param> /// <param name="averageSamples">Representation of the number of samples to get an average from, range from 0 to 4, which respectively corresponds to 1, 2, 4, 8, or 16 samples (1*(2^averageSamples))</param> /// <param name="gpioController">GpioController specified for this device</param> /// <param name="spiDisplay">SpiDevice specified for this device</param> /// <param name="chipSelectPin">Chip select pin number specified by the device</param> public MAX31856(ref GpioController _gpioController, ref SpiDevice _spiDisplay, int chipSelectPin, ThermocoupleType thermocoupleType = ThermocoupleType.K, int averageSamples = 0) { // Set up device's gpio controller and spi device and chip select pin this.Setup(ref _gpioController, ref _spiDisplay, chipSelectPin); /*** SET UP THE CONFIGURATION AND ALL DEFAULTS FOR THE MAX31856 ***/ // Set the Cold-Junction Temperature Offset to 0 first (important to do before setting up Configuration 0) WriteRegister(MAX31856_REG_WRITE_CJTO, 0x0); // Set Configuration 0 (conversion mode, one-shot mode fault configuration) WriteRegister(MAX31856_REG_WRITE_CR0, 0x82); // 0x80 is for continuous reading, but 0x40 is for one shot reading // Set Configuration 1 (Type of thermocouple, how many samples to average from) // Do some checks on averageSamples: default to 0, make sure it's not more than 4 or less than 0 averageSamples = (averageSamples < 0 || averageSamples > 4) ? 0 : averageSamples; WriteRegister(MAX31856_REG_WRITE_CR1, (byte)((averageSamples << 4) + (int)thermocoupleType)); // Set Fault Mask Register WriteRegister(MAX31856_REG_WRITE_MASK, 0xFF); // Set Cold-Junction Temperature Thresholds (defaults for now) WriteRegister(MAX31856_REG_WRITE_CJHF, 0x7F); WriteRegister(MAX31856_REG_WRITE_CJLF, 0xC0); // Set Linear Temperature Thresholds (defaults for now) WriteRegister(MAX31856_REG_WRITE_LTHFTH, 0x7F); WriteRegister(MAX31856_REG_WRITE_LTHFTL, 0xFF); WriteRegister(MAX31856_REG_WRITE_LTLFTH, 0x80); WriteRegister(MAX31856_REG_WRITE_LTLFTL, 0x00); // Just for testing to see if it accurately sets values to the register var cr0Config = ReadRegister(MAX31856_REG_READ_CR0); var cr1Config = ReadRegister(MAX31856_REG_READ_CR1); var faultMask = ReadRegister(MAX31856_REG_READ_MASK); var coldJunctionThresholds = ReadRegister(MAX31856_REG_READ_CJHF, 2); // Gets MAX31856_REG_READ_CJHF and MAX31856_REG_READ_CJLF var linearTemperatureThresholds = ReadRegister(MAX31856_REG_READ_LTHFTH, 4); // Grabs MAX31856_REG_READ_LTHFTH, MAX31856_REG_READ_LTHFTL, MAX31856_REG_READ_LTLFTH, and MAX31856_REG_READ_LTLFTL var coldJunctionTemperatureOffset = ReadRegister(MAX31856_REG_READ_CJTO); //Verify the defaults var taco = cr0Config; }
public void Configure(ThermocoupleType type, ReferenceJunctionType referenceJunctionType) { Adapter.ViSessionStatusCheck(IviDmmInterop.ConfigureThermocouple(Adapter.Session, DmmThermocoupleType.getC_Value(type), DmmReferenceJunctionType.getC_Value(referenceJunctionType))); }
/// <summary> /// Creates a new instance of the Max31856. /// </summary> /// <param name="spiDevice">The communications channel to a device on a SPI bus</param> /// <param name="thermocoupleType">Thermocouple type. It Defaults to T.</param> public Max31856(SpiDevice spiDevice, ThermocoupleType thermocoupleType = ThermocoupleType.T) { _spiDevice = spiDevice ?? throw new ArgumentNullException(nameof(spiDevice)); _thermocoupleType = (byte)thermocoupleType; Initialize(); }