raspberry pi 4B unable to activate both hardware pwm channels
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
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
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
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
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
- aBUGSworstnightmare
- Posts: 13432
- Joined: Tue Jun 30, 2015 1:35 pm
Re: raspberry pi 4B unable to activate both hardware pwm channels
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
Code: Select all
pi@cm4nanob:~ $ pinctrl get 12,13
12: a0 pd | lo // GPIO12 = PWM0_0
13: a0 pd | lo // GPIO13 = PWM0_1Re: raspberry pi 4B unable to activate both hardware pwm channels
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
however result is exactly same this is what im running
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)
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
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;
}
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)
- aBUGSworstnightmare
- Posts: 13432
- Joined: Tue Jun 30, 2015 1:35 pm
Re: raspberry pi 4B unable to activate both hardware pwm channels
both PWM channels are active, will dot digest your SW though.
this is for disabling HDMI audio
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
Now change to the folder for pwmchip0.
As nothing has claimed them one will have to do this manually
Now we have two PWM devices available.
Let's configure the first one and fire it up.
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.
as my oszillocope is showing me two PWM's (one with 100kHz and another with 200kHz) I consider this as closed for me.
this is for disabling HDMI audio
Code: Select all
dtoverlay=vc4-kms-v3d,noaudio
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_1Code: Select all
pi@cm4nanob:~ $ cd /sys/class/pwm
pi@cm4nanob:/sys/class/pwm $ cd pwmchip0Code: 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 unexportLet'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: normalLet'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: normalReturn to "Interfacing (DSI, CSI, I2C, etc.)"
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion