Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C3: ADC raw values calibration #550

Closed
wants to merge 7 commits into from

Conversation

JurajSadel
Copy link
Contributor

@JurajSadel JurajSadel commented May 18, 2023

This adds initial ADC raw values calibration. The solution is ported from https://github.com/apache/nuttx/blob/master/arch/risc-v/src/esp32c3/esp32c3_adc.c

The 11dB attenuation seems to be working fine, however, other values(0, 2.5, and 6dB) are weird - I'm getting 4095(raw) for the default state (with 11dB I'm getting ~2200(raw)). The weirdest thing here is that I have the same behavior in ESP-IDF oneshot example. I've tested with Rust board (C3, revision3) and 5V joystick.

If anyone has any idea, what is going on with attenuations (or can test this code) it'd be very appreciated.
I'll look into calculating voltage from raw values in the meantime.

Related #326

@JurajSadel JurajSadel mentioned this pull request May 18, 2023
7 tasks
@JurajSadel JurajSadel changed the title Feature/adc calibration C3: ADC raw values calibration May 18, 2023
@bjoernQ
Copy link
Contributor

bjoernQ commented May 19, 2023

Tested on ESP32-C3 and I get the same values I get with the eps-idf example. (With ADC_ATTEN_DB_0 and ADC_ATTEN_DB_11)

@@ -59,4 +59,25 @@ impl Efuse {
let efuse = unsafe { &*EFUSE::ptr() };
efuse.rd_repeat_data1.read().wdt_delay_sel().bits()
}

/// Read Efuse data and return them
pub fn read_efuse(address: u32, offset: u32, size: u32) -> u32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Efuses also can be read via peripheral access like so:

let efuse = unsafe { &*EFUSE::ptr() };

efuse.rd_sys_part1_data0.read().bit_field()

But seems currently bit fields isn't described.
(see registers definition in esp32c3.base.svd)

@elpiel
Copy link
Contributor

elpiel commented Jun 12, 2023

Is there anything else I need to do apart from using the branch to test this out?

ADC values still don't show correct values:

Screenshot from 2023-06-12 14-02-41
I'm measuring a 250 mAh battery (4.2V max) with a voltage divider (2 x 470 k Ohms resistors) and these are the values I get.
With attenuation 11db I should see ~ (4.2V/2) = 2.1V for a full battery.

@JurajSadel
Copy link
Contributor Author

@elpiel Could you try this PR, please?

@jessebraham
Copy link
Member

Superseded by #555

@JurajSadel JurajSadel deleted the feature/adc_calibration branch April 10, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants