ESP32 - GPIO25 as PWM output connected to GPIO33 as ADC input - voltage drop on pulse

Thread Starter

marcRoma

Joined Aug 13, 2020
5
I am a bit stuck on this one and would appreciate help or tips from the community here...

I am using ESP-IDF and using a dev board from TTGO (with LORA).

I've programmed the GPIO 25 to have a 100KHz PWM output with 50% duty cycle.
Looking at the osciloscope I see a nice, well behaved pulse 0-3.3V, as expected.

Now, I configured the GPIO33 as ADC input (atenuation DB 11). As soon as I connect the two GPIOs I see a drop on the Voltage on the high cycle of the pulse, from +3.3V to ~900mV in the osciloscope.

I've tried different configs and always get the same result above. Am I missing something fundamental here ? Any tips or ideas ?
Happy to share the code if description above not enough/clear.

Thx for the help!
 

dendad

Joined Feb 20, 2016
3,602
It sounds like the input is loading the output.
What does the PWM do if you just for a test, feed it to a 1K resistor to 0V?
Try other values too.
Now, I configured the GPIO33 as ADC input (atenuation DB 11).
I do not know what the inputs configured as that do. What does the resistance of the input measure?
And do you have anything else in circuit? A diagram may help.
 
As dendad mentioned the ADC is probably overloading the output. I don't remember the specs offhand, but the ESP modules have really low ratings (I think I saw 2mA). I haven't tried their ADC myself yet, but have a feeling most of your output is charging the ADC capacitor.
 

Thread Starter

marcRoma

Joined Aug 13, 2020
5
It sounds like the input is loading the output.
What does the PWM do if you just for a test, feed it to a 1K resistor to 0V?
Try other values too.

I do not know what the inputs configured as that do. What does the resistance of the input measure?
And do you have anything else in circuit? A diagram may help.
Thx dendad and geekoftheweek for the replies... I did a test with a 1.5K to 0V - the pulse is as expected: 0V to +5V 100KHz.
The Resistance on the GPIO33 is 6M.
I stripped out all the other components. Now I am only using the TTGO ESP32 board with the GPIO33 and GPIO25 wired directly to each other.
 

Thread Starter

marcRoma

Joined Aug 13, 2020
5
Should that not be 3.3V?
Are you sure you have set GPIO33 as an input?
my bad - it is 3.3V (and not 5V)
rgd GPIO33: yes - pretty sure GPIO33 is runnnig as input. I double checked by pluging VCC/+3.3V directly to the GPIO33. I get 4095 in the logs, as expected.
 
I realized I made a huge error. The ESP32 is much more advanced than the ESP12F I've been working with. It seems there is a way to set the output drive current, but I can't quite seem to locate the details in the datasheet. Have you tried changing settings there? I couldn't find specifics on the ADC itself, but other things I found would make me think it shouldn't cause this sort of issue. The only other thing is did you set the open drain mode on your output? Ideally it shouldn't give you 3.3V output without a pull up, but with only a scope connected maybe internal whatever is enough to give a false reading.
 

Thread Starter

marcRoma

Joined Aug 13, 2020
5
I realized I made a huge error. The ESP32 is much more advanced than the ESP12F I've been working with. It seems there is a way to set the output drive current, but I can't quite seem to locate the details in the datasheet. Have you tried changing settings there? I couldn't find specifics on the ADC itself, but other things I found would make me think it shouldn't cause this sort of issue. The only other thing is did you set the open drain mode on your output? Ideally it shouldn't give you 3.3V output without a pull up, but with only a scope connected maybe internal whatever is enough to give a false reading.
I think that is the right direction... the ADC input requires more current than the PWM currently supplies... not sure if there is any way to boost that current... need to investigate.
 
@marcRoma I did some more looking around. If I wasn't as far as I am on a project I would switch to the ESP32.

Anyways here's what I found...
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html shows:

What looks to be how to set the output drive level...
Code:
esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength)
And for the strength you would use:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html#_CPPv416gpio_drive_cap_t

Code:
GPIO_DRIVE_CAP_0 = 0 // Pad drive capability: weak
GPIO_DRIVE_CAP_1 = 1 // Pad drive capability: stronger
GPIO_DRIVE_CAP_2 = 2 // Pad drive capability: medium
GPIO_DRIVE_CAP_DEFAULT = 2 // Pad drive capability: medium
GPIO_DRIVE_CAP_3 = 3 // Pad drive capability: strongest
It doesn't give any details as to what current goes with each setting though. Maybe in the datasheet somewhere....

EDIT...

I found the values also:
https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf pg 53 lists the output as:
0 = 5 mA
1 = 10 mA
2 = 20 mA
3 = 40 mA

The default setting is supposed to be 2 (20 mA), but in the GPIO_MATRIX table starting on page 54 it shows 1 (10 mA) as the default for PWM pins if I'm reading it correctly. I don't know if changing the strength would change the PWM or not. I kind of wish I had one to test. Good luck!!

Another edit...

I tried to find examples for Arduino IDE type developing, but couldn't come up with anything yet. Hopefully the functions are available going the Arduino IDE route.
 
Last edited:

Thread Starter

marcRoma

Joined Aug 13, 2020
5
@marcRoma I did some more looking around. If I wasn't as far as I am on a project I would switch to the ESP32.

Anyways here's what I found...
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html shows:

What looks to be how to set the output drive level...
Code:
esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength)
And for the strength you would use:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html#_CPPv416gpio_drive_cap_t

Code:
GPIO_DRIVE_CAP_0 = 0 // Pad drive capability: weak
GPIO_DRIVE_CAP_1 = 1 // Pad drive capability: stronger
GPIO_DRIVE_CAP_2 = 2 // Pad drive capability: medium
GPIO_DRIVE_CAP_DEFAULT = 2 // Pad drive capability: medium
GPIO_DRIVE_CAP_3 = 3 // Pad drive capability: strongest
It doesn't give any details as to what current goes with each setting though. Maybe in the datasheet somewhere....

EDIT...

I found the values also:
https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf pg 53 lists the output as:
0 = 5 mA
1 = 10 mA
2 = 20 mA
3 = 40 mA

The default setting is supposed to be 2 (20 mA), but in the GPIO_MATRIX table starting on page 54 it shows 1 (10 mA) as the default for PWM pins if I'm reading it correctly. I don't know if changing the strength would change the PWM or not. I kind of wish I had one to test. Good luck!!

Another edit...

I tried to find examples for Arduino IDE type developing, but couldn't come up with anything yet. Hopefully the functions are available going the Arduino IDE route.
Wow! Awsome!!!
I changed quickly the code just to double check at which strength my code was running - I can confirm it is running with 2.
Strange enough, the 20mA should be enough for the ADC to read...
...anyway, I will run a test setting it to 3 and see happens.
thx for the findings, they are very helpfull indeed!
 
Wow! Awsome!!!
I changed quickly the code just to double check at which strength my code was running - I can confirm it is running with 2.
Strange enough, the 20mA should be enough for the ADC to read...
...anyway, I will run a test setting it to 3 and see happens.
thx for the findings, they are very helpfull indeed!
You are welcome. Thanks for motivating me to read more about the ESP32!!
 
Top