PWM pins

I am able to use the pin 33 as pwm but cant do same for pin 32,getting the following error:

Traceback (most recent call last):
File “ras.py”, line 44, in
main()
File “ras.py”, line 20, in main
p = GPIO.PWM(output_pin, 100)
File “/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py”, line 595, in init
_export_pwm(self._ch_info)
File “/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py”, line 231, in _export_pwm
f.write(str(ch_info.pwm_id))
OSError: [Errno 16] Device or resource busy

I am using two dc motors to control a robot.

hello sagar16eligar,

according to Jetson Nano GPIO Header PINOUT, may I know would you like to control pin-33 of J41?
thanks

I was able to control pin-33 but it’s with the pin 32 I am getting the errors.
Traceback (most recent call last):
File “ras.py”, line 44, in
main()
File “ras.py”, line 20, in main
p = GPIO.PWM(output_pin, 100)
File “/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py”, line 595, in init
_export_pwm(self._ch_info)
File “/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py”, line 231, in _export_pwm
f.write(str(ch_info.pwm_id))
OSError: [Errno 16] Device or resource busy

I am using two DC motors, so there are two PWM pins to connect.

hello sagar16eligar,

assume you’re control pin-33 of J41.
may I know had you done the customize through pinmux spreadsheet for configuration,
you should be follow below steps to control the PWM.

  1. change the gpio pin to pwm pin in pinmux spreadsheet
  2. generate the dtsi
  3. Use this dtsi to rebuild the dtb.
  4. Use this dtb to reflash the board
  5. Use the debugfs to control the pwm.

Thank you very much for your reply. I am really new to electronics stuff, are there any links or videos explaining these steps??

Dear JerryChang, do you have videos explaining these steps?? Thanks

hello nguyennhantinh,

there’s no training video to cover that.
you may access the application note, Jetson Nano Developer Kit 40-Pin Expansion Header Configuration by using the Nano pinmux spreadsheet.
thanks

Dear JerryChang
I used command bellow to config PWM:

# Enable Pin 32 / PWM0
busybox devmem 0x700031fc 32 0x45
busybox devmem 0x6000d504 32 0x2

# Enable Pin 33 / PWM2
busybox devmem 0x70003248 32 0x46
busybox devmem 0x6000d100 32 0x00

# Then enable & control the pwm, e.g.
cd /sys/devices/7000a000.pwm/pwm/pwmchip0
|--echo 0 > export  # Control PWM0 on Pin 32
|--echo 2 > export  # Control PWM2 on Pin 33

then Pin 33 can run with above command, but Pin 32 got error:

bash: echo: write error: Device or resource busy

I check PWM status:

sudo cat /sys/kernel/debug/pwm

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

Please help me fix this issue. Thanks

hello nguyennhantinh,

it seems pwm-0 (lightbar) is already opened, hence you cannot control it.
according to below, this should enabled by default.

<i>$l4t-r32.2/public_sources/kernel_src/hardware/nvidia/platform/t210b01/porg/kernel-dts/tegra210b01-porg-p3448-common.dtsi</i>

	pwm-leds {
 		compatible = "pwm-leds";
 		lightbar {
 			label = "led_lightbar";
 			pwms = <&tegra_pwm 0 40161>;
 			gpios = <&gpio TEGRA_GPIO(V, 0) GPIO_ACTIVE_LOW>;
 			max-brightness = <255>;
 			default-brightness = <255>;
 			linux,default-trigger = "default-on";
 		};

please review your device tree configurations, you might also have modification to disable it.
thanks

We used the /opt/nvidia/jetson-io/jetson-io.py utility to enable PWM on both pins 33 and 32, this seems to be permanent even after reboot, avoiding pinmux flash.

The problem is, it works totally different than raspberry GPiO and gpiozero lib, and we are not able to control traxxas servos. Can it be because of the frequency?

We used pigpiod pin_factory for the software PWM on raspberry and this seems to have default 5 microseconds sample rate, can we achieve the same with the hardware PWM in jetson?

root@jetson:/sys/devices/7000a000.pwm/pwm/pwmchip0/pwm0# echo 5000 > period
-bash: echo: write error: Invalid argument

Hi @razvan.grigore,

I am just wondering that have you manage to fix the issue?

no, we use a separate PWM driver board from adafruit, 16 channels.

Would be great if nvidia would answer officially.

Thank you for the answer. Hmm, I see… Yes, it needs to be solved.