ads1118example.ino 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Example for Arduino Library for Texas Instruments ADS1118 - 16-Bit Analog-to-Digital Converter with
  3. * Internal Reference and Temperature Sensor
  4. *
  5. * @author Alvaro Salazar <alvaro@denkitronik.com>
  6. * http://www.denkitronik.com
  7. *
  8. */
  9. #include "ADS1118.h"
  10. #include <SPI.h>
  11. //Definition of the Arduino pin to be used as the chip select pin (SPI CS pin). Example: pin 5
  12. #define CS 5
  13. //Creating an ADS1118 object (object's name is ads1118)
  14. ADS1118 ads1118(CS);
  15. void setup(){
  16. Serial.begin(115200);
  17. ads1118.begin(); //Initialize the ADS1118. Default setting: PULLUP RESISTOR, ADC MODE, RATE 8SPS, SINGLE SHOT, ±0.256V, DIFFERENTIAL AIN0-AIN1
  18. /*
  19. * EXAMPLES:
  20. * The lines above in this method are needed only if you want to change the default setting. Use them to fit your needs
  21. * If you need to take care of noise and the ENOB (Effective Number of Bits) see the tables at the end of this file
  22. */
  23. /* Changing the sampling rate.
  24. Available values: RATE_8SPS, RATE_16SPS, RATE_32SPS, RATE_64SPS, RATE_128SPS, RATE_250SPS, RATE_475SPS, RATE_860SPS */
  25. ads1118.setSamplingRate(ads1118.RATE_8SPS); //Using the setter method to change the sampling rate
  26. //ads1118.configRegister.bits.rate=ads1118.RATE_8SPS; //Driving the config register directly. Uncomment if you want to use this way
  27. /* Changing the input selected.
  28. Available values: Diferential inputs: DIFF_0_1, DIFF_0_3, DIFF_1_3, DIFF_2_3.
  29. Single ended input: AIN_0, AIN_1, AIN_2, AIN_3*/
  30. ads1118.setInputSelected(ads1118.DIFF_0_1); //Using the setter method to change the input selected
  31. //ads1118.configRegister.bits.mux=ads1118.DIFF_0_1; //Driving the config register directly. Uncomment if you want to use this way
  32. /* Changing the full scale range.
  33. Available values: FSR_6144 (±6.144V)*, FSR_4096(±4.096V)*, FSR_2048(±2.048V), FSR_1024(±1.024V), FSR_0512(±0.512V), FSR_0256(±0.256V).
  34. (*) No more than VDD + 0.3 V must be applied to this device. */
  35. ads1118.setFullScaleRange(ads1118.FSR_0256); //Using the setter method to change the full scale range
  36. //ads1118.configRegister.bits.pga=ads1118.FSR_0256; //Driving the config register directly. Uncomment if you want to use this way
  37. /* Setting to continuous conversion mode */
  38. ads1118.setContinuousMode(); //Using the setter method to set it to continuous mode
  39. //ads1118.configRegister.bits.operatingMode=CONTINUOUS; //Driving the config register directly. Uncomment if you want to use this way
  40. /* Setting to single shot conversion mode */
  41. ads1118.setSingleShotMode(); //Using the setter method to set it to "single shot conversion and power down" mode
  42. //ads1118.configRegister.bits.operatingMode=SINGLE_SHOT;//Driving the config register directly. Uncomment if you want to use this way
  43. /* Disabling the pull-up resistor */
  44. ads1118.disablePullup(); //Using the setter method to disable the pull-up resistor in Dout
  45. //ads1118.configRegister.bits.pullUp=PULLUP; //Driving the config register directly. Uncomment if you want to use this way
  46. /* Enabling the pull-up resistor */
  47. ads1118.enablePullup(); //Using the setter method to enable the pull-up resistor in Dout
  48. //ads1118.configRegister.bits.pullUp=NO_PULLUP; //Driving the config register directly. Uncomment if you want to use this way
  49. }
  50. void loop(){
  51. Serial.println(String(ads1118.getTemperature(),6)+" C"); //Getting temperature
  52. Serial.println(String(ads1118.getMilliVolts(),10)+"mV"); //Getting millivolts measured in the input selected
  53. //Serial.println(String(ads1118.getMilliVolts(ads1118.DIFF_0_1),10)+"mV"); //Specifying the input to be selected
  54. delay(200); //You can use a delay to save power. The ADS1118 will be in power down state during all the delay time. Optional
  55. }
  56. /*
  57. Table 1. Noise in μVRMS (μVPP) at VDD = 3.3 V [1]
  58. DATA RATE FSR (Full-Scale Range)
  59. (SPS) ±6.144 V ±4.096 V ±2.048 V ±1.024 V ±0.512 V ±0.256 V
  60. 8 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
  61. 16 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
  62. 32 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
  63. 64 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
  64. 128 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (12.35)
  65. 250 187.5 (252.09) 125 (148.28) 62.5 (84.03) 31.25 (39.54) 15.62 (16.06) 7.81 (18.53)
  66. 475 187.5 (266.92) 125 (227.38) 62.5 (79.08) 31.25 (56.84) 15.62 (32.13) 7.81 (25.95)
  67. 860 187.5 (430.06) 125 (266.93) 62.5 (118.63) 31.25 (64.26) 15.62 (40.78) 7.81 (35.83)
  68. Table 2. ENOB from RMS Noise (Noise-Free Bits from Peak-to-Peak Noise) at VDD = 3.3 V
  69. DATA RATE FSR (Full-Scale Range)
  70. (SPS) ±6.144 V ±4.096 V ±2.048 V ±1.024 V ±0.512 V ±0.256 V
  71. 8 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
  72. 16 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
  73. 32 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
  74. 64 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
  75. 128 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (15.33)
  76. 250 16 (15.57) 16 (15.75) 16 (15.57) 16 (15.66) 16 (15.96) 16 (14.75)
  77. 475 16 (15.49) 16 (15.13) 16 (15.66) 16 (15.13) 16 (14.95) 16 (14.26)
  78. 860 16 (14.8) 16 (14.9) 16 (15.07) 16 (14.95) 16 (14.61) 16 (13.8)
  79. [1] Texas Instruments, "ADS1118 Ultrasmall, Low-Power, SPI™-Compatible, 16-Bit Analog-to-Digital
  80. Converter with Internal Reference and Temperature Sensor", ADS1118 datasheet, SBAS457E [OCTOBER 2010–REVISED OCTOBER 2015].
  81. Note: This information is taken from http://www.ti.com
  82. Copyright © 2010–2015, Texas Instruments Incorporated
  83. */