[Thomas] wanted to play around with a few high-power LEDs and a RaspberryPi. LED controllers usually require some form of PWM to change the brightness of a LED, and unfortunately the Pi only has one PWM pin. [Thomas] could have gotten around this with a custom chip or even an Arduino hanging off the Pi’s USB port. He opted to go with software-based PWM, and did so in a way that is far superior to bit banging a pin.
Conventional wisdom says PWM without a real-time operating system is dumb – right up there with starting a land war in Asia. Turning a pin on and off in a while loop will eat up all the processor power in the Pi, so [Thomas] looked for a better way to do things. He came across the ServoBlaster project by [Richard Hirst] that creates pulses of different lengths by playing with direct memory access; [Richard] created a circular buffer that is read every 10μs. With 2000 values in the buffer, he can control eight different pins with very little impact on CPU usage.
For [Thomas], though, [Richard]’s project wasn’t enough. It was originally written for servos and is only able to drive PWM pins up to about 12%. A quick rewrite of [Richard]’s code allowed [Thomas] to control eight pins with PWM varying from 0% to 100% – and be able to do other things with his Pi in the process.
[Thomas] now has a 40 Watt RGB LED powered by a Raspberry Pi burned into his retina, and the satisfaction of a really clever way of giving the Pi more PWM pins.
Neat-O! I guess i’ll have to hack this hack though, so that the IR reciever still works. (pi-blaster sets all pins to outputs causing your other shiny things to stop working)
i was planing to do the same, using the Stellaris LaunchPad uDMA. it’s great to know that is really viable.
Is it possible to get PPM (For RC stuff) output with it?
Check here, its a 32 servo driver, all code is open source, there is even options for 8,16,32 servos on different chips
Link didnt make it, here you go:
http://www.mculabs.com/projects/ssx32.html
If it’s just continually copying data from a buffer to the output pins, then surely if you put the right data in, then you could do PPM or anything that involves continual pulses. So just from reading the description, yes.
+1000 for badass hacks.
This is right up there with someone’s “hack the HDMI for RGV laser scanning” hack.
Someone should start a specific repository so people can download every RPi hack ever written in one easy to copy .tar etc and help conserve author’s bandwidth.
Ha!, I got that “Land war in Asia” reference.
Inconceivable!
/NICE Hack
PWM – Pi Will Modulate
Nice!
Reminds me of a method I worked up for a project at work with an Arduino. I needed a way to generate 8 different frequencies on 8 different pins. Unfortunately the Arduino can only drive 2 or 3 different frequencies at once using the timers.
Ultimately I had it perform a math function to determine when to turn pins on and off. From a frequency it would calculate the period and then divide the current microsecond time on the controller by the period. A pin was switched high if the result was odd and low if even. Ultimately this allowed me to drive up to about 280-300 Hz while still being able to perform other functions on the Arduino. The waveform isn’t perfect, but it was good enough for an implement controller to think it was receiving signals from inductive sensors.
How many hardware PWM pins are there for RPI, and Is it possible to generate a PWM of frequncy above 25kHz with Rasberry Pi?
A little late, but has anybody got pi-blaster to work on the Pi with CYCLE_TIME_US defined as anything other than 10000?