I'm happy to announce that RPIO now includes PWM via DMA for very precise semi-hardware PWM. RPIO.PWM supports pulses with a maximum resolution of 1µs, all 15 available DMA channels and any number of GPIO's. Since it uses the same on-board PWM module as the sound card it may interfere with sound.
RPIO.PWM is written in C (source) and includes a Python wrapper compatible with Python 2 and 3. You can find the PWM documentation at pythonhosted.org/RPIO.The easiest way to install/update RPIO is with easy_install:
Code: Select all
$ sudo apt-get install python-setuptools
$ sudo easy_install -U RPIO
Code: Select all
# Setup PWM.Servo with the default 20ms subcycle
from RPIO import PWM
servo = PWM.Servo()

Code: Select all
# Set a 4000us (4ms) pulse every 20ms for GPIO 15:
servo.set_servo(15, 4000)

Code: Select all
# Now a 1000us (1ms) pulse for GPIO 17:
servo.set_servo(17, 1000)

Code: Select all
# We can use the low-level PWM methods to add further pulses to a subcycle:
PWM.add_channel_pulse(0, 17, 200, width=100)

Feedback is much appreciated!
Links
- Source code (GPLv3): https://github.com/metachris/RPIO
- Documentation: http://pythonhosted.org/RPIO
- C source of the PWM module: https://github.com/metachris/RPIO/tree/ ... urce/c_pwm
- https://pypi.python.org/pypi/RPIO