This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS122C04: ADC reading photodiode Constant Output. Interacing ADC with raspberry pi 4 using I2C.Review Circuit and code.

Part Number: ADS122C04

Hii,

I am trying to read photodiode value using ADS122C04 using raspberry pi4 with i2c.But i am getting constant output as change in input(Photodiode value).

Please correct me if any change in circuit i am using following circuit..

The following is the library for ADS122C04 i am using 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import RPi.GPIO as GPIO
from time import sleep
from smbus2 import SMBus, i2c_msg
class ADS122C04:
CMD_RESET = 0x06
CMD_START_SYNC = 0x08
CMD_POWERDOWN = 0x02
CMD_RDATA = 0x10
CMD_RREG = 0x20
CMD_WREG = 0x40
MUX_MASK = 0x1F
MUX_DIF_0_1 = 0x00
MUX_DIF_0_2 = 0x10
MUX_DIF_0_3 = 0x20
MUX_DIF_1_0 = 0x30
MUX_DIF_1_2 = 0x40
MUX_DIF_1_3 = 0x50
MUX_DIF_2_3 = 0x60
MUX_DIF_3_2 = 0x70
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This is code i am using

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from time import sleep
from ADS122C04_lib import ADS122C04
ads=ADS122C04( rdyPin=4 )
ads.reset()
ads.config(ads.MUX_SINGLE_2, ads.GAIN_1, ads.DATA_RATE_90SPS, ads.MODE_CONTINUOUS, ads.VREF_EXTERNAL, ads.PGA_DISABLED, ads.OP_MODE_NORMAL, ads.TEMP_SENSOR_OFF, ads.DCNT_DISABLE, ads.CRC_DISABLED, ads.BURN_OUT_CURRENT_OFF, ads.IDAC_CURRENT_OFF, ads.IDAC1_DISABLED, ads.IDAC2_DISABLED)
ads.start()
try:
while True:
result = ads.result()
print(result)
sleep(1) # Adjust the sleep duration as needed
except KeyboardInterrupt:
pass
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Please Help

Thanks,

  • Hi Sayali,

    We have example C code for the ADS122C04 available here: https://www.ti.com/tool/download/SBAC299 

    Are you verifying you are setting the device properly and cycling through the right MUX settings for reading your values? 

    Have you used a logic analyzer or oscilloscope to verify that your I2C communications to the device are working properly and match the data sheet's specifications?

    Also have you tried probing the input pins with a digital multimeter or oscilloscope to see what voltage present at the input pins looks like?

    Best Regards,

    Angel

  • yes i check i am getting proper voltage at input and i2c communication also working fine. but i am getting some random output as well but no change with change in input getting constant value.

    I check everythig but something i am missing that's why i am not getting proper output but i am no getting.So please review my code and circuit and please help me to find out what exactly i am missing.

    Here again i am sharing  my code and circuit 

    This is library file

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    import RPi.GPIO as GPIO
    from time import sleep
    from smbus2 import SMBus, i2c_msg
    class ADS122C04:
    CMD_RESET = 0x06
    CMD_START_SYNC = 0x08
    CMD_POWERDOWN = 0x02
    CMD_RDATA = 0x10
    CMD_RREG = 0x20
    CMD_WREG = 0x40
    #MUX_MASK = 0x1F
    MUX_DIF_0_1 = 0x0
    MUX_DIF_0_2 = 0x1
    MUX_DIF_0_3 = 0x2
    MUX_DIF_1_0 = 0x3
    MUX_DIF_1_2 = 0x4
    MUX_DIF_1_3 = 0x5
    MUX_DIF_2_3 = 0x6
    MUX_DIF_3_2 = 0x7
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This is main code i am using

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    from time import sleep
    from ADS122C04_lib import ADS122C04
    ads=ADS122C04()
    ads.reset()
    ads.config(ads.MUX_SINGLE_2, ads.GAIN_1, ads.DATA_RATE_20SPS, ads.MODE_CONTINUOUS, ads.VREF_EXTERNAL, ads.PGA_DISABLED, ads.OP_MODE_NORMAL, ads.TEMP_SENSOR_OFF, ads.DCNT_DISABLE, ads.CRC_DISABLED, ads.BURN_OUT_CURRENT_OFF, ads.IDAC_CURRENT_OFF, ads.IDAC1_DISABLED, ads.IDAC2_DISABLED)
    ads.start()
    try:
    while True:
    result = ads.result()
    print(result)
    sleep(1) # Adjust the sleep duration as needed
    except KeyboardInterrupt:
    pass
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    And Here the output i am getting

    Please help me to find the correct configuration for ADS122C04.

  • Hi Sayali,

    The problem with this setup is that there is no bias on your photodiode circuitry. 

    When you operate a photodiode without any bias voltage, shining light on it generates a very small voltage across its terminals.

    The most common way to read photodiode values is to use a transimpedance amplifier circuit and use the voltage output of this circuit as the input to the ADC. 

    The following resources help explain this concept and how to implement this circuit configuration:

    Photodiode amplifier circuit | Video | TI.com

    Using Photodiode Amplifiers for Ambient Light Sensing in Automotive Displays (Rev. A)

    Alternatively, you could try the following approach with the photodiode in reverse bias mode:

    Photodiodes are usually used in this mode, where a voltage is applied and the input to the ADC would be between the resistor and diode as shown in the picture.

    Best Regards,

    Angel

  • Hello,

    Thanks for your quick response.It helps me alot.

    I use photodiode in reverse bias mode.with multimeter i check voltage it is coming correctly without light fall on photodiode i am getting voltage between the resistor and diode is 0.07V and with light fall on photodiode i am getting voltage between the resistor and diode is max. 3.48V.

    I applied that voltage between the resistor and diode as input to ADC channel AIN2, But still i am getting constant output



    Please suggest me my code is ok or any change in that python library and code for ADS122C04.Any other changes in circuit.

    Please help me to resolve this issu. 

  • Hello,
         i made connection as follow
    A0 and A1 connected to ground
    RESET connected to 3.3V
    DGND and AVSS connected to ground
    REFN connected to ground
    REFP connected to 3.3V in between o.1uf capacitor with ground
    AVDD connected to 3.3V in between o.1uf capacitor with ground
    DVDD connected to 3.3V in between o.1uf capacitor with ground
    DRDY connected to 2.2K pull up resistor
    SDA connected to 2.2K pull up resistor
    SDL connected to 2.2K pull up resistor

    Now please help me to figure out at code side or circuit side is having issue.

  • Hi Sayali

    From your descriptions and schematic, the circuit should be okay.

    i am getting voltage between the resistor and diode is 0.07V and with light fall on photodiode i am getting voltage between the resistor and diode is max. 3.48V.

    Keep in mind that if your supply and VREF is 3.3V, the ADC can't read input voltages higher than this, so take this into consideration if the analog input voltage goes all the way up to 3.48V. You might have to modify either your supply voltage, or your photodiode circuitry to be within the appropriate range. 

    You likely have a problem with your software if you aren't able to get proper ADC readings but verified the voltages with a multimeter. 

    I would recommend probing your digital communication lines with a logic analyzer or a scope to verify that the digital communications seen, match what you intent to do with your code, and comply with the data sheet specifications for communicating with the device.

    Best Regards,

    Angel