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.

ADS1112: issue when reading two channels at the same time

Part Number: ADS1112

Hi Team,

There is a delay when reading two channels at the same time through I2C in the driver, and it may appear that the value of the first channel is obtained by reading the value of the second channel.

SW code is showed as below:

Programs that add a delay between reads can cause other problems.

Could you help comment on how to solve it? Thanks alot.

William

  • Hi William,

    From the code it is not clear when it is determined when to read the conversion result.  Most likely what is happening is even though the configuration changed the operating mode of continuous conversion will not change channels until the ongoing conversion ends.  This will result in reading the conversion data from the previously selected input channel.

    When cycling the mux, I recommend using single conversion mode instead of continuous mode.  What this will do is when the new configuration is written it will apply right away.  When using continuous conversion mode you never know for sure when the desired channel data will appear as the conversion result.  When using continuous conversion mode you should always disregard the first conversion after the channel change.

    Best regards,

    Bob B

  • Hi Bob,

    I'm William's colleague.We changed the mode to single conversion like you said, but the problem still exists. The code to read the conversion result is as follows.

    The above code is called about every 40 ms. We found that even the single mode needs to be read twice to get the correct value, and a msleep needs to be added. If not add the sleep, or read once,  both will get wrong value. Do I have to read it twice and increase the delay when cycling the mux?Looking forward to your reply.

    Best regards,

    Qun Wu

  • Hi Qun Wu,

    It is not clear to me what happens in the function motor_adc_update.  It would appear that the functionality is the same whether you are reading or writing to the device.  You could add another parameter such that a '0' writes to the device only, and a '1' reads the conversion result.

    There are two ways that you can use the device.  One way is to use a timer to delay reading the conversion result following the start of conversion.  The second way is to monitor the Configuration Register status bit for a low on bit 7.

    Let's keep it simple and use the delay along with single conversion mode.

    • motor_adc_update(MOTOR_FOCUS, 0) which writes to the ADC configuration 11010100 (0xD4) for channel 1 and starts conversion
    • msleep(20) which delays 20ms to allow conversion to complete
    • motor_adc_update(MOTOR_FOCUS, 1) which reads the channel 1 conversion result only
    • motor_adc_update(MOTOR_ZOOM, 0) which writes to the ADC configuration 11110100 (0xF4) for channel 2 and starts conversion
    • msleep(20) which delays 20ms to allow conversion to complete
    • motor_adc_update(MOTOR_ZOOM, 1) which reads the channel 2 conversion result only

    What I think is happening is your motor_adc_update function is starting the conversion and reading in the same loop.  The best method to verify the communication and timing is to use a logic analyzer.  This will show what the actual communication flow is to/from the ADC.

    Best regards,

    Bob B

  • Hi Bob,

    The problem has been solved, thank you very much for your help.

    Best regards,

    Qun Wu