Changed PWM behaviour?

ChrisHill
Posts: 9
Joined: Fri Jan 06, 2023 12:57 pm

Changed PWM behaviour?

Postby ChrisHill » Thu Feb 16, 2023 7:17 pm

I have made a PCB with a WROOM-32E module. The PCB includes a 16x2 LCD display, using a 16-pin parallel connection. I am controlling the display's contrast and brightness by using PWM control of a couple of GPIO pins (GPIO13 for brightness, via transistor to supply a controlled amount of my 5V supply, and GPIO21 for contrast, by controlling the voltage on the display's contrast pin directly). My application generates a web page that includes sliders for these two controls. Until this morning, these features were working perfectly.

I am using Visual Studio Code/PlatformIO, and this morning I had some issues with a different project so I tried updating PlatformIO. This evening I discovered that the PWM control of these pins seems to have stopped working - I'm pretty sure it's related to the update. Everything else still works: my app still generates the web pages to control the display, various buttons on my PCB still perform their intended functions, and I can still even make out very faint characters on the display. But I can no longer control the brightness or contrast. The backlight is off, and the contrast seems to be at its highest.

I used a basic multimeter to check the voltage on the two PWM pins, and they both seem to be at 0V, regardless of the slider settings.

I originally installed Visual Studio/PlatformIO in late January 2022, and unless it does so by itself in the background, it hadn't been updated since then until this morning.

So my question for the forum is whether an update this morning could somehow have changed the PWM behaviour of GPIO13 and GPIO21.

My code, which worked until this morning, is:

Code: Select all

const int freq = 5000;
const int ledChannel = 0;
const int ConChannel = 1;
const int resolution = 8;
.
.
.
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(BackLightpin, ledChannel);
ledcSetup(ConChannel, freq, resolution);
ledcAttachPin(Contrastpin, ConChannel);
.
pinMode(BackLightpin, OUTPUT);
pinMode(Contrastpin, OUTPUT);
.
.
.
ledcWrite(ledChannel, brightnessOn);
ledcWrite(ConChannel, 255-Contrast);
To help me debug this, can anyone tell me how to revert to an earlier version of the framework? My platformio.ini file previously contained the line:

Code: Select all

platform = espressif32
In an effort to specify an earlier version I tried changing that to, e.g.:

Code: Select all

platform = https://github.com/platformio/platform-espressif32.git
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.5.0
(3.5.0 is dated end of Jan 2022, so would be similar to the version I installed originally with VS Code).
But this fails with various error messages, so I must be doing something wrong in trying to get back to an earlier version.

It may be nothing to do with updating, but that is certainly how it appears at this stage. I'm out of ideas to fix this, so would appreciate any help.

ChrisHill
Posts: 9
Joined: Fri Jan 06, 2023 12:57 pm

Re: Changed PWM behaviour?

Postby ChrisHill » Fri Feb 17, 2023 9:55 am

It seems I was on the right lines with this approach:

Code: Select all

platform = https://github.com/platformio/platform-espressif32.git
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.5.0
but I was looking at version numbers for the wrong repository. :(

https://github.com/espressif/arduino-esp32.git is currently up to version 2.0.6. I worked backwards through previous versions and found that my PWM controls work as before if I go back to 2.0.2, but with version 2.0.3 they don't work.

2.0.2 was released on December 23, 2021, and 2.0.3 on May 4, 2022, so that fits with the version I would have installed in late January 2022.

I had a look through the release notes, and there are some bugfixes related to LEDC, so I suppose something has indeed changed the behaviour of my PWM pins. But they're bug FIXES, so I guess I need to research a bit more the proper way to use this feature in light of the changes.

This bug fix https://github.com/espressif/arduino-esp32/pull/6160 apparently added 'pinMode(pin,OUTPUT);' to the ledcAttach function, so I wondered if my lines of code that did this specifically were perhaps redundant and clashing with the ledcAttach function. It turns out they ARE redundant, but taking them out didn't fix my problem with versions after 2.0.2.

Oh well, at least I can continue in the meantime with 2.0.2, but it would be nice to know what I'm doing that clashes with later versions.

Any suggestions?

ChrisHill
Posts: 9
Joined: Fri Jan 06, 2023 12:57 pm

Re: Changed PWM behaviour?

Postby ChrisHill » Fri Feb 17, 2023 10:51 am

I'm an eejit. It WAS the redundant pinMode instructions - I had simply messed up the compilation (edited one file, compiled a different one!).

This bug report related to the same issue, and explained the fix.
https://github.com/espressif/arduino-esp32/issues/7673

I can now run my code successfully under the latest version.
Case closed.

Who is online

Users browsing this forum: No registered users and 48 guests