You're welcome. I've dug up my test code I used to work out how this all stuck together. I have 4 LEDs on 4 GPIO pins, all driven by the same PWM channel, but each with different PWM signals - I wanted to check they could be overwritten (which they can, so a 2ms pulse can be overwritten by a 1ms pulse - it wasn't clear from the spec to me whether it would work because you can add many non-overlapping pulses to a single GPIO pin, but it wasn't clear what would happen if you overwrote a long pulse with a shorter one).
Note the pin numbers are not the GPIO connector pin numbers - they are the chip pin numbers - there's loads of info about mapping between the two - search the forum for GPIO.BOARD and GPIO.BCM. You don't need anything like the number of imports I've used, I just cut and pasted these from my main project code to save time.
Code: Select all
#!/usr/bin/env python
from __future__ import division
import signal
import socket
import time
import string
import sys
import RPIO.PWM as PWM
import time
import math
import threading
import logging
from array import *
import select
import os
import struct
PWM.setup(1) # setup up PWM with 1us granularity (the smallest)
PWM.init_channel(0, 3000) # setup channel 0 (0-15 available) with a 3ms pulse repeat rate
PWM.add_channel_pulse(0, 18, 0, 1000) # turn on GPIO BCM pin 18 at 0us into the 3ms cycle and off 1000us later
PWM.add_channel_pulse(0, 23, 0, 1250) # turn on GPIO BCM pin 23 at 0us into the 3ms cycle and off 1250us later
PWM.add_channel_pulse(0, 24, 0, 1500) # turn on GPIO BCM pin 24 at 0us into the 3ms cycle and off 1500us later
PWM.add_channel_pulse(0, 25, 0, 2000) # turn on GPIO BCM pin 25 at 0us into the 3ms cycle and off 1000us later
time.sleep(10)
PWM.add_channel_pulse(0, 18, 0, 2000) # turn on GPIO BCM pin 18 at 0us into the 3ms cycle and off at 2000us later
PWM.add_channel_pulse(0, 23, 0, 1500) # turn on GPIO BCM pin 23 at 0us into the 3ms cycle and off at 1500us later
PWM.add_channel_pulse(0, 24, 0, 1250) # turn on GPIO BCM pin 24 at 0us into the 3ms cycle and off at 1250us later
PWM.add_channel_pulse(0, 25, 0, 1000) # turn on GPIO BCM pin 25 at 0us into the 3ms cycle and off at 1000us later
time.sleep(10)
PWM.clear_channel_gpio(0, 25)
time.sleep(1)
PWM.clear_channel_gpio(0, 24)
time.sleep(1)
PWM.clear_channel_gpio(0, 23)
time.sleep(1)
PWM.clear_channel_gpio(0, 18)
time.sleep(1)
PWM.clear_channel(0)
PWM.cleanup()