Page 1 of 1

raspberry pi 4B unable to activate both hardware pwm channels

Posted: Mon Nov 10, 2025 2:18 am
by rymer
hello im trying to make 2 pwm signals on 25kHz however no matter what i do only 1 channel ever actually works and second channel has no output

its always 13/19 (pwm1) that works and 12/18 (pwm0) never works

at this point after maybe 20 hours of trial and error i think i tried everything so to list few of my failed attemtps
- dtoverlay=pwm-2chan
- different combinations of values in dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func=2
- 18/19 and 12/13 switching around
- dtoverlay=vc4-kms-v3d,noaudio
- dtparam=audio=off
- different ways of interacting - python, c++, directly editing files in /sys/class/pwm/pwmchip0

so far i didnt notice any errors in programming for example in c++ output of gpioHardwarePWM is 0 which is ok

it doesnt matter what i try it just has no output no duty cycle no frequency nothing

i got 2 raspberries and they have exactly same issue both are pretty much new so i dont think this is actual defect of hardware

im checking it with multimeter

Re: raspberry pi 4B unable to activate both hardware pwm channels

Posted: Mon Nov 10, 2025 2:01 pm
by rymer
i have no idea why is this in this category i didnt make it here

edit: i made it in correct category however im not allowed to delete this post

Re: raspberry pi 4B unable to activate both hardware pwm channels

Posted: Mon Nov 10, 2025 2:30 pm
by DirkS
rymer wrote:
Mon Nov 10, 2025 2:01 pm
i have no idea why is this in this category i didnt make it here

edit: i made it in correct category however im not allowed to delete this post
Mods decide which category is best for your topic.
Posting in a section that deals with the matter (interfacing in this case) gives you a better chance of getting relevant responses

Re: raspberry pi 4B unable to activate both hardware pwm channels

Posted: Mon Nov 10, 2025 4:11 pm
by aBUGSworstnightmare
rymer wrote:
Mon Nov 10, 2025 2:18 am
,,
- different combinations of values in dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func=2
..
Please spot the failure!
Yes, your parameters are wrong as you've failed to use 'func2' parameter (https://github.com/raspberrypi/linux/bl ... ay.dts#L45) when selecting the correct ALT mode
https://github.com/raspberrypi/linux/bl ... .dts#L7-L9

adding/changing

Code: Select all

#dtparam=audio=on
dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4
results here with me in

Code: Select all

pi@cm4nanob:~ $ pinctrl get 12,13
12: a0 pd | lo // GPIO12 = PWM0_0
13: a0 pd | lo // GPIO13 = PWM0_1

Re: raspberry pi 4B unable to activate both hardware pwm channels

Posted: Mon Nov 10, 2025 7:42 pm
by rymer
i think i tried this combination already too but for good measure i just retested it also for good measure i will post my entire config

Code: Select all

# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
# Enable audio (loads snd_bcm2835)
dtparam=audio=off
# 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
# 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]
dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4
dtoverlay=vc4-kms-v3d,noaudio
however result is exactly same this is what im running

Code: Select all

#include <signal.h>
#include <unistd.h>
#include <pigpio.h>
#include <stdio.h>
volatile bool running = true;
void stop(int) {
 running = false;
}
constexpr int PWM_1 = 12;
constexpr int PWM_2 = 13;
int main() {
 if (gpioInitialise() < 0) {
 return 1;
 }
 int r1 = gpioHardwarePWM(PWM_1, 25000, 750000);
 int r2 = gpioHardwarePWM(PWM_2, 25000, 250000);
 fprintf(stderr, "PWM%d=%d PWM%d=%d\n", PWM_1, r1, PWM_2, r2);
 signal(SIGINT, stop);
 signal(SIGTERM, stop);
 while (running) {
 sleep(1);
 }
 gpioHardwarePWM(PWM_1, 0, 0);
 gpioHardwarePWM(PWM_2, 0, 0);
 gpioTerminate();
 return 0;
}
results
pin 12 no frequency no duty
pin 13 25kHz 25%

internal@raspberrypi:~/controller $ pinctrl get 12,13
12: a0 pd | lo // GPIO12 = PWM0_0
13: a0 pd | lo // GPIO13 = PWM0_1

(yes i rebooted before testing)

Re: raspberry pi 4B unable to activate both hardware pwm channels

Posted: Tue Nov 11, 2025 6:00 am
by aBUGSworstnightmare
both PWM channels are active, will dot digest your SW though.

this is for disabling HDMI audio

Code: Select all

dtoverlay=vc4-kms-v3d,noaudio
and doesn't matter to PWM

EDIT:
as I have no idea what you're doing and how you're testing let me show you how I would
having the overlay loaded first check if the two PWM nodes got created

Code: Select all

pi@cm4nanob:~ $ sudo cat /sys/kernel/debug/pwm
0: platform/fe20c000.pwm, 2 PWM devices
 pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1 ((null) ): period: 0 ns duty: 0 ns polarity: normal
pi@cm4nanob:~ $ pinctrl get 12,13
12: a0 pd | lo // GPIO12 = PWM0_0
13: a0 pd | lo // GPIO13 = PWM0_1
Now change to the folder for pwmchip0.

Code: Select all

pi@cm4nanob:~ $ cd /sys/class/pwm
pi@cm4nanob:/sys/class/pwm $ cd pwmchip0
As nothing has claimed them one will have to do this manually

Code: Select all

pi@cm4nanob:/sys/class/pwm/pwmchip0 $ echo 0 > export
pi@cm4nanob:/sys/class/pwm/pwmchip0 $ echo 1 > export
pi@cm4nanob:/sys/class/pwm/pwmchip0 $ dir
device	export	npwm power pwm0 pwm1 subsystem uevent unexport
Now we have two PWM devices available.

Let's configure the first one and fire it up.

Code: Select all

pi@cm4nanob:/sys/class/pwm/pwmchip0 $ cd pwm0
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm0 $ echo 10000 > period
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm0 $ echo 6000 > duty_cycle
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm0 $ echo 1 > enable
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm0 $ sudo cat /sys/kernel/debug/pwm
0: platform/fe20c000.pwm, 2 PWM devices
 pwm-0 (sysfs ): requested enabled period: 10000 ns duty: 6000 ns polarity: normal
 pwm-1 (sysfs ): requested period: 0 ns duty: 0 ns polarity: normal
as you can see PWM0 is active now, there is nothing for PWM1 so far.

Let's configure that as well and start it to.

Code: Select all

pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm0 $ cd /sys/class/pwm/pwmchip0/pwm1
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm1 $ echo 5000 > period
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm1 $ echo 3000 > duty_cycle
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm1 $ echo 1 > enable
pi@cm4nanob:/sys/class/pwm/pwmchip0/pwm1 $ sudo cat /sys/kernel/debug/pwm
0: platform/fe20c000.pwm, 2 PWM devices
 pwm-0 (sysfs ): requested enabled period: 10000 ns duty: 6000 ns polarity: normal
 pwm-1 (sysfs ): requested enabled period: 5000 ns duty: 3000 ns polarity: normal
as my oszillocope is showing me two PWM's (one with 100kHz and another with 200kHz) I consider this as closed for me.

AltStyle によって変換されたページ (->オリジナル) /