0

I have the problem, that the potentiometer goes from the range of 0 Volts to 3,3 volts. But within this range the measured value goes from about 0 to 65535 multiple times (over 10 cycles).

When I change the code from my ADC library to 32 bit I get 32 bit values (0 - 4294967296) but the same error with the beginning at 0 multiple times within the potentiometer range occurs.

Hardware:

Board: ESP32 ADC: MAX11613 (12 bit adc) https://www.mouser.de/datasheet/2/256/MAX11612-MAX11617-1508955.pdf Potentiometer: 3046L - 3 - 203 https://www.mouser.de/datasheet/2/54/3046-776396.pdf

Part of the code that reads the adc values:

uint8_t MAX11613::MAX11613_ADC_Read(structMAX11613* chip, uint8_t channel, uint16_t* val){
    
    uint8_t configurationByte = ( (channel<<1) & 0x0e) | 0x61;
    MAX11613_Configuration(chip, configurationByte);

    Wire.beginTransmission(chip->devAddress);
    Wire.requestFrom(chip->devAddress, (byte) 2);    // request 2 bytes from slave device wireIface
    while (Wire.available()) { // slave may send less than requested
    //char c = Wire.read(); // receive a byte as character
    
    uint16_t value = 0;
    value =  Wire.read();
    value |= Wire.read() << 8;

    //This also works:
    /*uint32_t buf1;
    size_t actually_read = Wire.readBytes((uint8_t*)&buf1, 2);
    *val = actually_read;
    //Serial.println(value);*/

    *val = value;
    }
    if (Wire.endTransmission() != 0){
    return 1;
    }
    return 0;
    
}

1 Answer 1

1

The MAX1161x are 12-bit ADCs, so the problem is not related to an uint16 overflow as you seem to assume. The ADC transmits most significant bits (MSB) first as can be seen in figure 10 on page 17. To account for that you need to change

value =  Wire.read();
value |= Wire.read() << 8;

to

value = Wire.read() << 8;
value |=  Wire.read();
2
  • Youre absolutely right. In addition I had to edit the first byte transmitted, because it only transfers the first 4 digits (4 bits + 8 bits = 12 bits):
    – schnecktec
    May 25, 2022 at 9:39
  • value = (Wire.read() & 0x000f) << 8; value |= (Wire.read() & 0x00ff);
    – schnecktec
    May 25, 2022 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.