[资料分享] ADS1263测量三线制PT100(RTD)电阻的配置代码

littleshrimp   2017-8-25 11:28 楼主
使用ADS1263内部恒流源,IDAC1=IDAC2=1.5mA 参考电阻使用820ohm 参考下边贴子可以将对应电阻转换为温度 https://bbs.eeworld.com.cn/thread-553748-1-1.html 参考电路 拷贝.jpg 代码中的公式 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的实际阻值
  1. double get_resistance(uint8 gain)
  2. {
  3. uint8 WriteRegData; //Stores the register write values
  4. uint8 AdcRegData[ADS126x_NUM_REG]; //Stores the register read values
  5. int32 AdcOutput = 0;
  6. uint8 gainBit = 0;
  7. double resistance;
  8. //Read ALL registers
  9. ADS126xReadRegister(ID, ADS126x_NUM_REG, AdcRegData);
  10. //MODE0 (CHOP OFF)
  11. WriteRegData = (AdcRegData[MODE0] & DELAY_MASK);
  12. ADS126xWriteRegister(MODE0, 1, &WriteRegData);
  13. //POWER VBIAS OFF
  14. WriteRegData = (AdcRegData[POWER] & ~VBIAS);
  15. ADS126xWriteRegister(MODE0, 1, &WriteRegData);
  16. //(IDACMUX) IDAC2 AIN0,IDAC1 AIN3
  17. WriteRegData = (AdcRegData[(IDACMUX)] & ~(MUX2_MASK | MUX1_MASK)) | MUX2_AIN0 | MUX1_AIN3;
  18. ADS126xWriteRegister(IDACMUX, 1, &WriteRegData);
  19. //((IDACMAG)) IDAC2 = IDAC1 = 1500uA
  20. WriteRegData = (AdcRegData[((IDACMAG))] & ~(MAG2_MASK | MAG1_MASK)) | MAG2_1500uA | MAG1_1500uA;
  21. ADS126xWriteRegister(IDACMAG, 1, &WriteRegData);
  22. //MODE2 (BYPASS OFF, GAIN = 1 V/V)
  23. switch(gain)
  24. {
  25. case 1:
  26. gainBit = 0x00;
  27. break;
  28. case 2:
  29. gainBit = 0x10;
  30. break;
  31. case 4:
  32. gainBit = 0x20;
  33. break;
  34. case 8:
  35. gainBit = 0x30;
  36. break;
  37. case 16:
  38. gainBit = 0x40;
  39. break;
  40. case 32:
  41. gainBit = 0x50;
  42. break;
  43. }
  44. WriteRegData = (AdcRegData[MODE2] & ~(DR_MASK | GAIN_MASK)) | DR_20_SPS | gainBit;
  45. ADS126xWriteRegister(MODE2, 1, &WriteRegData);
  46. //Reset OFCAL coefficients
  47. WriteRegData = 0x00;
  48. ADS126xWriteRegister(OFCAL2, 1, &WriteRegData); //OFCAL2 = 0x00
  49. WriteRegData = 0x00;
  50. ADS126xWriteRegister(OFCAL1, 1, &WriteRegData); //OFCAL1 = 0x00
  51. WriteRegData = 0x00;
  52. ADS126xWriteRegister(OFCAL0, 1, &WriteRegData); //OFCAL0 = 0x00
  53. //Reset FSCAL coefficients
  54. WriteRegData = 0x40;
  55. ADS126xWriteRegister(FSCAL2, 1, &WriteRegData); //FSCAL2 = 0x40
  56. WriteRegData = 0x00;
  57. ADS126xWriteRegister(FSCAL1, 1, &WriteRegData); //FSCAL1 = 0x00
  58. WriteRegData = 0x00;
  59. ADS126xWriteRegister(FSCAL0, 1, &WriteRegData); //FSCAL0 = 0x00
  60. //电阻测量
  61. //INPMUX (AINP = AIN1, AINN = AIN2)
  62. WriteRegData = MUXP_AIN1 | MUXN_AIN2;
  63. ADS126xWriteRegister(INPMUX, 1, &WriteRegData);
  64. //REFMUX AIN4 AIN5
  65. WriteRegData = RMUXP_AIN4 | RMUXN_AIN5;
  66. ADS126xWriteRegister(REFMUX, 1, &WriteRegData);
  67. //Read one conversion
  68. set_adc_START(1);
  69. WaitForDRDY();
  70. set_adc_START(0);
  71. AdcOutput = ADS126xReadData(6, 1);
  72. resistance = ((double) AdcOutput / gain) / 2147483640.00f * 2.00f * 820.00f;
  73. return resistance;
  74. }
ADS1263头文件
游客,如果您要查看本帖隐藏内容请回复
本帖最后由 littleshrimp 于 2017-8-25 11:34 编辑
虾扯蛋,蛋扯虾,虾扯蛋扯虾

回复评论 (7)

hhh&jjkkkkjjddf
点赞  2017-11-8 00:14
qqwqq
点赞  2017-12-2 23:20
这芯片真心不便宜
点赞  2018-5-14 10:26
感谢分享
点赞  2018-5-19 23:34

感谢分享

点赞  2021-8-5 09:46

谢谢分享

点赞  2023-3-20 00:12

oo

 

点赞  2023-10-7 10:51
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复