Skip to content

analogRead() provides incorrect results on the SAMD21 core. #446

@omzlo

Description

@omzlo

Consider the following sketch:

#define Debug Serial

void setup() {
  analogReadResolution(12);
  pinMode(A0, INPUT);
  Debug.begin(9600);
  while (!Debug);
}

void loop() {
  int a = analogRead(A0);
  float v = 3.3*((float)a)/4095;

  Debug.print(a);
  Debug.print(" ");
  Debug.print(v,3);
  Debug.println();

  delay(1000);
}

If you provide a voltage on pin A0, then results in v are typically offset by +35mV (sometimes a little less, sometimes a little more).

There is likely a bug in the Arduino code of the analogRead() function, as detailed here:
https://www.omzlo.com/articles/your-arduino-samd21-adc-is-wrong-did-you-notice

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions