ADS1115

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Hallo,
      ich habe da mal einen funktionierenden Code für den 16Bit AD-Wandler ADS1115.
      Netten Gruß Cable


      BASCOM-Quellcode: ADS1115

      1. 'ADS1115 16Bit A/D Wandler
      2. $regfile = "m328pdef.dat"
      3. $crystal = 16000000
      4. $hwstack = 32
      5. $swstack = 32
      6. $framesize = 32
      7. '
      8. Dim N As Byte
      9. Dim High_byte(4) As Byte
      10. Dim Low_byte(4) As Byte
      11. Dim Ads_high(4) As Byte
      12. Dim Ads_low(4) As Byte
      13. Dim Volt(4) As Single
      14. Dim Wert(4) As Integer
      15. Config Sda = Portc.4 'I2C-Pins definieren
      16. Config Scl = Portc.5
      17. Dim Lcd_backlight As Byte
      18. $lib "YwRobot_Lcd_i2c.lIb"
      19. Const Pcf8574_lcd = 64 'Adresse LCD
      20. Config Lcd = 20x4 '40x4,16x1, 16x2, 16x4, 16x4, 20x2, 20x4, 16x1a or 20x4A.
      21. Config I2cdelay = 2
      22. Initlcd 'LCD initialisieren
      23. Cursor Off Noblink 'Noblink , Blink, On, Off
      24. Cls
      25. Waitms 300
      26. 'Adresse ADS1115 Adresspin = low
      27. Const Ads1115_write = &H90
      28. Const Ads1115_read = &H91
      29. 'Const Ad_wert = 1.024 / 32767 '1024
      30. 'Const Ad_wert = 2.048 / 32767 '2048
      31. 'Const Ad_wert = 4.096 / 32767 '4096
      32. Const Ad_wert = 6.144 / 32767 '6144
      33. 'High Byte
      34. 'Bit 15 Operational status
      35. 'When writing
      36. 'No effect = &B0xxxxxxx xxxxxxxx
      37. 'Start a single conversion = &B1xxxxxxx xxxxxxxx
      38. 'When reading
      39. 'Device is currently performing a conversion = &B0xxxxxxx xxxxxxxx
      40. 'Device is not currently performing a conversion = &B1xxxxxxx xxxxxxxx
      41. 'Bit 14..12 Input Multiplexer configuration
      42. 'Ain0+Ain1= &Bx000xxxx xxxxxxxx default
      43. 'Ain0+Ain3= &bx001xxxx xxxxxxxx
      44. 'Ain1+Ain3= &Bx010xxxx xxxxxxxx
      45. 'Ain2+Ain3= &bx011xxxx xxxxxxxx
      46. 'Ain0+GND= &Bx100xxxx xxxxxxxx
      47. 'Ain1+GND= &Bx101xxxx xxxxxxxx
      48. 'Ain2+GND= &Bx110xxxx xxxxxxxx
      49. 'Ain3+GND= &Bx111xxxx xxxxxxxx
      50. 'Bit 11..9 Gain amplifier configuration
      51. 'FSR 6.144V= &Bxxxx000x xxxxxxxx
      52. 'FSR 4.096V= &Bxxxx001x xxxxxxxx
      53. 'FSR 2.048V= &Bxxxx010x xxxxxxxx default
      54. 'FSR 1.024V= &Bxxxx011x xxxxxxxx
      55. 'FSR 0.512V= &Bxxxx100x xxxxxxxx
      56. 'FSR 0.256V= &Bxxxx101x xxxxxxxx
      57. 'FSR 0.256V= &Bxxxx110x xxxxxxxx
      58. 'FSR 0.256V= &Bxxxx111x xxxxxxxx
      59. 'Bit 8 Device operating mode
      60. 'Continuous-conversion mode = &Bxxxxxxx0 xxxxxxxx
      61. 'Single-Shot mode = &Bxxxxxxx1 xxxxxxxx default
      62. '------------------------------------------------------------------------
      63. 'Low Byte
      64. 'Bit 7..5 Data Rate
      65. ' 8SPS= &Bxxxxxxxx 000xxxxx
      66. ' 16SPS= &Bxxxxxxxx 001xxxxx
      67. ' 32SPS= &Bxxxxxxxx 010xxxxx
      68. ' 64SPS= &Bxxxxxxxx 011xxxxx
      69. '128SPS= &Bxxxxxxxx 100xxxxx default
      70. '250SPS= &Bxxxxxxxx 101xxxxx
      71. '475SPS= &Bxxxxxxxx 110xxxxx
      72. '860SPS= &Bxxxxxxxx 111xxxxx
      73. 'Bit 4 Comparator Mode
      74. 'Traditonal = &Bxxxxxxxx xxx0xxxx default
      75. 'Window = &Bxxxxxxxx xxx1xxxx
      76. 'Bit 3 Comparator polarity
      77. 'Active low = &Bxxxxxxxx xxxx0xxx default
      78. 'Active high= &Bxxxxxxxx xxxx1xxx
      79. 'Bit 2 Latching Comparator
      80. 'Nonlatching = &Bxxxxxxxx xxxxx0xx default
      81. 'Latching = &Bxxxxxxxx xxxxx1xx
      82. 'Bit 1.0 Comparator queue and disable
      83. 'Assert after one conversion = &Bxxxxxxxx xxxxxx00
      84. 'Assert after two conversiosn = &Bxxxxxxxx xxxxxx01
      85. 'Assert after four conversions = &Bxxxxxxxx xxxxxx10
      86. 'Disable Comparator = &Bxxxxxxxx xxxxxx11 default
      87. High_byte(1) = &B11000000
      88. High_byte(2) = &B11010000
      89. High_byte(3) = &B11100000
      90. High_byte(4) = &B11110000
      91. Low_byte(1) = &B00000000
      92. Low_byte(2) = &B00000000
      93. Low_byte(3) = &B00000000
      94. Low_byte(4) = &B00000000
      95. '******************* Hauptprogramm *************************************
      96. Do
      97. For N = 1 To 4
      98. Gosub On_ads1115 'ADS1115 auslesen
      99. Wert(n) = 256 * Ads_high(n) : Wert(n) = Wert(n) + Ads_low(n)
      100. Volt(n) = Ad_wert * Wert(n)
      101. Locate N , 1 : Lcd " "
      102. Locate N , 1 : Lcd Fusing(volt(n) , "#.######") ; " Volt"
      103. Waitms 250
      104. Next
      105. Loop
      106. End
      107. '***************** Ende Hauptprogramm **********************************
      108. On_ads1115:
      109. I2cstart
      110. I2cwbyte Ads1115_write
      111. I2cwbyte &B00000001
      112. I2cwbyte High_byte(n)
      113. I2cwbyte Low_byte(n)
      114. I2cstop
      115. I2cstart
      116. I2cwbyte Ads1115_write
      117. I2cwbyte 0
      118. I2cstart
      119. I2cwbyte Ads1115_read
      120. I2crbyte Ads_high(n) , Ack
      121. I2crbyte Ads_low(n) , Nack
      122. I2cstop
      123. Return
      Alles anzeigen
      Versuch macht klug !

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Cable ()

    • Hallo
      gute Arbeit hat mir viel Vorbereitung erspart. Ich habe hier ein GY-ADS1115/ADS1015 Modul auf dem ein ADS1015 verbaut ist. Hier ein etwas angepasste Rohschrift (negative Werte werden nicht berücksichtigt):

      Quellcode

      1. 'ADS1015 12Bit A/D Wandler
      2. $regfile = "m8def.dat"
      3. $crystal = 1000000
      4. $hwstack = 32
      5. $swstack = 32
      6. $framesize = 32
      7. $lib "i2c_twi.lbx"
      8. Config Base = 0 '
      9. Dim N As Byte , High_byte As Byte
      10. Dim Ads_high(4) As Byte
      11. Dim Ads_low(4) As Byte
      12. Dim Volt(4) As Word
      13. Config Sda = Portc.4 'I2C-Pins definieren
      14. Config Scl = Portc.5
      15. $lib "YwRobot_Lcd_i2c.lib"
      16. Const Pcf8574_lcd = &H7E 'Adresse LCD
      17. Config Lcd = 20x4 '40x4,16x1, 16x2, 16x4, 16x4, 20x2, 20x4, 16x1a or 20x4A.
      18. Config Twi = 40000 'Normal 100000=100kHz
      19. Dim Lcd_backlight As Byte
      20. Initlcd 'LCD initialisieren
      21. Cursor Off Noblink 'Noblink , Blink, On, Off
      22. Cls
      23. Waitms 100
      24. 'Adresse ADS1115 Adresspin = low
      25. Const Ads1115_write = &H90
      26. Const Ads1115_read = &H91
      27. 'Const Ad_wert = 1.024 / 32767 '1024
      28. 'Const Ad_wert = 2.048 / 32767 '2048
      29. 'Const Ad_wert = 4.096 / 32767 '4096
      30. 'Const Ad_wert = 6.144 / 32767 '6144
      31. 'High Byte
      32. 'Bit 15 Operational status
      33. 'When writing
      34. 'No effect = &B0xxxxxxx xxxxxxxx
      35. 'Start a single conversion = &B1xxxxxxx xxxxxxxx
      36. 'When reading
      37. 'Device is currently performing a conversion = &B0xxxxxxx xxxxxxxx
      38. 'Device is not currently performing a conversion = &B1xxxxxxx xxxxxxxx
      39. 'Bit 14..12 Input Multiplexer configuration
      40. 'Ain0+Ain1= &Bx000xxxx xxxxxxxx default
      41. 'Ain0+Ain3= &bx001xxxx xxxxxxxx
      42. 'Ain1+Ain3= &Bx010xxxx xxxxxxxx
      43. 'Ain2+Ain3= &bx011xxxx xxxxxxxx
      44. 'Ain0+GND= &Bx100xxxx xxxxxxxx - Auswahl (11 nutzbare Bits)
      45. 'Ain1+GND= &Bx101xxxx xxxxxxxx -
      46. 'Ain2+GND= &Bx110xxxx xxxxxxxx -
      47. 'Ain3+GND= &Bx111xxxx xxxxxxxx -
      48. 'Bit 11..9 Gain amplifier configuration
      49. 'FSR 6.144V= &Bxxxx000x xxxxxxxx
      50. 'FSR 4.096V= &Bxxxx001x xxxxxxxx - ausgewählt 4,095V= 0111 111 1110 000
      51. 'FSR 2.048V= &Bxxxx010x xxxxxxxx default
      52. 'FSR 1.024V= &Bxxxx011x xxxxxxxx
      53. 'FSR 0.512V= &Bxxxx100x xxxxxxxx
      54. 'FSR 0.256V= &Bxxxx101x xxxxxxxx
      55. 'FSR 0.256V= &Bxxxx110x xxxxxxxx
      56. 'FSR 0.256V= &Bxxxx111x xxxxxxxx
      57. 'Bit 8 Device operating mode
      58. 'Continuous-conversion mode = &Bxxxxxxx0 xxxxxxxx
      59. 'Single-Shot mode = &Bxxxxxxx1 xxxxxxxx default -ausgewählt
      60. '------------------------------------------------------------------------
      61. 'Low Byte
      62. 'Bit 7..5 Data Rate
      63. ' 8SPS= &Bxxxxxxxx 000xxxxx
      64. ' 16SPS= &Bxxxxxxxx 001xxxxx
      65. ' 32SPS= &Bxxxxxxxx 010xxxxx
      66. ' 64SPS= &Bxxxxxxxx 011xxxxx
      67. '128SPS= &Bxxxxxxxx 100xxxxx default -behalten
      68. '250SPS= &Bxxxxxxxx 101xxxxx
      69. '475SPS= &Bxxxxxxxx 110xxxxx
      70. '860SPS= &Bxxxxxxxx 111xxxxx
      71. 'Bit 4 Comparator Mode
      72. 'Traditonal = &Bxxxxxxxx xxx0xxxx default -behalten
      73. 'Window = &Bxxxxxxxx xxx1xxxx
      74. 'Bit 3 Comparator polarity
      75. 'Active low = &Bxxxxxxxx xxxx0xxx default -behalten
      76. 'Active high= &Bxxxxxxxx xxxx1xxx
      77. 'Bit 2 Latching Comparator
      78. 'Nonlatching = &Bxxxxxxxx xxxxx0xx default -behalten
      79. 'Latching = &Bxxxxxxxx xxxxx1xx
      80. 'Bit 1.0 Comparator queue and disable
      81. 'Assert after one conversion = &Bxxxxxxxx xxxxxx00
      82. 'Assert after two conversiosn = &Bxxxxxxxx xxxxxx01
      83. 'Assert after four conversions = &Bxxxxxxxx xxxxxx10
      84. 'Disable Comparator = &Bxxxxxxxx xxxxxx11 default -behalten
      85. '******************* Hauptprogramm *************************************
      86. Do
      87. For N = 0 To 3
      88. Incr N
      89. Locate N , 1
      90. Decr N
      91. High_byte = N * 16 'Eingang wählen
      92. High_byte = High_byte + &B11000011 ' '
      93. Gosub On_ads1115 'ADS1115 auslesen
      94. Shift Ads_low(n) , Right , 3 'Low /8
      95. Volt(n) = 32 * Ads_high(n) 'High *32
      96. Volt(n) = Volt(n) + Ads_low(n) '
      97. Lcd "Eingang " ; N ; " = "
      98. Lcd Volt(n) ; "mV "
      99. Waitms 250
      100. Next
      101. Loop
      102. End
      103. '***************** Ende Hauptprogramm **********************************
      104. On_ads1115:
      105. I2cstart
      106. I2cwbyte Ads1115_write
      107. I2cwbyte 1 'wähle Config Register
      108. I2cwbyte High_byte
      109. I2cwbyte &B10000011 'Low_byte Comparator ausgeschaltet
      110. I2cstop
      111. Waitms 20 'Warte auf Convertierung
      112. I2cstart
      113. I2cwbyte Ads1115_write
      114. I2cwbyte 0 'wähle ADC-Daten
      115. I2cstart
      116. I2cwbyte Ads1115_read
      117. I2crbyte Ads_high(n) , Ack
      118. I2crbyte Ads_low(n) , Nack
      119. I2cstop
      120. Return
      Alles anzeigen
      Zwischen der Anforderung und dem Einlesen muß die Convertierungszeit gewartet werden sonst ließt man den vorherigen Wert.