BeagleBoardPWM

There are three pins capable of PWM (pulse-width modulation) exposed on the C3/C4 BeagleBoard expansion header. PWM is useful for control of a number of devices, from LEDs (which can be faded smoothly with PWM) to DC motors. For robotics, this means that three hobby servos can easily be controlled by the Beagle given nothing more than a simple level-shifting circuit, with no CPU usage to speak of.

Alternative approaches are possible. servodrive is a kernel module that emits servo control PWM using straight GPIO (this page also claims that straight 1.8 V from the Beagle is sufficient to control servos). This page shows how to use threading and GPIO to accomplish PWM in userspace. The rest of this page focuses on use of the OMAP's hardware PWM capabilities.

OMAP Mux Configuration
Because the PWM pins are not set as such by default, the OMAP's mux must be configured to expose them before they can be used. See BeagleBoardPinMux for more details on this procedure. The short version is to add the following lines to the definition of  in arch/arm/mach-omap2/board-omap3beagle.c (this has been tested with the 2.6.33 OMAP branch of the kernel).

OMAP3_MUX(DSS_DATA15, OMAP_MUX_MODE2|OMAP_PIN_OUTPUT), /* GPT9_PWMEVT, ball AB26, ex pin 4 */ OMAP3_MUX(UART2_TX, OMAP_MUX_MODE2|OMAP_PIN_OUTPUT), /* GPT11_PWMEVT, ball AA25, ex pin 6 */ OMAP3_MUX(UART2_RTS, OMAP_MUX_MODE2|OMAP_PIN_OUTPUT), /* GTP10_PWMEVT, ball AB25, ex pin 10 */

Obviously these lines should precede the line terminating the array.

Note: Setting the kernel config option CONFIG_OMAP_RESET_CLOCKS to yes [| may cause problems].

Activating PWM via Timer Registers
PWM output on the BeagleBoard is done via the OMAP processor's general-purpose timer mechanism, described in the OMAP35x TRM in section 16.2.4 (page 2546). To briefly summarize this (and simplify significantly), the general-purpose timer is a continuously-incrementing counter that can be configured to toggle the PWM output high when a certain value is reached, and low when it overflows. By adjusting the first number the duty cycle can be set. Setting the value the counter starts at can be used to set the frequency of the PWM.





Each GP timer has a 4K block for memory-mapped registers (see TRM Table 16-12). The start addresses of these blocks for the timers on the BeagleBoard are listed below.

These are the registers relevant to our purpose:

Interacting with Timer Registers in Linux
The best way to interact with the timer registers is to use the kernel module in development as a Google Summer of Code project (this driver is currently, as of July 2010, in development).

Historically interaction with the registers could be done via the special device. This file contains a live view of the contents of physical memory --- meaning that reading and writing to the physical address of a timer register as an offset in  reflects the actual thing.

There is one complication, though, in that reads and writes to the OMAP registers cannot be done with byte-oriented I/O (such as the  system call); however, this can be worked around by using the   syscall. This means that a pointer to a register can be cast to  and function correctly.

OMAP3530 PWM library
There is a small library available to simplify manipulating the timer registers via. It is made available under the LGPL 2.1 or MIT license.

Download:
 * omap3530-pwm-1.1.tar.gz (LGPL/MIT, md5 b33232531321778eadc022fef9cf7bac)
 * omap3530-pwm-1.0.tar.gz (LGPL only, md5 ff77617cf07450be1444019809c75a0c)

Links and References

 * PWM from an OMAP3 Linux System, Scott Ellis (kernel module)
 * 2010 GSoC Project: PWM driver
 * OMAP 3530 Technical Reference Manaul
 * BeagleBoard System Reference Manaul
 * [[Media:I2C_PWM_Hardware.pdf|Presentation on I2C, PWM and Hardware interfacing with the BeagleBoard]]
 * Project: Sumo Robot -- uses PWM to control drive motors via L298 motor drivers.
 * [[Media:I2C_PWM_Hardware.pdf|Presentation on I2C, PWM and Hardware interfacing with the BeagleBoard]]
 * Project: Sumo Robot -- uses PWM to control drive motors via L298 motor drivers.