User avatar
metachris
Posts: 96
Joined: Wed Feb 06, 2013 1:52 pm
Location: Vienna, Austria

Crosspost, New: Pulse-width modulation with RPIO.PWM

Sun Mar 10, 2013 5:38 pm

Sorry for crossposting, but I think this may be interesting for a lot of people not reading the Interfacing forum.

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
Here is an example with oscilloscope output (GPIO 15 is the blue channel, GPIO 17 the yellow one):

Code: Select all

# Setup PWM.Servo with the default 20ms subcycle
from RPIO import PWM
servo = PWM.Servo()
Image

Code: Select all

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

Code: Select all

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

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)
Image

Feedback is much appreciated!

Links
pythonhosted.org/RPIO

mattvenn
Posts: 24
Joined: Wed Jul 25, 2012 9:59 am

Re: Crosspost, New: Pulse-width modulation with RPIO.PWM

Fri Mar 22, 2013 7:34 pm

excellent!!! Worked no problems on the only pin I tried it on.
I'll be using this in my upcoming workshops.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm

Re: Crosspost, New: Pulse-width modulation with RPIO.PWM

Sat Mar 23, 2013 10:30 am

I agree great work, thanks for coding this.
Batteries not included, Some assembly required.

User avatar
jacksparrow
Posts: 13
Joined: Mon Mar 04, 2013 5:37 pm

Re: Crosspost, New: Pulse-width modulation with RPIO.PWM

Sat Mar 23, 2013 12:58 pm

Great work.Looks alike it's going to save me lot of time at work.

hradec
Posts: 7
Joined: Mon Apr 15, 2013 2:36 am

Re: Crosspost, New: Pulse-width modulation with RPIO.PWM

Mon Apr 15, 2013 3:45 am

Brilliant matte!!!! Congratulations!!!

I was wondering if this DMA approach allows a "maximum" number of pulses, so the pulses would stop after it's reached?

If so, this method could also be used to reliably control stepper drivers, like pololu 4988 ones.

anyhow... just brilliant!!!

cheers matte...
-H

ProudRoach
Posts: 3
Joined: Wed Mar 14, 2018 1:34 am

Re: Crosspost, New: Pulse-width modulation with RPIO.PWM

Wed Dec 05, 2018 7:36 pm

So is it that when you divide every 20µs by the 4µs you set it to you get 5µs of a 2V current?

Return to “Python”