Recently, I've discovered that I can use the sysfs to control the pwm of my raspberry pi 5. (I don't know about any libraries that are supported buy the pi-5 and can control pwm hardware.) Upon trying to test out the pwm by making an LED 50% brightness I ran into an issue where the pin wasn't outputting any value at all. I'm using pin 18 but I later swapped it to pin 12 (as pwm0 is sometimes pin 12) while troubleshooting - still no change. I also swapped around the period and duty_cycle values a few times from 10,000,000 and 5,000,000 respectively to 5000; 2500, but no change occurred. Here are the commands I used to communicate with the pwm:
cd /sys/class/pwm/pwmchip0
echo 0 > export
cd pwm0
echo ____ > period
echo ____ > duty_cycle
echo 1 > enable
Some things to note:
I realized I hadn't setup my pwm command line properly, so I went to /boot/firmware/config.txt and added a line of setup code. Here is the full config.txt file contents. (with the pwm command added)
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on
dtoverlay=pwm-2chan
Enable audio (loads snd_bcm2835)
dtparam=audio=on
Additional overlays and parameters are documented
/boot/firmware/overlays/README
Automatically load overlays for detected cameras
camera_auto_detect=1
Automatically load overlays for detected DSI displays
display_auto_detect=1
Automatically load initramfs files, if found
auto_initramfs=1
Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
Don't have the firmware create an initial video= setting in cmdline.txt.
Use the kernel's default instead.
disable_fw_kms_setup=1
Run in 64-bit mode
arm_64bit=1
Disable compensation for displays with overscan
disable_overscan=1
Run as fast as firmware / board allows
arm_boost=1
[cm4]
Enable host mode on the 2711 built-in XHCI USB controller.
This line should be removed if the legacy DWC2 controller is required
(e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[cm5]
dtoverlay=dwc2,dr_mode=host
[all]
When I went to /sys/kernel/debug/pwm it displayed:
pwm-0 (sysfs): requested enabled period: ___ ns duty: ___ ns polarity: normal
This probably means that the pwm is being outputted somewhere. Does anyone know what might be causing the pin 18/12 to output no value?
