使用ADS1263内部恒流源,IDAC1=IDAC2=1.5mA
参考电阻使用820ohm
参考下边贴子可以将对应电阻转换为温度
https://bbs.eeworld.com.cn/thread-553748-1-1.html
代码中的公式
resistance = ((double) AdcOutput / gain) / 2147483640.00f * 2.00f * 820.00f;
AdcOutput 是读取到的ADC码,gain是PGA的增益,AdcOutput / gain得到实际RTD两端的电压
2147483640.00f是2^31,32位ADC输出范围是±2147483640
* 2.00f 是因为RTD流过的电流是1.5mA,参考电阻流过的电路是1.5*2=3mA
* 820.00f得到RTD的实际阻值
- double get_resistance(uint8 gain)
- {
- uint8 WriteRegData; //Stores the register write values
- uint8 AdcRegData[ADS126x_NUM_REG]; //Stores the register read values
- int32 AdcOutput = 0;
- uint8 gainBit = 0;
- double resistance;
- //Read ALL registers
- ADS126xReadRegister(ID, ADS126x_NUM_REG, AdcRegData);
-
- //MODE0 (CHOP OFF)
- WriteRegData = (AdcRegData[MODE0] & DELAY_MASK);
- ADS126xWriteRegister(MODE0, 1, &WriteRegData);
-
- //POWER VBIAS OFF
- WriteRegData = (AdcRegData[POWER] & ~VBIAS);
- ADS126xWriteRegister(MODE0, 1, &WriteRegData);
-
- //(IDACMUX) IDAC2 AIN0,IDAC1 AIN3
- WriteRegData = (AdcRegData[(IDACMUX)] & ~(MUX2_MASK | MUX1_MASK)) | MUX2_AIN0 | MUX1_AIN3;
- ADS126xWriteRegister(IDACMUX, 1, &WriteRegData);
-
- //((IDACMAG)) IDAC2 = IDAC1 = 1500uA
- WriteRegData = (AdcRegData[((IDACMAG))] & ~(MAG2_MASK | MAG1_MASK)) | MAG2_1500uA | MAG1_1500uA;
- ADS126xWriteRegister(IDACMAG, 1, &WriteRegData);
-
-
- //MODE2 (BYPASS OFF, GAIN = 1 V/V)
- switch(gain)
- {
- case 1:
- gainBit = 0x00;
- break;
- case 2:
- gainBit = 0x10;
- break;
- case 4:
- gainBit = 0x20;
- break;
- case 8:
- gainBit = 0x30;
- break;
- case 16:
- gainBit = 0x40;
- break;
- case 32:
- gainBit = 0x50;
- break;
- }
- WriteRegData = (AdcRegData[MODE2] & ~(DR_MASK | GAIN_MASK)) | DR_20_SPS | gainBit;
- ADS126xWriteRegister(MODE2, 1, &WriteRegData);
-
- //Reset OFCAL coefficients
- WriteRegData = 0x00;
- ADS126xWriteRegister(OFCAL2, 1, &WriteRegData); //OFCAL2 = 0x00
- WriteRegData = 0x00;
- ADS126xWriteRegister(OFCAL1, 1, &WriteRegData); //OFCAL1 = 0x00
- WriteRegData = 0x00;
- ADS126xWriteRegister(OFCAL0, 1, &WriteRegData); //OFCAL0 = 0x00
-
- //Reset FSCAL coefficients
- WriteRegData = 0x40;
- ADS126xWriteRegister(FSCAL2, 1, &WriteRegData); //FSCAL2 = 0x40
- WriteRegData = 0x00;
- ADS126xWriteRegister(FSCAL1, 1, &WriteRegData); //FSCAL1 = 0x00
- WriteRegData = 0x00;
- ADS126xWriteRegister(FSCAL0, 1, &WriteRegData); //FSCAL0 = 0x00
-
-
- //电阻测量
- //INPMUX (AINP = AIN1, AINN = AIN2)
- WriteRegData = MUXP_AIN1 | MUXN_AIN2;
- ADS126xWriteRegister(INPMUX, 1, &WriteRegData);
-
- //REFMUX AIN4 AIN5
- WriteRegData = RMUXP_AIN4 | RMUXN_AIN5;
- ADS126xWriteRegister(REFMUX, 1, &WriteRegData);
- //Read one conversion
- set_adc_START(1);
- WaitForDRDY();
- set_adc_START(0);
- AdcOutput = ADS126xReadData(6, 1);
- resistance = ((double) AdcOutput / gain) / 2147483640.00f * 2.00f * 820.00f;
-
- return resistance;
- }
ADS1263头文件
本帖最后由 littleshrimp 于 2017-8-25 11:34 编辑