Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3552

Troubleshooting • Re: Hardware PWM not working with Raspberry Pi 5 4GB

$
0
0
I can only do not the 'noob' way!

Here is the overlay which I've wrote for this demo. Might not be the most elegant one, but working.

Code:

/* * pwm-gpio12-overlay.dts *//dts-v1/;/plugin/;//#include <dt-bindings/gpio/gpio.h>//#include <dt-bindings/leds/common.h>/ {compatible = "brcm,bcm2835";fragment@0 {target = <&gpio>;__overlay__ {pwm_pins: pwm_pins {brcm,pins = <12>;brcm,function = <4>; /* ALT4 = PWM out */brcm,pull = <0>;};};};fragment@1 {target = <&pwm>;frag1: __overlay__ {pinctrl-names = "default";pinctrl-0 = <&pwm_pins>;/* in Hz */assigned-clock-rates = <750000000>;status = "okay";};};fragment@2 {target-path = "/";__overlay__ {leds: leds@0 {compatible = "pwm-leds";     status = "okay";// available PWM range for LED 0 - 255// PWM LED on PWM0.0 on GPIO12status0: status0 {label = "status0";pwms = <&pwm 0 3500000 0>;pwm-names = "status0";linux,default-trigger = "none";};};};};};
Is configures a PWM controllable LED, 256 brightness steps (duty cycles) are available that way.

A compiled overlay is attached. If you load that (via your config.txt) you can adjust the brightness like shown below. The second block shows the PWM outputs after each command.

USE 'sudo -I' AT OWN RISK!!!!

Code:

pi@book13th:~ $ sudo -iSSH is enabled and the default password for the 'pi' user has not been changed.This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.root@book13th:~# echo 155 > /sys/class/leds/status0/brightnessroot@book13th:~# echo 90 > /sys/class/leds/status0/brightnessroot@book13th:~# echo 0  > /sys/class/leds/status0/brightnessroot@book13th:~# echo 255  > /sys/class/leds/status0/brightnessroot@book13th:~# exitlogoutpi@book13th:~ $ 
LED is off after boot.
Setting the brightness to 155 --> PWM duty is 2127450 ns
Setting the brightness to 90 --> PWM duty is 1235294 ns
Setting the brightness to 0 --> PWM duty is 0 ns
Setting the brightness to 255 --> PWM duty is 3500000 ns

Code:

pi@book13th:~ $ sudo cat /sys/kernel/debug/pwmplatform/1f0009c000.pwm, 4 PWM devices pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   (cooling_fan         ): requested enabled period: 41566 ns duty: 24450 ns polarity: inverse usage_powerplatform/1f00098000.pwm, 4 PWM devices pwm-0   (status0             ): requested enabled period: 3500000 ns duty: 0 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   ((null)              ): period: 0 ns duty: 0 ns polarity: normalplatform/107d517a80.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: normalpi@book13th:~ $ sudo cat /sys/kernel/debug/pwmplatform/1f0009c000.pwm, 4 PWM devices pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   (cooling_fan         ): requested enabled period: 41566 ns duty: 24450 ns polarity: inverse usage_powerplatform/1f00098000.pwm, 4 PWM devices pwm-0   (status0             ): requested enabled period: 3500000 ns duty: 2127450 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   ((null)              ): period: 0 ns duty: 0 ns polarity: normalplatform/107d517a80.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: normalpi@book13th:~ $ sudo cat /sys/kernel/debug/pwmplatform/1f0009c000.pwm, 4 PWM devices pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   (cooling_fan         ): requested enabled period: 41566 ns duty: 24450 ns polarity: inverse usage_powerplatform/1f00098000.pwm, 4 PWM devices pwm-0   (status0             ): requested enabled period: 3500000 ns duty: 1235294 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   ((null)              ): period: 0 ns duty: 0 ns polarity: normalplatform/107d517a80.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: normalpi@book13th:~ $ sudo cat /sys/kernel/debug/pwmplatform/1f0009c000.pwm, 4 PWM devices pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   (cooling_fan         ): requested enabled period: 41566 ns duty: 24450 ns polarity: inverse usage_powerplatform/1f00098000.pwm, 4 PWM devices pwm-0   (status0             ): requested enabled period: 3500000 ns duty: 0 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   ((null)              ): period: 0 ns duty: 0 ns polarity: normalplatform/107d517a80.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: normalpi@book13th:~ $ sudo cat /sys/kernel/debug/pwmplatform/1f0009c000.pwm, 4 PWM devices pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   (cooling_fan         ): requested enabled period: 41566 ns duty: 24450 ns polarity: inverse usage_powerplatform/1f00098000.pwm, 4 PWM devices pwm-0   (status0             ): requested enabled period: 3500000 ns duty: 3500000 ns polarity: normal pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal pwm-3   ((null)              ): period: 0 ns duty: 0 ns polarity: normalplatform/107d517a80.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
pwm-gpio12.dtbo.zip

Statistics: Posted by aBUGSworstnightmare — Mon Mar 04, 2024 3:57 pm



Viewing all articles
Browse latest Browse all 3552

Trending Articles