找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6664|回复: 2
收起左侧

ADS1115引脚图电路图与arduino源程序及pdf资料手册下载

[复制链接]
ID:372825 发表于 2018-7-16 20:15 | 显示全部楼层 |阅读模式
ADS1115资料,了解一下
0.png

ADS1115引脚图:
0.png 0.png

ADS1115管脚功能描述:
0.png

ADS1115框图:
0.png

ADS1115电路图:
0.png

arduino源程序如下:
  1. /**************************************************************************/
  2. /*!
  3.     @file     Adafruit_ADS1015.cpp
  4.     @author   K.Townsend (Adafruit Industries)
  5.     @license  BSD (see license.txt)

  6.     Driver for the ADS1015/ADS1115 ADC

  7.     This is a library for the Adafruit MPL115A2 breakout

  8.     Adafruit invests time and resources providing this open source code,
  9.     please support Adafruit and open-source hardware by purchasing
  10.     products from Adafruit!

  11.     @section  HISTORY

  12.     v1.0 - First release
  13. */
  14. /**************************************************************************/
  15. #if ARDUINO >= 100
  16. #include "Arduino.h"
  17. #else
  18. #include "WProgram.h"
  19. #endif

  20. #include <Wire.h>

  21. #include "Adafruit_ADS1015.h"

  22. /**************************************************************************/
  23. /*!
  24.     @brief  Abstract away platform differences in Arduino wire library
  25. */
  26. /**************************************************************************/
  27. static uint8_t i2cread(void) {
  28.   #if ARDUINO >= 100
  29.   return Wire.read();
  30.   #else
  31.   return Wire.receive();
  32.   #endif
  33. }

  34. /**************************************************************************/
  35. /*!
  36.     @brief  Abstract away platform differences in Arduino wire library
  37. */
  38. /**************************************************************************/
  39. static void i2cwrite(uint8_t x) {
  40.   #if ARDUINO >= 100
  41.   Wire.write((uint8_t)x);
  42.   #else
  43.   Wire.send(x);
  44.   #endif
  45. }

  46. /**************************************************************************/
  47. /*!
  48.     @brief  Writes 16-bits to the specified destination register
  49. */
  50. /**************************************************************************/
  51. static void writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value) {
  52.   Wire.beginTransmission(i2cAddress);
  53.   i2cwrite((uint8_t)reg);
  54.   i2cwrite((uint8_t)(value>>8));
  55.   i2cwrite((uint8_t)(value & 0xFF));
  56.   Wire.endTransmission();
  57. }

  58. /**************************************************************************/
  59. /*!
  60.     @brief  Writes 16-bits to the specified destination register
  61. */
  62. /**************************************************************************/
  63. static uint16_t readRegister(uint8_t i2cAddress, uint8_t reg) {
  64.   Wire.beginTransmission(i2cAddress);
  65.   i2cwrite(ADS1015_REG_POINTER_CONVERT);
  66.   Wire.endTransmission();
  67.   Wire.requestFrom(i2cAddress, (uint8_t)2);
  68.   return ((i2cread() << 8) | i2cread());  
  69. }

  70. /**************************************************************************/
  71. /*!
  72.     @brief  Instantiates a new ADS1015 class w/appropriate properties
  73. */
  74. /**************************************************************************/
  75. Adafruit_ADS1015::Adafruit_ADS1015(uint8_t i2cAddress)
  76. {
  77.    m_i2cAddress = i2cAddress;
  78.    m_conversionDelay = ADS1015_CONVERSIONDELAY;
  79.    m_bitShift = 4;
  80.    m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
  81. }

  82. /**************************************************************************/
  83. /*!
  84.     @brief  Instantiates a new ADS1115 class w/appropriate properties
  85. */
  86. /**************************************************************************/
  87. Adafruit_ADS1115::Adafruit_ADS1115(uint8_t i2cAddress)
  88. {
  89.    m_i2cAddress = i2cAddress;
  90.    m_conversionDelay = ADS1115_CONVERSIONDELAY;
  91.    m_bitShift = 0;
  92.    m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
  93. }

  94. /**************************************************************************/
  95. /*!
  96.     @brief  Sets up the HW (reads coefficients values, etc.)
  97. */
  98. /**************************************************************************/
  99. void Adafruit_ADS1015::begin() {
  100.   Wire.begin();
  101. }

  102. /**************************************************************************/
  103. /*!
  104.     @brief  Sets the gain and input voltage range
  105. */
  106. /**************************************************************************/
  107. void Adafruit_ADS1015::setGain(adsGain_t gain)
  108. {
  109.   m_gain = gain;
  110. }

  111. /**************************************************************************/
  112. /*!
  113.     @brief  Gets a gain and input voltage range
  114. */
  115. /**************************************************************************/
  116. adsGain_t Adafruit_ADS1015::getGain()
  117. {
  118.   return m_gain;
  119. }

  120. /**************************************************************************/
  121. /*!
  122.     @brief  Gets a single-ended ADC reading from the specified channel
  123. */
  124. /**************************************************************************/
  125. uint16_t Adafruit_ADS1015::readADC_SingleEnded(uint8_t channel) {
  126.   if (channel > 3)
  127.   {
  128.     return 0;
  129.   }
  130.   
  131.   // Start with default values
  132.   uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)
  133.                     ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)
  134.                     ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)
  135.                     ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)
  136.                     ADS1015_REG_CONFIG_DR_1600SPS   | // 1600 samples per second (default)
  137.                     ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)

  138.   // Set PGA/voltage range
  139.   config |= m_gain;

  140.   // Set single-ended input channel
  141.   switch (channel)
  142.   {
  143.     case (0):
  144.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
  145.       break;
  146.     case (1):
  147.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
  148.       break;
  149.     case (2):
  150.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
  151.       break;
  152.     case (3):
  153.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
  154.       break;
  155.   }

  156.   // Set 'start single-conversion' bit
  157.   config |= ADS1015_REG_CONFIG_OS_SINGLE;

  158.   // Write config register to the ADC
  159.   writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);

  160.   // Wait for the conversion to complete
  161.   delay(m_conversionDelay);

  162.   // Read the conversion results
  163.   // Shift 12-bit results right 4 bits for the ADS1015
  164.   return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;  
  165. }

  166. /**************************************************************************/
  167. /*!
  168.     @brief  Reads the conversion results, measuring the voltage
  169.             difference between the P (AIN0) and N (AIN1) input.  Generates
  170.             a signed value since the difference can be either
  171.             positive or negative.
  172. */
  173. /**************************************************************************/
  174. int16_t Adafruit_ADS1015::readADC_Differential_0_1() {
  175.   // Start with default values
  176.   uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)
  177.                     ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)
  178.                     ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)
  179.                     ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)
  180.                     ADS1015_REG_CONFIG_DR_1600SPS   | // 1600 samples per second (default)
  181.                     ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)

  182.   // Set PGA/voltage range
  183.   config |= m_gain;
  184.                     
  185.   // Set channels
  186.   config |= ADS1015_REG_CONFIG_MUX_DIFF_0_1;          // AIN0 = P, AIN1 = N

  187.   // Set 'start single-conversion' bit
  188.   config |= ADS1015_REG_CONFIG_OS_SINGLE;

  189.   // Write config register to the ADC
  190.   writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);

  191.   // Wait for the conversion to complete
  192.   delay(m_conversionDelay);

  193.   // Read the conversion results
  194.   uint16_t res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
  195.   if (m_bitShift == 0)
  196.   {
  197.     return (int16_t)res;
  198.   }
  199.   else
  200.   {
  201.     // Shift 12-bit results right 4 bits for the ADS1015,
  202.     // making sure we keep the sign bit intact
  203.     if (res > 0x07FF)
  204.     {
  205.       // negative number - extend the sign to 16th bit
  206.       res |= 0xF000;
  207.     }
  208.     return (int16_t)res;
  209.   }
  210. }

  211. /**************************************************************************/
  212. /*!
  213.     @brief  Reads the conversion results, measuring the voltage
  214.             difference between the P (AIN2) and N (AIN3) input.  Generates
  215.             a signed value since the difference can be either
  216.             positive or negative.
  217. */
  218. /**************************************************************************/
  219. int16_t Adafruit_ADS1015::readADC_Differential_2_3() {
  220.   // Start with default values
  221.   uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)
  222.                     ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)
  223.                     ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)
  224.                     ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)
  225.                     ADS1015_REG_CONFIG_DR_1600SPS   | // 1600 samples per second (default)
  226.                     ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)

  227.   // Set PGA/voltage range
  228.   config |= m_gain;

  229.   // Set channels
  230.   config |= ADS1015_REG_CONFIG_MUX_DIFF_2_3;          // AIN2 = P, AIN3 = N

  231.   // Set 'start single-conversion' bit
  232.   config |= ADS1015_REG_CONFIG_OS_SINGLE;

  233.   // Write config register to the ADC
  234.   writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);

  235.   // Wait for the conversion to complete
  236.   delay(m_conversionDelay);

  237.   // Read the conversion results
  238.   uint16_t res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
  239.   if (m_bitShift == 0)
  240.   {
  241.     return (int16_t)res;
  242.   }
  243.   else
  244.   {
  245.     // Shift 12-bit results right 4 bits for the ADS1015,
  246.     // making sure we keep the sign bit intact
  247.     if (res > 0x07FF)
  248.     {
  249.       // negative number - extend the sign to 16th bit
  250.       res |= 0xF000;
  251.     }
  252.     return (int16_t)res;
  253.   }
  254. }

  255. /**************************************************************************/
  256. /*!
  257.     @brief  Sets up the comparator to operate in basic mode, causing the
  258.             ALERT/RDY pin to assert (go from high to low) when the ADC
  259.             value exceeds the specified threshold.

  260.             This will also set the ADC in continuous conversion mode.
  261. */
  262. /**************************************************************************/
  263. void Adafruit_ADS1015::startComparator_SingleEnded(uint8_t channel, int16_t threshold)
  264. {
  265.   // Start with default values
  266.   uint16_t config = ADS1015_REG_CONFIG_CQUE_1CONV   | // Comparator enabled and asserts on 1 match
  267.                     ADS1015_REG_CONFIG_CLAT_LATCH   | // Latching mode
  268.                     ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)
  269.                     ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)
  270.                     ADS1015_REG_CONFIG_DR_1600SPS   | // 1600 samples per second (default)
  271.                     ADS1015_REG_CONFIG_MODE_CONTIN  | // Continuous conversion mode
  272.                     ADS1015_REG_CONFIG_MODE_CONTIN;   // Continuous conversion mode

  273.   // Set PGA/voltage range
  274.   config |= m_gain;
  275.                     
  276.   // Set single-ended input channel
  277.   switch (channel)
  278.   {
  279.     case (0):
  280.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
  281.       break;
  282.     case (1):
  283.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
  284.       break;
  285.     case (2):
  286.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
  287.       break;
  288.     case (3):
  289.       config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
  290.       break;
  291.   }

  292. ……………………

  293. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载(内含资料手册):
ADS1115,ADS1015资料.zip (1.4 MB, 下载次数: 47)
回复

使用道具 举报

ID:389852 发表于 2018-9-3 10:01 | 显示全部楼层
最近在做这个啊,就是老感觉采样速度不行,该配置的都配置了,郁闷
回复

使用道具 举报

ID:64765 发表于 2019-10-13 16:51 | 显示全部楼层
好资料,学习了,谢谢分享。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表