How to use PWM on Xavier NX

hello Andrey1984,

Jetson Xavier NX has four Pulse Width Modulator (PWM) outputs.
they’re pin-206/GPIO07; pin-218/GPIO12; pin-228/GPIO13; pin-230/GPIO14.

so, you should have pin customization to set those pin as PWM.
thanks

@JerryChang
Thank you for your response.
What exactly customization would be required to set these four? Coudl you extend, please?
Just the jetson-io utility won’t manage it, will it?
Which examtly steps will need to be implemented in order to get these four activated? With use of jetson-io? without use of jetson-io?

hello Andrey1984,

may I know which pin you’re not able to configure it as PWM?

Jetson-IO tool to simplify the configuration of the I/Os exposed by the 40‑pin expansion header.
please have pinmux spreadsheet customize to update the cfg for the board configuration, you should modify the customer usage to toggle the pin as PWM through pinmux.
thanks

@JerryChang
from devs:
" pins that are marked blue (so routed to 40-pin header) only has 3 PWM available pins
GPIO14 is not routed to this header
soldering to some SOC place is bad idea I guess
and FAN pin present on SOC is not clear for me"

hello Andrey1984,

that’s correct.

as you can see from the pinmux spreadsheet.
there shows the sample usage that pin-230/GPIO14 is used by baseboard FAN PWM.
you may used that if you’re having your own carrier board design.
thanks

@JerryChang
Thank you for following up!
What are the choices to use the devkit nx developers board with 4PWM, is it possible? how to rearrange the GPIO14 also address the FAN somehow?
After cfg got generated which are the further steps ?
Whuch files to move to where?
Which command to use for flashing?

@JerryChang
from devs [ they updated pinmux → cfg]
then flashed nx with flash.sh from sdkmanager folder
"
works for 2 PWM
on pins 32 and 33
tested with jetson-gpio
seems its not available to test PWM on FAN pin from it
as well as PWM on board pin 15 doesn’t work too"

hello Andrey1984,

if you don’t have fan, you can use that PWM for something else.

@JerryChang
Thank you for your response
we got the nx devkit
I am trying to assist remote dev to get 4PWM that is a fixed requirement.
However they were able to get only 2 PWM .
Will you be able to give a helping hand with getting all four somehow? Or at least 3 at the very beginning? What are the options to detach the fan from devkit NX without it getting burned overheated?

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