ADC: how to configure different attenuations for channels? (solved)

newsettler_AI
Posts: 121
Joined: Wed Apr 05, 2017 12:49 pm

ADC: how to configure different attenuations for channels? (solved)

Postby newsettler_AI » Wed Apr 24, 2019 7:28 pm

Hi,

I need measure 2.5V voltage at IO_35 and 0...2V and pins 33,36,39.

So, problem is that values I've got from IO_35 is wrong...

channels & attenuation :

Code: Select all

static const adc_channel_t bat  = ADC1_CHANNEL_5; // IO33
static const adc_channel_t one = ADC1_CHANNEL_0; // IO36 
static const adc_channel_t two = ADC1_CHANNEL_3; // IO39
static const adc_channel_t vref = ADC1_CHANNEL_7; // IO35 - VREF

static const adc_atten_t atten = ADC_ATTEN_DB_6;

Code: Select all

void adc_init()
{
	check_efuse();

	adc1_config_width(ADC_WIDTH_BIT_12);
	adc1_config_channel_atten(bat, atten);
	adc1_config_channel_atten(vref, ADC_ATTEN_DB_11);
	adc1_config_channel_atten(one, atten);
	adc1_config_channel_atten(two, atten);

    //Characterize ADC
    adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
    esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);
    print_char_val_type(val_type);
}
Looks like esp_adc_cal_characterize initializes with ADC_ATTEN_DB_6 value...

Here is output:

Code: Select all

[2019-04-24_22:11:39]bat(IO33): bit:(3282) [1553] mV
[2019-04-24_22:11:39]one(IO36): bit:(770) [446] mV 
[2019-04-24_22:11:39]two(IO39): bit:(0) [107] mV 
[2019-04-24_22:11:39]vref(IO35): bit:(2940) [1402] mV 
Calculated voltage value is wrong, I've measured and it is really 2.5V.
Last edited by newsettler_AI on Fri Apr 26, 2019 10:31 am, edited 1 time in total.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ADC: how to configure different attenuations for channels?

Postby WiFive » Thu Apr 25, 2019 7:14 am

You should do

Code: Select all

adc_chars_vref = calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars_vref);
Then you have 2 sets of chars

newsettler_AI
Posts: 121
Joined: Wed Apr 05, 2017 12:49 pm

Re: ADC: how to configure different attenuations for channels?

Postby newsettler_AI » Fri Apr 26, 2019 10:30 am

WiFive wrote:
Thu Apr 25, 2019 7:14 am
You should do

Code: Select all

adc_chars_vref = calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars_vref);
Then you have 2 sets of chars
Thanks a lot, this helped

Who is online

Users browsing this forum: Bing [Bot] and 116 guests