Jetson/PWM

= PWM = Pulse Width Modulation (PWM) is often used to control the speed of motors and servo motors or even LEDs, since PWM uses fast digital pulses instead of a continuous analog output voltage. Jetson TK1 offers 2 options for PWM output:
 * 1) PWM on an external microcontroller such as an Arduino board. This is by far the easiest & best option.
 * 2) PWM directly in Tegra. This is more tricky and might not give as stable a signal timing.

Note that motors usually require a separate power supply than what Jetson provides. Some low-power motors might be OK with the power available in Jetson power pins or from a USB port but most motors need more power such as directly from the battery or power supply instead of getting power from Jetson or from the Arduino.

PWM on an external microcontroller
The easiest solution for PWM by far is to: connect to Arduino from Jetson TK1, so that your main program running on Jetson decides what the motors should do, and it sends that info to an Arduino that does the actual PWM control. To control motors or servo motors, you can either attach a servo motor shield onto a regular Arduino, or use an Arduino clone that includes its own servo motor controller electronics so it didn't need a separate motor controller shield. But if you use a regular Arduino then the easiest solution would be to add a servo motor shield to a regular Arduino. Because low-level real-time operations like PWM need consistent "hard-realtime" timing that a microcontroller is much more suited to than a big CPU / Application Processor like Tegra.

To send the info to an Arduino or any microcontroller from Jetson TK1, follow the GPIO info about 5V GPIO outputs if you just need 1-way communication, or use a serial UART connection (or even I2C) from Jetson TK1 to the Arduino if you want 2-way communication.

PWM directly in Tegra
You can control PWM output via sysfs at runtime, similar to how you can use GPIO using sysfs. You’ll need to make sure that the pinmux is set up so that PWM is routed to the pin, and that the GPIO for that pin is not claimed, so that the pinmux function is not overridden. Again, you’ll need the following in .config: CONFIG_PWM_SYSFS=y

Then: cd /sys/devices/soc0/7000a000.pwm/pwm/pwmchip0

Note: In the L4T kernel, the “soc0” directory component might not be there, and the PWM controller might be named something different like “pwm.0” or “pwm.1”. You might want to just run: cd /sys find. –type d –name "pwmchip*"

Note: You might need to replace “0” in the commands below with a different PWM channel ID: echo 0 > export cd pwm0 echo 1000000 > period echo 500000 > duty_cycle   # or whatever number 0..period you want; you can write to this file later to change the duty cycle echo 1 > enable

and when you’re done: cd .. echo 0 > unexport