Page 1 of 1

How to set the analog attenuation?

Posted: Sat Dec 10, 2016 2:14 pm
by torntrousers
The code to set the esp32/arduino code to set the analog attenuation doesn't seem to work. Can anyone say how its supposed to be done? Or is there some bug in the SDK?

Code is here: https://github.com/espressif/arduino-es ... -adc.c#L69

Issue here: https://github.com/espressif/arduino-esp32/issues/87

Thanks for any help

Re: How to set the analog attenuation?

Posted: Sun Dec 11, 2016 9:35 am
by WiFive

Code: Select all

adc1_config_width(ADC_WIDTH_12Bit);//config adc1 width
adc1_pad_init(ADC1_CHANNEL_6);
adc1_config_channel_atten(ADC1_CHANNEL_6,ADC_ATTEN_0db);
int val=adc1_get_voltage(ADC1_CHANNEL_6);
adc1_config_channel_atten(ADC1_CHANNEL_6,ADC_ATTEN_11db);
int val2=adc1_get_voltage(ADC1_CHANNEL_6);
printf("ADC1 CH6 value: %d @ 0db, %d @ 11db\n", val, val2);
fflush(stdout);

Code: Select all

ADC1 CH6 value: 1828 @ 0db, 448 @ 11db

Re: How to set the analog attenuation?

Posted: Tue Dec 13, 2016 1:49 pm
by torntrousers
Thanks!

Re: How to set the analog attenuation?

Posted: Wed Jan 04, 2017 8:35 am
by TESTTHISONE
I have a question.
In order to call this function - adc1_pad_init(...),
what header file did you include?