https://toitlang.org/ logo
PWM Issues
# help
s
Hello, We’re experiencing issues with sending PWM signals. We’re using a Walter Board (ESP32-S3) with the demo code provided on the official website, configured to suit our requirements. Below is the code we're using:
Copy code
py
import gpio
import gpio.pwm

main:
  led := gpio.Pin 2 --output
  generator := pwm.Pwm --frequency=50
  channel := generator.start led
  channel.set-duty-factor 0.5
  sleep --ms=10_000
  channel.close
  generator.close
  led.close
Software setup: esp32s3-octo-spiram envelope Jaguar v1.45.1 SDK version: v2.0.0-alpha.170 Below i'll provide the full Error:
Copy code
py
E (328) octal_psram: PSRAM ID read error: 0x00000000, PSRAM chipESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x9 (SPI_FAST_FLASH_BOOT)
Saved PC:0x403846e6
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3810,len:0x88
load:0x403c9700,len:0x96c
load:0x403cc700,len:0x2504
entry 0x403c9850
E (299) octal_psram: PSRAM ID read error: 0x00000000, PSRAM chip not found or not supported, or wrong PSRAM line mode
E (299) esp_psram: PSRAM enabled but initialization failed. Bailing out.
[toit] INFO: starting <v2.0.0-alpha.170>
[toit] DEBUG: clearing RTC memory: powered on by hardware source
[toit] INFO: running on ESP32S3 - revision 0.2
[wifi] DEBUG: connecting
[wifi] WARN: connect failed {reason: unknown reason (203)}
[wifi] DEBUG: closing
[jaguar] WARN: running Jaguar failed due to 'CONNECT_FAILED: unknown reason (203)' (1/3)
[wifi] DEBUG: connecting
[wifi] DEBUG: connected
[wifi] INFO: network address dynamically assigned through dhcp {ip: 192.168.1.18}
[wifi] INFO: dns server address dynamically assigned through dhcp {ip: [192.168.1.1]}
[jaguar.http] INFO: running Jaguar device 'inverted-function' (id: '60b97c28-386d-44a8-bc4f-b80a1caed762') on 'http://192.168.1.18:9000'
[jaguar] INFO: program 2bc4defe-e5b8-655a-b6a2-1b631dd1a028 started
E (21677) ledc: freq_hz=50 duty_resolution=20

******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.170>
******************************************************************************
EXCEPTION error.
UNKNOWN ERROR 0x102(258)
  0: pwm-init_                 <sdk>\gpio\pwm.toit:177:3
  1: Pwm                       <sdk>\gpio\pwm.toit:103:12
  2: main                      testing.toit:6:16
******************************************************************************

[jaguar] ERROR: program 2bc4defe-e5b8-655a-b6a2-1b631dd1a028 stopped - exit code 1
f
The S3 doesn't support low frequencies with the pwm.
I will try to find the exact values and update the documentation of the pwm library. I hope I will also find a better way to report the error when I do that.
k
We already tested successfully PWM with 50Hz earlier this year on Walter (gpio2)? Checked with Oscilloscope and it worked fine. I can't remember the version of the SDK 😦 @User ?
f
Interesting. I was convinced we ran into a similar issue some time ago. Let me see if I can find it.
k
It was a pretest for using Walter as substitute for the old Pycom/Gpy.
f
If it works on an older SDK we can maybe get it to work again. Last time I looked I couldn't find any way, though.
Hmm. Maybe it's possible by using a different clock as input.
k
@User do you have a Walter board or a similar one for testing?
f
I have an S3
s
I believe we tested on alpha.153, since it was not relevant back then I did not check it though.
k
is there a way deploy this old SDK version? for pwm testing only ...
f
You can always download an older Jaguar
I just tried with SDK 152 and 154 and both exhibit the same error.
Copy code
E (12975) ledc: freq_hz=50 duty_resolution=20
k
We had definitly positive pwm-tests for server control usage .... hmm? I decided - late August 2024 to replace gpy with Walter because of this sscuessful test ... hmm?
f
I managed to get it working, but I had to change the C++ primitives. So I don't think it ever worked with Toit.
Today is my last day before vacation and I won't be able to cleanly fix this now, but it's clearly possible. I will implement this correctly in the beginning of next year.
k
I am absolutely sure that we had a working pwm 50Hz on Walter ... but I am confused now 🙂 Thanks a lot for your effort and it is a rather important step for us to get Walter running instead of gpy.
@Spruiid please take some time to find out what we did last summer 😉
f
I will see if I can add a (maybe hackish) fix before I leave for vacation.
I have uploaded a PR.
A fix was committed and will be part of alpha.175. I have uploaded an envelope for 174 to my drive: https://drive.google.com/file/d/1LLiFIq3up3lFfIJ-W4RaPigN-VS4kZcV/view?usp=drive_link With Jaguar you can simply
jag flash <PATH-TO-ENVELOPE>
. (If it's in your current directory use
./<NAME-OF-ENVELOPE
(with a
./
))
o
Thank you. The pwm fix worked. Was the update on espressif updates or toit side?
f
Toit. We had a bug in the S3 implementation. I'm in the process of adding more hardware tests to cover more variants.