Integrate PWM driver for DC motors with Jetson nano

Van Malleghem Antoine
3 min readMar 22, 2023

--

If you like this article, don’t hesitate to like and/or comment it. You can also follow me for more stories around robotics / embedded systems. Thanks in advance for your support.

In this story, I would like to explain how you can integrate a Nvidia Jetson Nano with an Hat-MDD10 to drive your DC motors with PWM.

Hardware setup

From the Hat-MDD10 official User’s Manual, you can find the following picture :

Hardware configuration of the Hat-MDD10

From Nvidia documentation, you can find that you have 2 PWM pins on your Nano: 32 (PWM0) and 33 (PWM2). For directions, you can use the GPIO pins you want (we choose 12 and 13).

One remaining task : don’t forget the ground ! We choose pin 25 of the header on Jetson Nano

In summary :

  • PWM1 is connected to the pin33 of the header on Jetson Nano
  • PWM2 is connected to the pin32 of the header on the Jetson Nano
  • DIR1 is connected to the pin13 of the header on the Jetson Nano
  • DIR2 is connected to the pin12 of the header on the Jetson Nano
  • GND is connected to the pin25 of the header on the Jetson Nano
Global setup

Software setup

Now that everything is connected, you must set the pin 32 and 33 as PWM pins. Otherwise, you will not be able to send PWM commands. There is several ways to do so. I tried 4 different ways. Let me explain my conclusions for each tentative.

sudo /opt/nvidia/jetson-io/jetson-io.py
# UI :
# - Configure Jetson 40pin
# - Configure header pins manually
# - Activate pwm0 [32] and pwm2 [33]
# - Save
# - Reboot

This way is the easiest way proposed by Nvidia but I tried it and looks like it doesn’t work. I guess it depends on several things like the Jetpack version for example.

sudo /opt/nvidia/jetson-io/config-by-function.py 1="pwm0 pwm2" -o dtbo
dtc -I dtb -O dts -o my-overlay.dts /boot/kernel_tegra210-p3448-0000-p3449-0000-b00-hdr40-user-custom.dtbo
dtc -O dtb -o my-overlay.dtbo -@ my-overlay.dts
sudo cp my-overlay.dtbo /boot

This does the same as the first way but programmaticaly. Consequently, it doesn’t work on my Nano.

  • Manually using busybox
# Enable pin 32 / PWM0
sudo busybox devmem 0x700031fc 32 0x45
sudo busybox devmem 0x6000d504 32 0x2

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

And guess what, it works ! You can now control your motors with PWM. Unfortunately, you will see that it stops working if you reboot your Nano. To solve this issue, put these 4 commands (without sudo) into the “rc.local” file and enable the related service.

In my opinion, this is more a workaround than the cleanest solution but at least it allows you to quickly have a working solution.

  • With pinmux

This is the best, cleanest and recommended way to accomplish this task. Unfortunately, you have to re-compile Uboot, re-flash your SD card and you need a Windows to use a provided excel sheet. If you want to implement it, here is a great link : https://www.seeedstudio.com/blog/2020/05/27/configure-pwm-output-on-jetson-nano-m/

You can find the last version of the excel sheet here : https://developer.nvidia.com/jetson-nano-pinmux

Don’t hesitate to contact me if you have any question. If you want to follow our project, you can visit our website and register to our newsletter : https://www.otto-project.golf/ (it is in french for now but your browser is able to deal with it I think).

--

--

Van Malleghem Antoine

I’m here to automate the world with robots and softwares. Golang and ROS enthusiast, I’m a true sotfware craftman. Always available for a coffee, contact me !