How to use PWM on Xavier NX

Can you share some examples how any of 4 available PWM’s can be programmed ( Examples of using PWM by some new lib rather then jetson-gpio) ? Jetson-gpio gives no access to the FAN PWM and PWM on pin15 doesn’t work (only PWM on pins 32/33 works fine from this lib)

hello krestyaninovivan,

please check pinmux spreadsheets to have pin customization, please update customer usage column according to your settings. you should also check developer guide, MB1 Configuration Changes, and also, please execute the python script, $OUT/Linux_for_Tegra/kernel/pinmux/t19x/pinmux-dts2cfg.py to convert pinmux, gpio and pad dts file into cfg format for your target.
if that’s still not working, please share the values in the pin configurations (*.cfg) for reference,
thanks

@JerryChang Thank you for following up!
Could you also point out an example on how to code pwm after the pinmux configuration? code with c? python? sysfs? else? What are the choices with examples?
As I understand the jetson.gpio examples allowed to address somehow two PWM from the set of PWMs that are from GPIOs header.
Are ther ealso examples on how to address/sode the rest of PWMs including the Fan PWM?
So that all 4 PWM will be coded somehow?

please check debug node for PWMs, # cat /sys/kernel/debug/pwm

here’s shows an example to enable PWM for using,
please acquire pwm channel with command, $ echo 0 > /sys/class/pwm/pwmchip1/export.
after running above command, pwm0 folder will be created under /sys/class/pwm/pwmchip1/pwm0.
there’s PWM waveform configuration attributes present under /sys/class/pwm/pwmchip1/pwm0
you may use below commands to configure PWM via sysnodes, configure the period in nano-seconds.
$ echo <value> > /sys/class/pwm/pwmchip1/pwm0/period
$ echo <value> > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
after that, please enable PWM to make it works, $ echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

Thank you for your response
The jetson gpio example won’t allow accessing the fan’s PWM but sysfs will do, right?
Jetson/PWM - eLinux.org
jetson-gpio/simple_pwm.py at master · NVIDIA/jetson-gpio · GitHub
will the debug example also work for pwm2, pwm3, pwm4?

hello Andrey1984,

yes, please have a try.
you may share the steps in details for reference if you need further supports.
thanks

@JerryChang, unfortunately, developers failed to implement 4 PWM on devkit NX using instructions from this thread, so they had to use raspberry for 4PWM to control 4 motors

I was reading the various threads on enabling PWM on NX. I was able to get 3 PWMs working on the NX development board.

  1. Flash fresh copy of jp46 sd card image
  2. Use jetson-io to enable PWM on pins 15/32/33 of J12 of development board.
  3. Use pinmux spreadsheet and trial and error to learn which pwmchip in linux corresponds to each pin. I discovered pin 15/32/33 correspond to pwmchip1/pwmchip4/pwmchip0 in linux.
  4. Use bash script below to twiddle 120hz 50% duty square wave on pin15
  5. Use scope to check for the square wave.
  6. Adjust period/duty_cycle live and watch changes on scope. Units seem to be ns, so 8333333ns = 8.333333ms = 120hz for period.

Bash script with no error checking to generate 120hz square wave on pin 15:
#!/bin/bash
echo 0 > /sys/class/pwm/pwmchip1/export
echo 8333333 > /sys/class/pwm/pwmchip1/pwm0/period
echo 4166667 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
cat /sys/kernel/debug/pwm

Pins 32/33 also work. In the above bash, use “pwmchip4” for pin 32, and use “pwmchip0” for pin33.

The dev board appears to bring out only 3 PWMs (not 4). However from basic sanity check I can see PWM on all 3 pins which is sufficient for my usecase. We’ll see if I can get this to work via pinmux spreadsheet instead of jetson-io as well as stress testing vs sanity check with scope.

hello, if you dont mind can i see the simplest sample code you used for a servo motor to work when connected on pwm pin? thanks

please also refer to comment #30, you may have a test via PWM debug nodes.

1 Like