ESP32C6 ADC not working properly
-
rafael.04694
- Posts: 1
- Joined: Wed Apr 05, 2023 7:25 pm
ESP32C6 ADC not working properly
Sorry in advance in case this post is repeated.
I'm trying to read voltages using the ESP ADC, but something weird happens.
I'm using the one shot example from ESP-IDF.
When the pin with the used channel is connected to 3.3V it returns a raw reading of 4081, giving me a V = 4081 * 3V3 / 4095 = 2.28 V which is pretty good. However, when I connect the pin to GND, the raw value is 2144, which gives me something like 1.7V.
I'm using the new C6, and I know its calibration is still not available, but shouldn't the method I'm using work? Considering it works for 3V3?
(The code is the one bellow, with an addition of a printf that prints the voltage using the formula above).
Code: https://github.com/espressif/esp-idf/bl ... ead_main.c
I'm trying to read voltages using the ESP ADC, but something weird happens.
I'm using the one shot example from ESP-IDF.
When the pin with the used channel is connected to 3.3V it returns a raw reading of 4081, giving me a V = 4081 * 3V3 / 4095 = 2.28 V which is pretty good. However, when I connect the pin to GND, the raw value is 2144, which gives me something like 1.7V.
I'm using the new C6, and I know its calibration is still not available, but shouldn't the method I'm using work? Considering it works for 3V3?
(The code is the one bellow, with an addition of a printf that prints the voltage using the formula above).
Code: https://github.com/espressif/esp-idf/bl ... ead_main.c
Re: ESP32C6 ADC not working properly
Wondering if it is because you're witching between two channels all the time. Does it still does that if you only measure one channel?
Re: ESP32C6 ADC not working properly
I have the same issue - higher bit from 12-bits ADC value always is '1'.
Re: ESP32C6 ADC not working properly
Hello! I am experiencing the same issue.
If I connect the pin to GND I get the following ADC output: 0b0000100001110001
If I connect it to 3.3V I get: 0b0000111111110001
Is this a hardware bug?
If I connect the pin to GND I get the following ADC output: 0b0000100001110001
If I connect it to 3.3V I get: 0b0000111111110001
Is this a hardware bug?
Re: ESP32C6 ADC not working properly
I'm getting the same thing on 2x ESP32-C6-DevKitM-1, and also on a ESP32-H2-DevKitM-1. To get the same thing on H2 and C6, I'm dubious of a hardware bug.
For me I'm working in rust. And this is my first time working with ESP32 units, so I'm inclined to think I'm doing something wrong. However I've basically got the same code as in the example on https://docs.rs/esp32c6-hal/latest/esp3 ... index.html. So I can't see how it would be a software issue either. Unless there's some prerequisites that I've missed.
Also, to note, I do get a signal. When the input voltage changes, so does the value read. But it's nowhere near what it's supposed to be. When pulled to ground, I get ~2144 (bounces around a bit), and when floating it goes to 4081. When I have an input voltage of 0.307v and 0dB attenuation, I should read a value of about 1571, but instead get 3297.
For me I'm working in rust. And this is my first time working with ESP32 units, so I'm inclined to think I'm doing something wrong. However I've basically got the same code as in the example on https://docs.rs/esp32c6-hal/latest/esp3 ... index.html. So I can't see how it would be a software issue either. Unless there's some prerequisites that I've missed.
Also, to note, I do get a signal. When the input voltage changes, so does the value read. But it's nowhere near what it's supposed to be. When pulled to ground, I get ~2144 (bounces around a bit), and when floating it goes to 4081. When I have an input voltage of 0.307v and 0dB attenuation, I should read a value of about 1571, but instead get 3297.
Re: ESP32C6 ADC not working properly
Same problem here one year later, any update on that? Surprisingly I have tested oneshot read from Arduino and it worked fine...
-
yeohwaisiang
- Posts: 2
- Joined: Fri Jun 07, 2024 1:34 pm
Re: ESP32C6 ADC not working properly
still no one can resolved the ADC-4081 issue?
where are their engineers?
where are their engineers?
Re: ESP32C6 ADC not working properly
Based on my tests in C and Rust, the problem occurs in Rust esp-hal.
If code in C language has DEFAULT_VREF set to 1100 problem should not occur.
This gives me
If code in C language has DEFAULT_VREF set to 1100 problem should not occur.
Code: Select all
#include <Arduino.h>
#include "driver/adc.h"
#define DEFAULT_VREF 1100
#define ADC_PIN A4
// Define the ADC channel and attenuation
#define ADC_CHANNEL ADC1_CHANNEL_4 // important check your pin channel, for ESP32-C6 DevkitC I have a pin 4
#define ADC_ATTEN ADC_ATTEN_DB_11
int ADC_VALUE = 0;
double voltage_value = 0.0;
void setup() {
Serial.begin(9600);
pinMode(ADC_PIN, INPUT); // set the analog reference to 3.3V
// Initialize the ADC configuration
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC_CHANNEL, ADC_ATTEN);
}
void loop() {
do_adc();
delay(500);
}
void do_adc() {
sensor_reading();
Serial.print("ADC value: ");
Serial.println(ADC_VALUE);
Serial.print("ADC voltage: ");
Serial.println(voltage_value);
}
float sensor_reading() {
ADC_VALUE = adc1_get_raw(ADC_CHANNEL);
voltage_value = (ADC_VALUE * 3.3 );
return voltage_value;
}
Re: ESP32C6 ADC not working properly
Last day I did some changes in my Rust code and it worked almost perfectly
Important part is adc1_config.enable_pin_with_cal::<GpioPin<4>, AdcCalBasic<ADC1>>(hw_390_pin, Attenuation::_11dB);, if you do not define AdcCalScheme output may give you always 4081. There are 3 possible implementations of the AdcCalScheme
Code: Select all
#[main]
fn main() -> ! {
let mut adc1_config = AdcConfig::new();
let pin = adc1_config.enable_pin_with_cal::<GpioPin<4>, AdcCalBasic<ADC1>>(hw_390_pin, Attenuation::_11dB);
let adc1 = Adc::new(peripherals.ADC1, adc1_config);
loop {
let out: i32 = block!(adc.read_oneshot(&mut pin)).unwrap() as i32;
info!("read: {:?}", out);
delay.delay_millis(500);
}
}
- 1. AdcCalBasic
2. AdcCalCurve
3. AdcCalLine
Code: Select all
pub struct AdcPin<PIN, ADCI, CS = ()> {
/// The underlying GPIO pin
pub pin: PIN,
/// Calibration scheme used for the configured ADC pin
#[cfg_attr(esp32, allow(unused))]
pub cal_scheme: CS,
_phantom: PhantomData<ADCI>,
}
Who is online
Users browsing this forum: PetalBot and 4 guests
