Nano PWM C++

Trying to do PWM with Jetson Nano.

Using the library at . Seems to work ok for GPIOs and for PWM0 (pin 33) (at least to instantiate the PWM control code). If I try to instantiate a PWM instance for Pin 32, my application immediately crashes with:

[Exception] Can’t open /export (catched from: PWM::PWM())
terminate called after throwing an instance of ‘std::runtime_error’
what(): Can’t open /export
Aborted (core dumped)

I’ve enabled both PWM channels using the tool, I’ve installed the JetsonGPIO library, the /sys/kernel/debug/pinctrl/700008d4.pinmux/pinmux-pins file shows the following:
root@jetson-robot:/sys/kernel/debug/pinctrl/700008d4.pinmux# cat pinmux-pins | grep -i pwm
pin 38 (PE6): 700008d4.pinmux (GPIO UNCLAIMED) (HOG) function pwm2 group pe6
pin 168 (LCD_BL_PWM PV0): 700008d4.pinmux (GPIO UNCLAIMED) (HOG) function pwm0 group lcd_bl_pwm_pv0

output from sudo cat /sys/kernel/debug/pwm is:

platform/70110000.pwm, 1 PWM device
pwm-0 (pwm-regulator ): requested enabled period: 2500 ns duty: 0 ns polarity: normal

platform/7000a000.pwm, 4 PWM devices
pwm-0 (sysfs ): requested period: 0 ns duty: 0 ns polarity: normal
pwm-1 (pwm-regulator ): requested enabled period: 8000 ns duty: 1440 ns polarity: normal
pwm-2 ((null) ): period: 20000000 ns duty: 10000000 ns polarity: normal
pwm-3 (pwm-fan ): requested enabled period: 45334 ns duty: 0 ns polarity: normal

Any ideas on how to troubleshoot? My project needs the two different frequency PWM outputs.


hello nvidia5,

the pin LCD_BL_PWM is default configure as GPIO pin,
could you please access Pinmux spreadsheet through download center.
please also refer to Configuring the 40-pin Expansion Header, and you’ll need to configure the pin as PWM for verification.

Ok, so am I incorrect in believing that this configuration is supposed to be handled by – as the second link you posted says?

I’ve configured it as a pwm pin using the procedure in that link.

Any other ideas?

@JerryChang – am I incorrect in my understanding here?

please check the last paragraph of,

The system pinmux must be configured to connect the hardware PWM controlller(s) to the relevant pins. If the pinmux is not configured, PWM signals will not reach the pins! The JetsonGPIO library does not dynamically modify the pinmux configuration to achieve this. Read the L4T documentation for details on how to configure the pinmux.

you should have pinmux configuration to set the pin as PWM, then you’ll able to use it.

I’m aware of that.

The document you’re quoting is seven months old, before and the latest version of the jetson nano software was released.

The question I’m asking is did not the replace the pinmux spreadsheet configuration method as it seems to be from your second link posted above? If not, what’s the purpose of

hello Josh1745,

pinmux spreadsheet shows the default pin configurations; you’ll need to have customization and then flash the new configuration to the developer kit if you have different pin configurations.
Jetson-IO could overwrite the pin configuration dynamically.

if Jetson-io overwrites the pin configuration dynamically, why doesn’t the second PWM pin work when it’s told to configure it as a pwm pin?

The reason I’m really asking is that the pinmux configuration procedure documented in your documentation doesn’t work, so I’ve got to find another way.

hello Josh1745,

could you please refer to Control PWM through sysfs to configure PWM0, this process should be similar in Nano.

here also a discussion thread Topic 107310, which show the steps to control the PWM.

Thanks for the links. I’ve been through all of that already.

Here’s the output when I run through trying to manually export both PWM pins:

josh@jetson-robot:/sys/class/pwm$ ls
pwmchip0 pwmchip4
josh@jetson-robot:/sys/class/pwm$ ls pwmchip0/
device export npwm power subsystem uevent unexport
josh@jetson-robot:/sys/class/pwm$ cd pwmchip0/
josh@jetson-robot:/sys/class/pwm/pwmchip0$ echo 0 > export
josh@jetson-robot:/sys/class/pwm/pwmchip0$ ls
device export npwm power pwm0 subsystem uevent unexport
josh@jetson-robot:/sys/class/pwm/pwmchip0$ cd …
josh@jetson-robot:/sys/class/pwm$ cd pwmchip4/
josh@jetson-robot:/sys/class/pwm/pwmchip4$ ls
device export npwm power subsystem uevent unexport
josh@jetson-robot:/sys/class/pwm/pwmchip4$ echo 0 > export
-bash: echo: write error: Device or resource busy

Hi Josh1745,

You can only access pwmchip0 (@7000a000).
pwmchip4(@70110000) is not expected to be used by user.

“The Pulse Width Modulator controller is a four channel frequency divider whose pulse width varies. Each channel has a programmable frequency divider and a programmable pulse width generator”

As per the above statement, individual 4 channels of pwm@pwmchip0 can be used (based on availability) by exporting them.
i.e. echo <0/1/2/3> > /sys/class/pwm/pwmchip0/export

Please try with above and let us know what problem do you face on your configuration.

Thanks & Regards,

1 Like

Sandipan – thank you very much for that clarification. I understand now, and I can at least manually set the parameters and activate the second PWM line.

Greatly appreciated!

In addition to the misconception I had here that was explained above by Sandipan, the library I referenced in the OP is broken. I’ve fixed the library and the working library is at this link:

1 Like