ESP32-C3 SuperMini ADC

Hallo, Ich habe ein Messdiagramm erstellt.

der ADC liefert über AnalogRead ein sehr schlechtes Ergebnis.
Über ADC. analogReadMilliVolts(pin) bekommt man ganz ordentliche Ergebnisse.
Der höchst gemessene Wert beträgt 2,865V.

Ich habe zwei Sketch Beispiele beigelegt.
Diesbezüglich gibt es bereits mehrere Diskussionen in diesem Forum.

ESP32-C3 ADC issue - reading 4095 at 2.8V

ESP32 ADC – Read Analog Input in Arduino IDE

analogRead

// Definiere den Pin für den Analogeingang
const int analogPin = A0; // A0 ist der Standard-Analogeingang

void setup() {
  // Initialisiere die serielle Kommunikation
  Serial.begin(115200);
}

void loop() {
  // Lese den Wert vom Analogeingang
  int analogValue = analogRead(analogPin);
  
  // Wandle den analogen Wert in Volt um
  float voltage = analogValue * (3.3 / 4095.0);
  
  // Gib den gelesenen Wert und die Spannung im Seriellen Monitor aus
  Serial.print("Analog Value: ");
  Serial.print(analogValue);
  Serial.print(" - Voltage: ");
  Serial.print(voltage, 3); // Ausgabe mit 3 Dezimalstellen
  Serial.println(" V");
  
  // Warte eine Sekunde, bevor der nächste Wert gelesen wird
  delay(1000);
}

analogReadMilliVolts(analogPin)

// Definiere den Pin für den Analogeingang
const int analogPin = A0; // A0 ist der Standard-Analogeingang

void setup() {
  // Initialisiere die serielle Kommunikation
  Serial.begin(115200);
}

void loop() {
  // Lese die Spannung in Millivolt vom Analogeingang
  int milliVolts = analogReadMilliVolts(analogPin);
  
  // Gib die Spannung im Seriellen Monitor aus
  Serial.print("Voltage: ");
  Serial.print(milliVolts / 1000.0, 3); // Umrechnung in Volt und Ausgabe mit 3 Dezimalstellen
  Serial.println(" V");
  
  // Warte eine Sekunde, bevor der nächste Wert gelesen wird
  delay(1000);
}

Multimeter analogRead analogReadMilliVolts
0,010 0,017 0,016
0,015 0,019 0,019
0,050 0,073 0,055
0,100 0,115 0,104
0,200 0,227 0,207
0,300 0,330 0,303
0,400 0,446 0,405
0,500 0,550 0,504
0,600 0,666 0,604
0,700 0,780 0,705
0,800 0,890 0,804
0,900 1,000 0,904
1,000 1,115 1,005
1,100 1,230 1,107
1,200 1,340 1,204
1,300 1,440 1,305
1,400 1,580 1,408
1,500 1,690 1,509
1,600 1,800 1,610
1,700 1,900 1,712
1,800 2,030 1,810
1,900 2,150 1,910
2,000 2,260 2,007
2,100 2,370 2,104
2,200 2,470 2,206
2,300 2,630 2,310
2,400 2,720 2,400
2,500 2,840 2,500
2,600 2,970 2,605
2,700 3,100 2,705
2,800 3,230 2,820
2,900 3,300 2,865
3,000 3,300 2,865
3,100 3,300 2,865
3,200 3,300 2,865
3,300 3,300 2,865

If your goal is to measure the range of 0-3.3V then both ways are wrong. If the measurement range ends at 2.86V then you can increase it with a voltage divider to correctly measure higher voltages. You can use a voltage divider for this using two resistors if the input impedance is not important to you or using one resistor, which together with the internal impedance of the ADC will also create a voltage divider. After selecting the resistor or resistors you need to correctly calibrate the ADC using a reference meter. In the case of a built-in ADC it is also important that the chip is powered from a linear regulator with large filtering capacitors. You can improve the accuracy of the measurements themselves by oversampling and introducing calibration points into the code along with spline interpolation or at least linear interpolation. If you care about accurate measurements, it is worth considering an external ADC such as the ADS1115, which provides 16-bit precision and variable gain allowing for flexible voltage measurement over a variety of ranges.

Thank you Jack for your explanation.

I have a circuit where I use a PWM controller as the power supply. Do you have a recommendation on how I can filter the power supply?
You have explained a lot to me, that is very interesting.